fix: extend DeepSeek reasoning_content fallback to text-only assistant messages - #16247
Closed
brian-doherty wants to merge 1 commit into
Closed
Conversation
…t messages DeepSeek thinking mode requires reasoning_content on EVERY assistant message replayed to the API, not just tool-call ones. The previous code only set the empty-string fallback for tool-call messages, so text-only responses (e.g. the final response after a tool loop) could be persisted without reasoning_content. On session resume, replaying such a message to DeepSeek's API produces HTTP 400: The reasoning_content in the thinking mode must be passed back to the API. The replay safety net in _copy_reasoning_content_for_api (step 4) already handles this on replay, but storing correct data from creation time is cleaner and avoids relying on the replay catch-all. Separates Kimi (tool-call-only empty-string) from DeepSeek (all assistant messages) so each provider's contract is met precisely. Refs NousResearch#15250, NousResearch#15998
Collaborator
Collaborator
|
Part of the reasoning_content fix cluster. |
Contributor
|
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.
Bug
When using DeepSeek in thinking mode (
reasoning_effort: medium), text-only assistant responses (the final reply after a tool loop) could be persisted to the session DB without areasoning_contentfield. On session resume, replaying that message to DeepSeek's API produces:This forced users to start a new session to recover.
Root Cause
_build_assistant_message(the creation path atrun_agent.py:7763) only guaranteed thereasoning_content=""fallback for tool-call messages under DeepSeek thinking mode. Text-only responses fell through without settingreasoning_contentat all, because:reasoning_contenton every turnmsg["tool_calls"]was truthy AND_needs_deepseek_tool_reasoning()was TrueFix
Separates the Kimi (tool-call-only) and DeepSeek (all messages) fallback logic:
reasoning_content=""only on tool-call messagesreasoning_contentset on every assistant message, falling back to the content of thereasoningfield or empty stringThe replay safety net in
_copy_reasoning_content_for_api(step 4) already catches this edge case, but storing correct data from creation time is cleaner and avoids relying on the replay-time catch-all.Related
Refs #15250 (original DeepSeek tool-call
reasoning_contentfix), #15998 (this bug).Test Plan
pytest tests/run_agent/ -x -q