fuzhengwei / fuzhengwei/WaLiCode
Responses 协议多轮对话:thinking 模式 reasoning_content 未回传导致 502
- Dominant language
- No language data
- Stars
- 133
- Forks
- 11
- PR merge metrics
- No merged PRs in 30d
Description
## 环境
- 客户端:WaLiCode(本地 AI 编程助手,作为 API 客户端使用,与 Claude Code 相同)
- 协议:**Responses API**(`/v1/responses`)
- 模型:`deepseek-v4-flash`(DeepSeek thinking 模式)
- 使用方式:多轮对话 + 工具调用(tool_calls)
## 问题描述
通过 **Responses 协议**请求 thinking 模式的模型时,第一轮模型输出了 `reasoning_content`(思维链)并调用工具(tool_calls)。第二轮把对话历史回传给 API 时,**上一轮的 `reasoning_content` 没有被回传**,API 拒绝请求报 502:
```
API Error (502): All channels failed for model deepseek-v4-flash after 1 attempt(s):
OpenCode-GO: {"error":{"param":null,"type":"invalid_request_error","code":"invalid_request_error",
"message":"Error from provider (Console Go): Upstream request failed: [invalid_request_error]
The reasoning_content in the thinking mode must be passed back to the API."}}
```
> 该问题与中间网关/代理无关,**直接请求 DeepSeek 官方 Responses 端点同样复现**。根因在客户端(WaLiCode)——重建下一轮请求时,没有把上一轮输出里的 reasoning 内容随请求回传。
## 预期行为
- 第一轮:assistant 输出 `reasoning_content` + `tool_calls`(工具调用)
- 第二轮:请求 `input` 中应包含上一轮的 reasoning 内容(Responses 协议的 `reasoning` item 应回传,或在对应 assistant 消息上携带 `reasoning_content`)
- 不应报 502
## 建议排查方向
- 客户端在持久化/重建对话时,需要把第一轮输出中的 `reasoning` item 一并保留,并在第二轮 `input` 中回传,而不是只回传 message / function_call item。
- 对涉及工具调用的轮次,`reasoning_content` 必须挂在紧随其后的 **assistant(tool_calls) 消息**(即带 tool_calls 的那条)上。
- 典型 input 顺序为 `reasoning → assistant 文本 → function_call → function_call_output`。其中 assistant 文本消息先到达,若 reasoning 被这条中间文本消息消费掉,等 function_call 需要挂载时就没有了——这会让 thinking 模式的下游把后续请求直接判为非法。
Contributor guide
No contributing guide indexed for this repository
Research direction
Start by tracing the client’s Responses API /v1/responses history persistence and request reconstruction for multi-turn tool calls. Check how the first response’s reasoning item and reasoning_content are retained and ordered with assistant, function_call, and function_call_output items. Done means the second request preserves the required reasoning content and no longer receives the reported 502.
Written by the indexing model from the issue text.
Assessment
- Domain
- ai, api
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Quiet
- Clarity
- Mostly clear
- Newbie friendliness
- 45/100