fix: add DeepSeek reasoning_content echo for tool-call messages (fixes #15353)#15354
Closed
chen1749144759 wants to merge 1 commit into
Closed
fix: add DeepSeek reasoning_content echo for tool-call messages (fixes #15353)#15354chen1749144759 wants to merge 1 commit into
chen1749144759 wants to merge 1 commit into
Conversation
DeepSeek V4 thinking mode requires reasoning_content on every assistant message that includes tool_calls. When this field is missing from persisted history, replaying the session causes HTTP 400: 'The reasoning_content in the thinking mode must be passed back to the API.' Two-part fix (refs NousResearch#15250): 1. _copy_reasoning_content_for_api: Merge the Kimi-only and DeepSeek detection into a single needs_tool_reasoning_echo check. This handles already-poisoned persisted sessions by injecting an empty reasoning_content on replay. 2. _build_assistant_message: Store reasoning_content='' on new DeepSeek tool-call messages at creation time, preventing future session poisoning at the source. Additional fix: 3. _handle_max_iterations: Add missing call to _copy_reasoning_content_for_api in the max-iterations flush path (previously only main loop and flush_memories had it). Detection covers: - provider == 'deepseek' - model name containing 'deepseek' (case-insensitive) - base URL matching api.deepseek.com (for custom provider)
Contributor
|
Merged via PR #15407 — your commit We added a small refactor on top (extracted |
6 tasks
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.
Summary
DeepSeek V4 thinking mode requires
reasoning_contenton every assistant message that includestool_calls. When missing, replay causes HTTP 400.Closes #15353
Related: #14938 #14933 #15213
Changes
1. Merge DeepSeek into
needs_tool_reasoning_echocheckIn
_copy_reasoning_content_for_api(), replaced the Kimi-only detection with a combined check covering:provider == "deepseek""deepseek" in model(case-insensitive)api.deepseek.combase URL (custom provider)This handles already-poisoned persisted sessions by injecting empty
reasoning_contenton replay.2. Store
reasoning_contenton new tool-call messagesAdded
_needs_deepseek_tool_reasoning()helper method, wired into_build_assistant_message(). When a DeepSeek tool-call message is created without reasoning text (common for streaming tool-only turns), storesreasoning_content=""instead of omitting the field. Prevents future session poisoning at the source.3. Fix
_handle_max_iterationspathAdded missing call to
_copy_reasoning_content_for_api()in the max-iterations flush path. Previously only the main loop andflush_memories()had this call.Test Plan
reasoning_contentDiff
1 file changed:
run_agent.py(+30, -3)