Repository navigation
Conversation
…he DeepSeek channel DeepSeek 系上游(官方及兼容接口)开启思考模式时,历史中携带 tool_calls 的 assistant 轮次必须回传 reasoning_content,否则上游返回 HTTP 400 "reasoning_content must be passed back to the API"(QuantumNous#4543 / QuantumNous#6939 / QuantumNous#4408)。即使客户端(如 Cursor、上下文压缩后的重放)或中间路由裁剪掉了该字段,只要经过 DeepSeek 渠道 就会触发。 FIX: - DeepSeek 适配器 ConvertOpenAIRequest 出口处补全:凡带 tool_calls 且缺 reasoning_content 的 assistant 消息补空字符串,已有非空值原样保留,user/tool 消息不受影响 ADD: - relay/channel/deepseek/adaptor_test.go:5 个单测覆盖补全/保留/不误伤场景 仅在 DeepSeek 渠道类型内生效,不触碰通用格式转换层。
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Organization UI Review profile: CHILL Plan: Team Run ID: 📒 Files selected for processing (2)
Included review availability: Your plan provides up to 10 included reviews per hour; 9 remain after this review. WalkthroughThe DeepSeek adapter now ensures assistant messages with tool calls include ChangesDeepSeek reasoning content
Estimated code review effort: 2 (Simple) | ~10 minutes Merge Risk: ⚪ Minimal · up to This localized fix restores the required reasoning field only for DeepSeek assistant tool-call requests and preserves existing values, preventing the reported 400 errors without changing permissions, deployment scope, or other providers. No actionable merge-blocking risk remains beyond normal checks and review. Suggested reviewers: Poem
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
Full details: Linked Issues checkExplanation The changes address issue
✨ Finishing Touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
Agent
Links
reasoning_content报错 #4543, thinking is enabled but reasoning_content is missing in assistant tool call message at index 108 #4408, fix(claude): 保留 thinking signature 以修复 DeepSeek 多轮对话 400 #6998, fix(relayconvert): preserve assistant reasoning across request protocol conversions #6593, fix: preserve reasoning_content across request #6655, fix: preserve Claude reasoning content in message conversions #4497User request
Out of scope — refuse
Kind
Issue facts
reasoning_contentmust be passed back to the API"。tool_calls的 assistant 轮次必须原样回传reasoning_content。但很多客户端(Cursor、Claude Code)或上下文压缩工具在回传历史时会自行裁剪掉该字段——[BUG] ClaudeCode 使用 OpenAI 格式接入的 Deepseek V4 上游会遇到 400reasoning_content报错 #4543 中已实测确认(@Feliks151450):即使走 DeepSeek 渠道类型,new-api 也不会补上,照样报错。用户侧无法规避。reasoning_content报错 #4543 26 条评论、调用deepseek-v4-flash会报错:400 The 'reasoning_content’ in the thinking mode must be passed back to the API. #6939、thinking is enabled but reasoning_content is missing in assistant tool call message at index 108 #4408、[Channel] DeepSeek: thinking mode fails on multi-turn with "reasoning_content must be passed back" #4806、[BUG] DeepSeek V4 Pro 多轮对话后调用出错,Thereasoning_contentin the thinking mode must be passed back to the API. #4515 均为同一报错)。reasoning_content报错 #4543 中认可"可以考虑针对这个渠道类型补齐这个"),但当前适配器未做此补全。relay/channel/deepseek/adaptor.go(DeepSeek 渠道类型请求出口)。Change
在
relay/channel/deepseek/adaptor.go的ConvertOpenAIRequest出口处新增ensureToolCallReasoningContent:request.Messages;role == "assistant"且携带tool_calls而reasoning_content为nil的消息,补全为空字符串"";user/tool等其他角色的消息不受影响。为什么补空字符串? 上游校验仅要求字段存在(接受空串),补空串既能通过校验,又不伪造思考内容、不增加 Token 计费。
为什么只在 DeepSeek 适配器改? 影响面最小。通用转换层的映射(#6593 方向)无法覆盖字段已被客户端裁剪的场景——此时历史里已无 thinking 可映射,渠道出口是唯一有效层;且 DeepSeek 渠道专属兜底不触碰通用转换,与其他供应商零相互影响。
Research
Duplicate / prior art
reasoning_content报错 #4543/fix: 协议转换请求侧多方向丢失 assistant 推理内容(chat→Responses / Messages→Chat / chat→Claude / chat→Gemini) #6592 已明确通用转换不默认处理该字段);fix(claude): 保留 thinking signature 以修复 DeepSeek 多轮对话 400 #6998 修反方向(OpenAI 请求 → Claude 渠道)的 thinking signature 透传。没有任何 PR 在 DeepSeek 渠道适配器内做兜底,而这正是维护者在 [BUG] ClaudeCode 使用 OpenAI 格式接入的 Deepseek V4 上游会遇到 400reasoning_content报错 #4543(2026-05-04)松口的方向:"可以考虑针对这个渠道类型补齐这个,之后我看看"。本 PR 只做这一件事,与上述 PR 零文件冲突;即使后续通用层做了映射,本兜底仍能保证被客户端裁剪过的请求通过校验,两者互补。Docs and code
relay/channel/deepseek/adaptor.go的ConvertOpenAIRequest是 DeepSeek 渠道发上游前的最后出口,在此补全覆盖所有进入该渠道类型的请求,无论客户端什么协议、字段是否被中间环节裁剪。Alternatives considered
reasoning_content报错 #4543 实测不可行——客户端裁剪行为不受 new-api 控制。Files
relay/channel/deepseek/adaptor.goensureToolCallReasoningContent兜底补全relay/channel/deepseek/adaptor_test.goBehavior
reasoning_content的 tool_calls 轮次时原样转发,上游返回 400。reasoning_content: "",请求通过校验;已有值不受影响。Verification
go build ./relay/channel/deepseek/— PASSgo vet ./relay/channel/deepseek/— PASSgo test ./relay/channel/deepseek/— PASS(新增 5 用例)adaptor_test.go(表驱动,require/assert)。reasoning_contentin the thinking mode must be passed back to the API. #4515);MySQL/PostgreSQL(改动不涉及 DB)。Risks
reasoning_content,需改为注入占位文本(上游目前接受空串)。Scope check
Note: 本 PR 的问题定位、代码实现与单测由 AI 辅助完成,提交者已审阅全部内容并对其准确性负责,在真实的腾讯云 DeepSeek 接口上通过了 15 小时 / 约 20,000 次调用的实测验证。
Summary by CodeRabbit
Bug Fixes
Tests