agentscope-java icon indicating copy to clipboard operation
agentscope-java copied to clipboard

[Bug]: OpenAIMultiModalTool throws HTTP 503 on non-OpenAI proxies due to hardcoded gpt-4o fallback model

Open Buktal opened this issue 5 months ago • 1 comments

Describe the bug

OpenAIMultiModalTool.openaiImageToText hardcodes "gpt-4o" as the fallback model name when the LLM does not supply the optional model parameter. When deployed against a non-OpenAI-compatible backend (e.g. a MiniMax proxy), the backend returns HTTP 503 because it does not recognize gpt-4o.

To Reproduce

  1. Instantiate OpenAIMultiModalTool with a custom baseUrl pointing to a non-OpenAI backend:
    new OpenAIMultiModalTool(apiKey, "http://your-proxy-host/");
    
  2. Register the tool in a Toolkit and run a ReActAgent with an image input.
  3. The agent calls openai_image_to_text without specifying the model parameter (or the LLM picks gpt-4o from the description hints).
  4. The tool sends { "model": "gpt-4o", ... } to POST /v1/chat/completions.
  5. The backend returns 503.

Expected behavior

OpenAIMultiModalTool should either:

  • Accept a defaultModelName constructor parameter so callers can override the fallback, or
  • Remove "gpt-4o" / "gpt-4-vision-preview" from the @ToolParam description to avoid steering the LLM toward OpenAI-specific model names.

Error messages

io.agentscope.core.model.exception.InternalServerException: OpenAI API request failed with status 503
    at io.agentscope.core.model.exception.OpenAIException.create(OpenAIException.java:88)
    at io.agentscope.core.model.OpenAIClient.callApi(OpenAIClient.java:666)
    at io.agentscope.core.model.OpenAIClient.callApi(OpenAIClient.java:609)
    at io.agentscope.core.tool.multimodal.OpenAIMultiModalTool.lambda$openaiImageToText$8(OpenAIMultiModalTool.java:331)

Root cause in source (OpenAIMultiModalTool.java:286):

String finalModel = Optional.ofNullable(model)
    .filter(s -> !s.trim().isEmpty())
    .orElse("gpt-4o");  // hardcoded fallback

Environment

  • AgentScope-Java Version: 2.0.0-RC2
  • Java Version: 21
  • OS: Windows 11

Additional context

The @ToolParam description for model currently reads:

"The vision model to use, e.g., 'gpt-4o', 'gpt-4-vision-preview'"

This actively guides the LLM to fill in gpt-4o, which makes the 503 hard to diagnose — the error looks like a transient service outage rather than a model-name mismatch.

Workaround (applied in this project)

Subclass OpenAIMultiModalTool, shadow the 4-parameter openaiImageToText override (no @Tool annotation so the framework scanner skips it), and expose a 3-parameter @Tool method that always injects the configured model name:

public class KstMultiModalTool extends OpenAIMultiModalTool {

    private final String defaultModelName;

    public KstMultiModalTool(String apiKey, String baseUrl, String defaultModelName) {
        super(apiKey, baseUrl);
        this.defaultModelName = defaultModelName;
    }

    @Override
    public Mono<ToolResultBlock> openaiImageToText(
            String imageUrls, String prompt, String model, Integer maxTokens) {
        return super.openaiImageToText(imageUrls, prompt, defaultModelName, maxTokens);
    }

    @Tool(name = "openai_image_to_text",
          description = "Convert image(s) to text. Analyzes images and returns text descriptions.")
    public Mono<ToolResultBlock> analyzeImages(
            @ToolParam(name = "image_urls", description = "Image URLs to analyze (comma-separated)")
            String imageUrls,
            @ToolParam(name = "prompt", description = "What to extract from the images", required = false)
            String prompt,
            @ToolParam(name = "max_tokens", description = "Maximum tokens in response", required = false)
            Integer maxTokens) {
        return super.openaiImageToText(imageUrls, prompt, defaultModelName, maxTokens);
    }
}

Buktal avatar Jun 10 '26 07:06 Buktal

我计划提交一个 PR 来修复这个问题,方案是:

  1. 新增一个 defaultModelName 构造参数,让调用方可以指定默认模型名
  2. 修改 openaiImageToText 的 @ToolParam description,去掉 gpt-4o、gpt-4-vision-preview 等 OpenAI 特定的模型名提示

Buktal avatar Jun 10 '26 12:06 Buktal