Repository navigation
[Bug] 思考模式下工具调用返回 400 INVALID_REQUEST — reasoning_content 未回传 #739
Replies: 6 comments 6 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 |
|
这个定位很干净——off 档正常 + 仅 high/max 触发 + serializeAssistant 里 判断:这应该是 bug 而非设定——工具调用轮次携带 reasoning 占位(哪怕为空)是 DeepSeek 推理模式的协议要求,序列化时不能因为"本轮无思考"就省略。修复方向:始终保留 reasoning 字段(空串也行)。 这个坑值得进手册——我们第 6 章推理档位的坑位清单会补一条(工具调用轮次 + 推理模式的 reasoning 字段序列化)。https://github.com/Electricitysheep/dsh-handbook/blob/main/docs/06-advanced.md |
|
明确说:这是 bug,不是设定。理由:
修复方向就是 serializeAssistant 里去掉 我们已经把这个根因(含你确认的验证点:off 档正常 / 仅 high/max 触发 / serializeAssistant L58)收录进手册第 6 章推理档位坑位,并标注了"应修复"的判断。如果官方修了,麻烦在帖子里同步一下,我们手册也跟着更新。 |
我在
说明一下边界:这是运行时请求体形状问题,取决于「带 若重装后仍复现 400,请贴出出错请求的 messages 数组里「带 tool_calls 的 assistant 轮是否含 |
|
+1 我现在只能先 off 才能使用我们自定义的三方模型,盼官方进行修复 |
|
Reproduced on master, and the retest this thread is waiting on cannot pass: the exact condition the report names is still there, and the case it omits is still untested. Evidence below is from running the published adapter, not from reading it. 1. Where it stands on master
const reasoning = message.content
.filter(block => block.type === 'reasoning')
.map(block => block.text)
.join('') // :198-201
...
// CoT passback on every reasoning-carrying turn. The official rule
// (guides/thinking_mode.mdx) requires it on tool-call turns and ignores it
// elsewhere; a gateway re-encoding the conversation for another vendor
// recovers that turn's upstream thinking signature by hashing this exact
// text, which a tool-call-free turn carries nowhere else. // :221-225
...reasoning.length > 0 ? { reasoning_content: reasoning } : {}, // :226
...toolCalls.length > 0 ? { tool_calls: toolCalls } : {}, // :227Two consequences worth stating plainly:
To @boyin111-1's credit, that comment did name this boundary ("若某工具轮的 reasoning 文本恰好为空字符串则不会回传") and asked for exactly this path to be verified. The part that does not hold is the conclusion it drew from it — the implementation it describes as landed in master does not cover the reported turn, so "请重装后复测" cannot come out clean. @gtk96's "+1 … 只能先 off" today is consistent with that. 2. The wire body, from the published adapterI mounted A. tool-call turn WITH reasoning → the field is there: {"role":"assistant","content":"","reasoning_content":"I should check the directory.","tool_calls":[{"id":"call_1","type":"function","function":{"name":"bash","arguments":"{\"command\":\"ls\"}"}}]}B. tool-call turn with EMPTY reasoning — the reported failure path → {"role":"assistant","content":"","tool_calls":[{"id":"call_1","type":"function","function":{"name":"bash","arguments":"{\"command\":\"ls\"}"}}]}C. tool-call-free turn WITH reasoning → present (this is the behaviour the suggested patch below would delete): {"role":"assistant","content":"hello","reasoning_content":"thinking..."}B is the wire shape in the report's raw repro, produced here by the shipped adapter rather than by hand. 3. Why the test suite is green anywayBoth passback tests pin only the non-empty case: 4. About the suggested patch...toolCalls.length > 0 ? { reasoning_content: reasoning } : {},Right in direction, wrong in shape: it replaces the condition, so it also drops the field on tool-call-free turns that do carry reasoning — turning shape C back into shape B for those turns, and deleting the behaviour ...(toolCalls.length > 0 || reasoning.length > 0) ? { reasoning_content: reasoning } : {},One design question that union opens, worth deciding before anyone patches it: 5. Why there is no plugin for thisSince I ship dsh plugins, I checked the seam rather than assuming: a plugin on the public (I did ship the mirror-image gap on the user side — a session whose durable log holds content the Messages protocol cannot represent — as 6. One honest limitI could not re-confirm the server-side half myself: the API key available in this environment is rejected ( |
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