fix(agent): send thinking control to DeepSeek direct API to prevent 400 on tool-call replay#17225
Closed
luyao618 wants to merge 1 commit into
Closed
Conversation
b9675a4 to
3a2d7d6
Compare
…00 on tool-call replay DeepSeek's direct API (api.deepseek.com) defaults to thinking=enabled when no explicit thinking parameter is sent. This causes the model to generate reasoning_content in responses, which must be replayed on subsequent API calls. When the user sets reasoning_effort: none, the config was silently ignored because _supports_reasoning_extra_body() returns False for direct DeepSeek — so extra_body.reasoning was never sent. The model defaulted to thinking=enabled, generated reasoning_content, and the next API call failed with 400 'reasoning_content must be passed back'. Add DeepSeek direct API thinking control to ChatCompletionsTransport, following the existing Kimi pattern: emit extra_body.thinking with type 'enabled' or 'disabled' based on reasoning_config. Thread is_deepseek_direct from run_agent.py (detected via provider name or base_url matching api.deepseek.com). OpenRouter DeepSeek path is unchanged — it uses extra_body.reasoning which is a separate parameter handled by the existing supports_reasoning gate. Fixes NousResearch#17212
3a2d7d6 to
444c454
Compare
Contributor
Author
|
Closing: this PR has merge conflicts and the codebase has moved on. Will re-submit if the fix is still needed. |
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?
DeepSeek's direct API (
api.deepseek.com) defaults tothinking=enabledwhen no explicitthinkingparameter is sent. When the user setsreasoning_effort: nonein config, the setting was silently ignored because_supports_reasoning_extra_body()returnsFalsefor direct DeepSeek endpoints — soextra_body.reasoning(OpenRouter format) was never sent. The model defaulted to thinking=enabled, generatedreasoning_contentin its response, and the next API call failed with HTTP 400:"reasoning_content must be passed back".This PR adds DeepSeek direct API thinking control to
ChatCompletionsTransport.build_kwargs(), following the existing Kimi pattern: emitextra_body.thinkingwithtype: "enabled"ortype: "disabled"based on the user'sreasoning_config. Theis_deepseek_directflag is threaded fromrun_agent.py, detected via provider name (deepseek) or base URL matching (api.deepseek.com).The OpenRouter DeepSeek path is unchanged — it uses
extra_body.reasoningwhich is a separate parameter handled by the existingsupports_reasoninggate.Related Issue
Fixes #17212
Type of Change
Changes Made
agent/transports/chat_completions.py: Added DeepSeek direct APIextra_body.thinkingblock (after existing Kimi block), withenabled/disabledcontrol based onreasoning_configrun_agent.py: Added_is_deepseek_directdetection (provider == "deepseek" or base_url matches api.deepseek.com) and threaded it to transport paramstests/agent/transports/test_chat_completions.py: Added 5 test cases covering default enabled, disabled via config, effort=none, OpenRouter unchanged, Kimi unchangedHow to Test
api.deepseek.com) andreasoning_effort: nonepytest tests/agent/transports/test_chat_completions.py -vpytest tests/ -q --ignore=tests/integration --ignore=tests/e2eChecklist
Code
pytest tests/ -qand all tests passDocumentation & Housekeeping