[Bug] 思考模式下工具调用返回 400 INVALID_REQUEST — reasoning_content 未回传 #739
kunxiOvOkunxi
started this conversation in
General
Replies: 1 comment 2 replies
|
推理模式(reasoningEffort=high/max)下工具调用失败,通常是思考内容(reasoning_content)在工具调用轮次里没被正确回传(DeepSeek 官方的 reasoning 模型要求工具调用轮次携带上一轮 reasoning_content)。 可先确认:1) 非推理模式(low/无)是否正常?2) 是否是流式分块时 reasoning_content 丢失?我们的手册第 6 章性能调优记录了推理档位的坑(含"降档后行为差异"):https://github.com/Electricitysheep/dsh-handbook/blob/main/docs/06-advanced.md |
2 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
环境信息
agent-default-model.model = deepseek-v4-pro
agent-default-model.reasoningEffort = max(high 同样可复现)
问题描述
开启思考模式(reasoningEffort = high 或 max)后,当智能体在会话中需要
调用工具(如 bash、fs 等)时,该轮请求稳定返回:
HTTP 400 INVALID_REQUEST
{"error":{"message":"The
reasoning_contentin the thinking mode must bepassed back to the API.","code":"invalid_request_error"}}
导致开启思考模式后,任何涉及工具调用的任务都无法完成;只有把
reasoningEffort 设为 off 才能绕过。
复现步骤
返回 400 INVALID_REQUEST。
根因定位
问题出在 @deepseek-ai/dsh-llm-deepseek/lib/index.js 的
serializeAssistant():
return {
role: "assistant",
content: text,
...toolCalls.length > 0 && reasoning.length > 0
? { reasoning_content: reasoning } : {}, // ← 问题在这里
...toolCalls.length > 0 ? { tool_calls: toolCalls } : {}
};
当 assistant 轮次带工具调用、但思考内容为空(reasoning.length === 0)时,
上述条件不成立,导致 reasoning_content 字段被整体省略。
而 DeepSeek 思考模式 API 要求:只要 assistant 轮次携带 tool_calls,
就必须回传 reasoning_content(即使为空字符串)。
这与该包 README 中"对携带工具调用的 assistant 轮次,会将
reasoning_content 序列化回历史(思考模式 API 必需)"的描述不符。
最小复现(raw API)
以下请求可直接复现(省略 Authorization 头):
POST https://api.deepseek.com/chat/completions
{
"model": "deepseek-v4-pro",
"messages": [
{"role":"user","content":"run ls"},
{"role":"assistant","content":"",
"tool_calls":[{"id":"call_1","type":"function",
"function":{"name":"bash","arguments":"{"command":"ls"}"}}]},
{"role":"tool","tool_call_id":"call_1","content":"file1 file2"}
],
"stream": true,
"tools": [{"type":"function","function":{
"name":"bash","description":"run a command",
"parameters":{"type":"object",
"properties":{"command":{"type":"string"}},"required":["command"]}}}]
}
→ 返回 400:The
reasoning_contentin the thinking mode must be passedback to the API.
期望行为 vs 实际行为
reasoning_content(空则回传空字符串 ""),使请求正常完成。
建议修复
将条件改为"只要带 tool_calls 就回传 reasoning_content(可为空字符串)",
例如:
...toolCalls.length > 0 ? { reasoning_content: reasoning } : {},
补充说明
stream_options 等参数问题(单独测试均为 200 OK)。
读取的(dsh-base 中 agent-default-model 注释明确写着
"consumers read it at creation time")。
触发第一次 400 INVALID_REQUEST。此时这条"缺少 reasoning_content 的
assistant 消息"已进入会话历史。
reasoning_content 的消息,后续每一轮(turn 2~11)都在 step 1
稳定复现同一个 400,形成"会话中毒"。
实测佐证(同一会话):
All reactions