Skip to content

docs(quick-start): fix invalid tool parameter schema that breaks DashScope function calling - #282

Open
z1258 wants to merge 1 commit into
spring-ai-alibaba:mainfrom
z1258:patch-1
Open

z1258 wants to merge 1 commit into
spring-ai-alibaba:mainfrom
z1258:patch-1

Conversation

@z1258

@z1258 z1258 commented Sep 12, 2026 •

Copy link
Copy Markdown

Closes alibaba/spring-ai-alibaba#4966

问题

quick-start 的「构建一个基础 Agent」与「构建一个真实的 Agent」示例中,
FunctionToolCallback 使用了 .inputType(String.class),生成的工具参数 schema 是:

{ "type": "string", "additionalProperties": false }

而 DashScope 要求 function 的 parameters 必须是 JSON object。结果是模型产出合法的
tool_call 后,第二轮把该 tool_call 回传时被服务端拒绝,照抄文档即复现 400:

HTTP 400 - {"request_id":"330f8d4d-77f5-9671-86ba-a1b223fbb175","code":"InvalidParameter",
"message":"<400> InternalError.Algo.InvalidParameter: The \"function.arguments\" parameter of the code model must be in JSON format."}

原因:FunctionToolCallback.Builder.build() 只依据 inputType 推导 schema
(JsonSchemaGenerator.generateForType(this.inputType)),不会读取 apply() 的方法签名,
因此 String.class 直接翻译成 "type": "string"。

改动

# 位置 改动
R1 构建一个基础 Agent 引入 WeatherRequest record,inputType 改为 WeatherRequest.class
R2 步骤 2 · WeatherForLocationTool 同上;@ToolParam 移到 record 组件上
R3 步骤 2 · UserLocationTool 同上
R4 步骤 2 · 两个 ToolCallback inputType 改为对应 record
R5 SYSTEM_PROMPT 工具名与注册名统一(getWeatherForLocation / getUserLocation)
R6 步骤 3 · 依赖 版本统一为 1.1.2.0(与「添加依赖」小节一致)
R7 高级功能 · HumanInTheLoopHook approvalOn("getWeatherTool", ...) 改为文档中真实存在的工具名
R8 步骤 1 列表 System Prom → System Prompt

验证

  • 照抄原文(inputType(String.class))→ 稳定复现上述 400;
  • 应用 R1 后的写法(inputType(WeatherRequest.class))→ 正常返回,工具被真实调用:
DEBUG o.s.a.t.function.FunctionToolCallback : Starting execution of tool: get_weather
DEBUG o.s.a.t.function.FunctionToolCallback : Successful execution of tool: get_weather

环境:JDK 21.0.10 / Spring Boot 3.5.5 / agent-framework 1.1.2.0 / starter-dashscope 1.1.2.0 / 默认模型。

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Docs] quick-start 示例照抄即复现 400:工具 inputType 使用 String.class

1 participant