Repository navigation
fix(deepseek): pass reasoning_content back for all assistant turns - #3272
Conversation
DeepSeek's thinking mode requires reasoning_content to be fully passed back
for every assistant turn when the request carries tools, but the formatter
used to strip it from turns without tool calls, and framework-synthesized
assistant messages (e.g. subagent completion notifications) never carry a
ThinkingBlock at all - both producing HTTP 400 ("The reasoning_content in
the thinking mode must be passed back to the API").
- applyDeepSeekFixes never strips reasoning_content and backfills an empty
string for assistant messages that lack it, in both the compat and the
deprecated DeepSeekFormatter and DeepSeekMultiAgentFormatter
- thinking mode is decided by the request's thinking option
({"type": "enabled"|"disabled"}); when the option is absent the formatter
assumes thinking is enabled (DeepSeek's server-side default), so missing
traces are backfilled anyway, and an explicit "disabled" opts out
- fixes run on the two-arg doFormat(List, GenerateOptions) production path;
the one-arg applyDeepSeekFixes overload had no production caller and is
removed; the deprecated formatter additionally keeps its legacy
name-field removal
- fixes mutate the freshly converted message list in place; the contract is
documented on both formatters, and en/zh deepseek.md describe the new
thinking-option semantics
- add DeepSeekReasoningContentPassbackTest covering the reported scenario
plus two-arg production-path, thinking-option and in-place-mutation tests
(593 module tests green, DeepSeek formatter classes at 100% line/branch
coverage)
Fixes agentscope-ai#3246
Codecov Report✅ All modified and coverable lines are covered by tests. 📢 Thoughts on this report? Let us know! |
oss-maintainer
left a comment
There was a problem hiding this comment.
Summary
Backfills reasoning_content on all assistant turns (including tool-call and framework-synthesized sub-agent turns) in both the formatter/ and compat/deepseek/ DeepSeek formatters, replaces the old "keep reasoning only for segments with tool calls" rule, and documents the thinking-mode detection and the in-place mutation contract. The behaviour change is deliberate and the API contract (HTTP 400 unless reasoning is passed back for tool-carrying requests) is quoted in the javadoc, so this fixes a real failure mode rather than masking one.
I read the two copies side by side at head: the reasoning backfill is present in both, the "unset option ⇒ assume thinking on" default and the caller-owns-the-list mutation contract are both documented where I would have asked about them, and the new DeepSeekReasoningContentPassbackTest plus the added cases in the four existing formatter tests cover backfill, explicit opt-out, serialization and the two-arg formatting path. CLA is signed (license/cla=success on 4037595c), and ~1,090 of the +1,375 lines are tests/docs. Approved.
Findings
- [Warning]
compat/deepseek/DeepSeekFormatter.java:131— thename-stripping rule applied by the non-compat copy is absent here; the fix landed on one copy only. Worth a parity note or test.
Cross-repo note
None required: the change is confined to agentscope-extensions-model-openai, and compat/deepseek keeps its existing public surface.
Automated review by github-manager-bot
| } | ||
| return result; | ||
| for (OpenAIMessage msg : messages) { | ||
| fixMessage(msg); |
There was a problem hiding this comment.
[Warning] Verified at head: this compat/deepseek copy only backfills reasoning_content, while formatter/DeepSeekFormatter.fixMessage(msg, thinkingMode) also does an unconditional msg.setName(null) ("Legacy rule: drop the name field (DeepSeek returns HTTP 400 when it is present)"). If that 400 rule holds for the wire format, it holds for this copy too — either the compat path has a latent name-field bug, or the asymmetry is intentional and is worth one line of comment plus a parity test asserting both copies emit the same shape. Not blocking this PR (the name handling here is pre-existing and untouched by your change), just flagging that the fix landed on one copy only.
…3272) Backport the verified fix to the 2.0.x implementation and retain its existing public contracts where the upstream kernel differs. (cherry picked from commit 9343ff0) Constraint: No AgentScope Service or SDK migration Confidence: high Not-tested: Whole-repository verification pending after lane integration
AgentScope-Java Version
2.0.4-SNAPSHOTDescription
Fixes #3246
Summary
DeepSeek's thinking mode requires
reasoning_contentto be fully passed back for every assistant turn when the request carries tools, but the framework produced HTTP 400 ("The reasoning_content in the thinking mode must be passed back to the API") in everyday scenarios: plain text assistant turns lost their reasoning, and framework-synthesized assistant messages (e.g. subagent completion notifications) never carry any.Root cause
Two code paths violated the DeepSeek thinking-mode contract:
DeepSeekFormatter(both the compat and the deprecated variants) only keptreasoning_contenton assistant messages containing tool calls, silently dropping it from plain text turns — the next tool-carrying request then violated the pass-back rule.namefield and text content; having never carried aThinkingBlock, they serialize withoutreasoning_content.Both produce a request whose history misses
reasoning_contenton assistant turns whiletoolsis present → HTTP 400. Additionally, the fixes only lived on the one-argapplyDeepSeekFixes(List)overload, while production traffic goes through the two-argdoFormat(List, GenerateOptions)path — so the existing one-arg fixes were never applied in production at all.Changes
applyDeepSeekFixesnever stripsreasoning_contentand backfills an empty string for assistant messages that lack it, in both the compat and the deprecatedDeepSeekFormatterandDeepSeekMultiAgentFormatter; both formatters now override the two-argdoFormat(List, GenerateOptions)production path.thinkingoption ({"type": "enabled"|"disabled"}in the additional body params, as encoded byDeepSeekModelProvider). When the option is absent the formatter assumes thinking is enabled (DeepSeek's server-side default), so missing traces are backfilled anyway; an explicitdisabledopts out. The previous history-scan fallback is removed — it could not detect the reported scenario (no thinking option and noreasoning_contentin history).applyDeepSeekFixesoverload had no production caller and is removed; the deprecated formatter additionally keeps its legacyname-field removal.docs/v2/en|zh/integration/model/deepseek.mddescribe the new thinking-option semantics.How to test
No Docker/network required:
DeepSeekReasoningContentPassbackTest(new): the reported scenario plus two-arg production-path, thinking-option and in-place-mutation tests.Checklist
Please check the following items before code is ready to be reviewed.
mvn spotless:applymvn test)