Skip to content

[Bug]:如果给智能体设定了schema同时又绑定了工具会导致返回数据格式不正确,没有按照指定格式返回2.03版本 #3393

Closed

Description

@zt18661205847

如下面的代码

        Toolkit toolkit = new Toolkit();
        toolkit.registerTool(new Tool1());
        toolkit.registerTool(new Tool2());

        ObjectMapper om = new ObjectMapper();
        JsonNode schema = om.readTree("""
    {
      "type": "object",
      "properties": {
        "sentiment": { "type": "string", "enum": ["positive", "negative", "neutral"] },
        "confidence": { "type": "number" }
      },
      "required": ["sentiment", "confidence"]
    }
    """);


        ReActAgent agent = ReActAgent.builder()
                .name("GuardedAgent")
                .sysPrompt("你是一个助理")
                .model("dashscope:qwen-plus")
               .toolkit(toolkit)
                .build();

        Msg result = agent.call(List.of(new UserMessage("美丽")), schema).block();

        System.out.println(result.getTextContent());

当不设定tookkit时返回正确

{"confidence":0.95,"sentiment":"positive"}

当设定工具后返回

generate_response({"response": {"confidence": 0.95, "sentiment": "positive"}})

甚至是纯文本

Activity

  1. added
    bug
    on Oct 3, 2026
  2. oss-maintainer commented on Oct 3, 2026

    @oss-maintainer
  3. added
    area/core/agent
    area/core/model
    on Oct 3, 2026
  4. jujn commented on Oct 3, 2026

    @jujn
    Collaborator

    DashScope 只在一部分模型支持严格的 JSON Schema 结构化输出:https://help.aliyun.com/zh/model-studio/qwen-structured-output#支持的模型
    框架这边是用了一个工具(generate_response)来强制模型结构化输出。
    可以用 ToolChoice.Specific("generate_response") 强制模型调用这个工具,或者换个好点的模型(qwen-plus 老古董了)

  5. zt18661205847 commented on Oct 4, 2026

    @zt18661205847
    Author

    为什么不通过 模型支持schema适配+system prompt做schema兜底来做呢?纯用工具的话它有可能会不掉,特别是工具配备比较多的情况

  6. added a commit that references this issue on Oct 10, 2026
    8eb9115
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    area/core/agentarea/core/modelbug

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions