feat(agent): preserve Anthropic thinking blocks and enable interleaved thinking#120
Merged
spachava753 merged 1 commit intomainfrom Dec 22, 2025
Merged
Conversation
…d thinking When resuming conversations across different providers, thinking blocks from one provider (e.g., Gemini) are incompatible with another (e.g., Anthropic). Previously, CPE filtered out all thinking blocks, but this prevented Claude from benefiting from its own preserved reasoning when resuming conversations. The new AnthropicThinkingBlockFilter identifies Anthropic thinking blocks by checking for the `anthropic_thinking_signature` key in ExtraFields, keeping those while filtering out thinking blocks from other providers. Non-Anthropic generators continue to use the existing BlockWhitelistFilter that removes all thinking blocks. Additionally, Anthropic API requests now include beta headers for interleaved thinking (`interleaved-thinking-2025-05-14`) and server-side context management (`context-management-2025-06-27`), enabling Claude to reason between tool calls and allowing the API to manage thinking block retention automatically. Closes #115
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
When resuming conversations across different providers, thinking blocks from one provider (e.g., Gemini) are incompatible with another (e.g., Anthropic). Previously, CPE filtered out all thinking blocks, but this prevented Claude from benefiting from its own preserved reasoning when resuming conversations.
Changes
New AnthropicThinkingBlockFilter: Identifies Anthropic thinking blocks by checking for the
anthropic_thinking_signaturekey in ExtraFields, keeping those while filtering out thinking blocks from other providers. Non-Anthropic generators continue to use the existing BlockWhitelistFilter.Beta headers for Anthropic: API requests now include:
interleaved-thinking-2025-05-14- enables Claude to reason between tool callscontext-management-2025-06-27- enables server-side thinking block retention managementTesting
Added comprehensive tests for the new filter covering Anthropic/Gemini/OpenRouter thinking blocks, edge cases, and mixed provider conversations.
Closes #115