fix: preserve empty reasoning_content for DeepSeek thinking mode across turns#15237
Closed
duouoduo wants to merge 2 commits into
Closed
fix: preserve empty reasoning_content for DeepSeek thinking mode across turns#15237duouoduo wants to merge 2 commits into
duouoduo wants to merge 2 commits into
Conversation
…ss turns - _extract_reasoning: use isinstance(str) instead of truthy check to capture empty reasoning strings from DeepSeek thinking mode - _copy_reasoning_content_for_api: remove truthy guard so empty reasoning is still replayed as reasoning_content in API requests - chat_completions transport: use is not None instead of truthy check for reasoning_content and reasoning_details fields - Expand requires_reasoning to cover deepseek provider and api.deepseek.com base URL - Add deepseek- to reasoning_model_prefixes Fixes HTTP 400: 'The reasoning_content in the thinking mode must be passed back to the API.'
…nt from NousResearch#15228 - _copy_reasoning_content_for_api: split DeepSeek into separate block, use setdefault instead of tool_calls-gated assignment, so empty reasoning_content is set on ALL assistant messages (not just tool-call) - chat_completions.py build_kwargs: add is_deepseek flag + thinking mode toggle (thinking: {type: enabled|disabled}) for native DeepSeek API - _build_api_kwargs: plumb _is_deepseek through to transport params - Keep our complementary fixes: isinstance checks in _extract_reasoning, is not None in chat_completions transport, deepseek- prefix
Collaborator
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.
What does this PR do?
Fixes HTTP 400 error from DeepSeek API: "The reasoning_content in the thinking mode must be passed back to the API."
DeepSeek v4 Flash has a "thinking mode" where the model returns
reasoning_contentin its responses. The API requires this field to be preserved and replayed in subsequent requests — even if it is an empty string during tool-call turns. Hermes was using truthy checks (if reasoning_content:) that silently dropped empty strings, breaking the thinking mode state across multi-turn conversations.Changes
run_agent.py—_extract_reasoning: Replaced truthy check withisinstance(r, str), so empty reasoning strings are captured.run_agent.py—_copy_reasoning_content_for_api: Removed truthy guard so empty reasoning is replayed. Expanded provider list to cover DeepSeek (by name, base URL, model prefix).agent/transports/chat_completions.py: Changedif reasoning_content:toif reasoning_content is not None(same forreasoning_details), preserving empty strings/lists.Type of Change
How to Test
deepseek-v4-flash(thinking mode model)Checklist