fix: ensure reasoning_content on all assistant messages for DeepSeek/Kimi thinking mode - #15996
Closed
highland0971 wants to merge 1 commit into
Closed
highland0971 wants to merge 1 commit into
highland0971 wants to merge 1 commit into
Conversation
…Kimi thinking mode DeepSeek V4 and Volc Ark Coding Plan's thinking mode requires every assistant message in the conversation history to have 'reasoning_content' field (even if empty string). Missing this field on text-only (non-tool-call) responses causes HTTP 400: 'The reasoning_content in the thinking mode must be passed back to the API.' Three changes: 1. agent_loop.py: Always set reasoning_content (not conditional on reasoning) 2. run_agent.py: _copy_reasoning_content_for_api applies to all assistant turns for DeepSeek/Kimi providers, not just tool-call turns 3. chat_completions.py: convert_messages() ensures reasoning_content is present on all assistant messages before API call (defense-in-depth)
Contributor
Collaborator
|
Closing as redundant — the DeepSeek
21 regression tests in |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
DeepSeek and Volc Ark thinking mode requires every assistant message (including plain text replies) to carry a
reasoning_contentfield. When this field is missing, the API returns HTTP 400:Root Cause
Three places where
reasoning_contentcould be dropped:reasoning_contentonly when non-empty (if reasoning:)_copy_reasoning_content_for_apionly covered tool-call assistant turnsconvert_messagesreturned messages as-is when no Codex sanitization was needed — no field normalizationFix (3 changes)
environments/agent_loop.pyL323 & L494: changedif reasoning: msg_dict["reasoning_content"] = reasoning→msg_dict["reasoning_content"] = reasoning or ""(unconditional)run_agent.py_copy_reasoning_content_for_api: expanded scope from tool-call-only to all assistant turns for DeepSeek/Kimi providersagent/transports/chat_completions.pyconvert_messages: added defense-in-depth normalization — ensures everyrole=="assistant"message hasreasoning_contentTesting
Verified in production (Feishu bot with DeepSeek V4 Pro thinking mode). Previously failing conversations now work correctly. Three-layer defense ensures future changes won't re-introduce the issue.