Skip to content

fix(proxy): patch missing reasoning_content in assistant messages for… - #908

Open
mambo-wang wants to merge 4 commits into
TencentCloud:feat/server_teamfrom
mambo-wang:fix/proxy-deepseek-reasoning-content-clean
Open

fix(proxy): patch missing reasoning_content in assistant messages for…#908
mambo-wang wants to merge 4 commits into
TencentCloud:feat/server_teamfrom
mambo-wang:fix/proxy-deepseek-reasoning-content-clean

Conversation

@mambo-wang

Copy link
Copy Markdown

… DeepSeek thinking mode

DeepSeek thinking-mode API rejects message histories where an assistant turn (e.g. a proxy-generated session-init form tool_call) has no reasoning_content, returning HTTP 400. Patch such messages with an empty reasoning_content string before forwarding, which satisfies the API while preserving normal thinking behaviour.


Description | 描述

Fix: MemoryProxy/src/handler.tsbuildUpstreamBody() now calls patchMissingReasoningContent(), which patches assistant messages that lack a reasoning_content field with an empty string before forwarding.

DeepSeek 的 thinking 模式 API 会拒绝消息历史中缺少 reasoning_content 的 assistant 消息(例如 proxy 在 session-init 阶段伪造的表单 tool_call),返回 HTTP 400:

The reasoning_content in the thinking mode must be passed back to the API.

该问题导致任何使用 DeepSeek thinking 模型作为上游的会话初始化流程被阻断:用户走完资产确认表单后,下一个真实请求必然 400,记忆注入也不会生效。

修复已验证(直打 DeepSeek API):补空串 → 200 且保留思考能力;thinking:{"type":"disabled"} → 200 但禁用思考。非 assistant 消息及已携带该字段的消息不做处理,对 OpenAI 等其他上游无副作用(body 原样返回)。

Related Issue | 关联 Issue

None | 无(部署验证过程中发现的协议兼容性缺陷,无关联 Issue)

Change Type | 修改类型

  • Bug fix | Bug 修复
  • New feature | 新功能
  • Documentation update | 文档更新
  • Code optimization | 代码优化

Self-test Checklist | 自测清单

  • Verified locally | 本地验证通过(真实 Proxy + DeepSeek thinking 上游跑通完整表单链路 R1→R4:asset_confirm → team/agent/task → 注册 → 转发,修复后 200,三条注入 Hook 全部执行,上游 reasoning_content 可见注入上下文)
  • No existing features affected | 无影响现有功能(buildUpstreamBody 对无缺失字段的消息返回原 body,非 thinking 上游行为不变)

Additional Notes | 其他说明

  • 改动范围仅 MemoryProxy/src/handler.ts(+32 行),基于 upstream 最新 feat/server_teamfe3230f)创建。
  • 采用补空串而非 thinking:{"type":"disabled"},是为了在满足 API 校验的同时保留模型的正常思考能力。
  • 可选加固方向(本次未做):在 config 中标记上游是否为 thinking 模型、仅对该类上游启用补丁;或在表单构造阶段直接生成带 reasoning_content 的消息。当前实现作为最小兜底,对任意上游无副作用。

… DeepSeek thinking mode

DeepSeek thinking-mode API rejects message histories where an assistant
turn (e.g. a proxy-generated session-init form tool_call) has no
reasoning_content, returning HTTP 400. Patch such messages with an empty
reasoning_content string before forwarding, which satisfies the API while
preserving normal thinking behaviour.
@honchow

honchow commented Aug 10, 2026

Copy link
Copy Markdown
Collaborator

感谢提交PR,以下建议麻烦考虑下:

  1. 看起来.codewiki目录下是测试文件,麻烦删除下。
  2. reasoning_content 补字段是全模型生效,是否会影响非DeepSeek上游?

- 浠?git 绉婚櫎璇彁浜ょ殑 .codewiki 鍒嗘瀽缂撳瓨锛圫QLite db锛夛紝骞跺湪 .gitignore 涓拷鐣?- CreditPricingEntry 鏂板 requiresReasoningContent 鏍囪锛屼粎瀵规樉寮忔爣璁扮殑
  DeepSeek thinking 妯″瀷鍚敤 reasoning_content 琛ヤ竵锛岄伩鍏嶅奖鍝嶉潪 DeepSeek 涓婃父
- 鏇存柊 config.example.yaml 涓?deepseek-v4-pro/flash 娣诲姞鏍囪绀轰緥
@mambo-wang

Copy link
Copy Markdown
Author

已修改

@Maxwell-Code07

Copy link
Copy Markdown
Collaborator

Thank you for your attention and contribution! We will schedule an internal review of this PR, and we will share any feedback right here.

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.

3 participants