feat(models): add extended thinking support for AnthropicLlm#5392
Open
sebastienc wants to merge 3 commits intogoogle:mainfrom
Open
feat(models): add extended thinking support for AnthropicLlm#5392sebastienc wants to merge 3 commits intogoogle:mainfrom
sebastienc wants to merge 3 commits intogoogle:mainfrom
Conversation
This was referenced Apr 19, 2026
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
Fixes #3079
Disclaimer: I'm using Claude Code to generate the following text. I find the summary is better than what I would've wrote.
Adds extended thinking (reasoning token) support for
AnthropicLlmandClaude(Vertex AI), addressing the long-standing gap vs. Gemini's native thinking support._build_thinking_param— mapsllm_request.config.thinking_config.thinking_budgetto Anthropic'sThinkingConfigEnabledParam; clamps tomax_tokens - 1to satisfy the API constraint; returnsNOT_GIVENwhen thinking is not configuredpart_to_message_block— newpart.thought=Truebranch (checked beforepart.textto avoid misclassification) producesThinkingBlockParamorRedactedThinkingBlockParamfor multi-turn continuitycontent_block_to_part— handlesThinkingBlockandRedactedThinkingBlockresponse blocks, converting them toPart(thought=True, thought_signature=…)matching the pattern used byLiteLlmgenerate_content_async— passesthinkingparam to both streaming and non-streamingmessages.createcalls_generate_content_streaming— accumulatesThinkingDeltaandSignatureDeltaevents into a new_ThinkingAccumulator; thinking blocks appear in the final aggregated response only (not as partials, keeping consumers simple);RedactedThinkingBlockdata captured atcontent_block_start_ThinkingAccumulator— PydanticBaseModel(consistent with streaming accumulators inlite_llm.py)Note on previous PR #3070: that PR was closed because it used the synchronous Anthropic client after the codebase had migrated to
AsyncAnthropic. This implementation is fully async and uses the nativethinkingparameter available in the current SDK — no beta headers required.Testing plan
Unit tests
18 new tests added to
tests/unittests/models/test_anthropic_llm.py, all passing. Full suite: 59 passed.Manual E2E test
Sample agent:
contributing/samples/hello_world_anthropic_thinking/Uses
AnthropicLlm(model="claude-sonnet-4-6")withBuiltInPlanner(thinking_config=types.ThinkingConfig(thinking_budget=5000)).The thinking block text (
The user wants to check which of the numbers…) surfaces in the event stream before the final response, confirming theThinkingBlock → Part(thought=True)pipeline works end-to-end. Two successfulPOST /v1/messagescalls observed (first: thinking + tool call; second: tool result → final answer).