fix(anthropic): preserve thinking blocks on DeepSeek's /anthropic endpoint#16149
Closed
comxtohr wants to merge 1 commit into
Closed
fix(anthropic): preserve thinking blocks on DeepSeek's /anthropic endpoint#16149comxtohr wants to merge 1 commit into
comxtohr wants to merge 1 commit into
Conversation
…point
DeepSeek's anthropic-compat endpoint requires thinking blocks (with their
DeepSeek-issued signatures) to be replayed unchanged on subsequent turns
when thinking mode is enabled. The generic third-party path strips them
to avoid Anthropic-signature validation errors on other proxies, which
caused HTTP 400::
The content[].thinking in the thinking mode must be passed back to
the API.
Detect ``api.deepseek.com/anthropic`` and skip the strip — DeepSeek's
signatures are its own and DeepSeek validates them. cache_control is
still stripped from thinking blocks (unchanged from prior behavior).
This was referenced Apr 28, 2026
Contributor
|
Superseded by PR #17510, which uses the Kimi-parity strip-signed / keep-unsigned pattern (matching DeepSeek's published Anthropic-compat matrix — |
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's anthropic-compat endpoint (
https://api.deepseek.com/anthropic) requires that anythinking/redacted_thinkingblocks returned in assistant messages be replayed unchanged (signature included) on subsequent turns when thinking mode is enabled.convert_messages_to_anthropiccurrently treats DeepSeek as a generic third-party Anthropic endpoint and strips all thinking blocks, which causes DeepSeek to reject the next request with HTTP 400:The signatures DeepSeek issues are its own — not Anthropic's — so DeepSeek can and does validate them. This PR adds an endpoint-detection helper analogous to
_is_kimi_coding_endpointand skips the thinking-block strip for DeepSeek.cache_controlis still stripped from thinking blocks (unchanged from prior behavior on every endpoint).Related: #15700 (same error text, same endpoint, complementary failure mode — that issue describes the thinking-disabled path which still needs an explicit
thinking: {"type": "disabled"}to be sent; this PR fixes the thinking-enabled path. See my comment there for the breakdown.)Note: #16135 / #16137 / #15717 surface a similar-looking 400 but the error text is
reasoning_content(OpenAI-compat route, fixed in_copy_reasoning_content_for_api), notcontent[].thinking(anthropic-compat route, this PR). Different code path.Reproduction
Configure Hermes against DeepSeek's anthropic-compat endpoint with thinking enabled:
Issue any prompt that triggers a multi-turn exchange (tool use, follow-up, etc.). The second turn 400s with the message above.
Changes
agent/anthropic_adapter.py: add_is_deepseek_anthropic_endpoint(base_url)and a corresponding branch in the thinking-block management loop that preservesthinking/redacted_thinkingblocks unchanged.tests/agent/test_deepseek_anthropic_thinking.py: new regression suite covering endpoint detection (incl. casing/trailing-slash variants), preservation across multiple prior assistant turns, redacted blocks,cache_controlstripping, and non-regression on MiniMax + native Anthropic paths.Test plan
pytest tests/agent/test_deepseek_anthropic_thinking.py tests/agent/test_kimi_coding_anthropic_thinking.py tests/agent/test_anthropic_adapter.py— 164 passeddeepseek-v4-prowithreasoning_effort: xhigh— multi-turn conversations no longer 400Closes part of #15700 (enabled-thinking path).