Repository navigation
Conversation
AnthropicLlm always sent thinking.display "summarized" for adaptive
thinking and ignored ThinkingConfig.include_thoughts. Callers could not
get the API's own default ("omitted" on Claude Opus 4.7 and later), so
every model turn carried a reasoning summary in its thought parts.
Read include_thoughts: False now sends display "omitted", for adaptive
thinking and for a manual budget. None and True send the same request
as before.
types.ThinkingConfig(thinking_budget=-1, include_thoughts=False)
# "thinking": {"type": "adaptive", "display": "omitted"}
Omitted thinking blocks arrive with empty text and a signature. They are
already sent back as thinking blocks, so tool loops keep working; new
tests cover that in the streaming and non-streaming paths.
Fixes google#8377
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.
Please ensure you have read the contribution guide before creating a pull request.
Link to Issue or Description of Change
1. Link to an existing issue (if applicable):
Problem:
AnthropicLlmmaps a negativethinking_budgetto{"type": "adaptive", "display": "summarized"}, fixed, and never readsThinkingConfig.include_thoughts(code).
A caller who turns on adaptive thinking always gets Claude's reasoning
summaries back as thought parts, and can't choose the API's own default,
"omitted"on Claude Opus 4.7 and later. The parts are then stored insession events and reach logs, telemetry and memory.
Solution:
Read
include_thoughtsin_build_anthropic_thinking_param:include_thoughtsthinking_budget < 0thinking_budget > 0None(default)display: "summarized"(unchanged)display(unchanged)Truedisplay: "summarized"(unchanged)display(unchanged)Falsedisplay: "omitted"display: "omitted"thinking_budget=0still sends{"type": "disabled"}only; Claude rejectsdisplaythere.NoneandTruesend the same request as before, so nothing changes forexisting configs that don't set
include_thoughts=False.displayon"enabled"is allowed by theAnthropic docs
and typed on
ThinkingConfigEnabledParamin currentanthropicreleases.On a manual budget it is sent only for
False: the models that stillaccept
"enabled"return summaries by default, soNone/Trueneed nofield there.
include_thoughtsis the provider-neutral switch genai already has, andLiteLlmalready readsinclude_thoughts=Falseas "no thought parts". AClaude-specific field on
AnthropicGenerateContentConfig(likeeffort)is the alternative discussed in the issue; it can be added later on top of
this.
_build_anthropic_thinking_paramno longer says the reasoningalways comes back as summarized thoughts, and the
AnthropicLlmandClaudeclass docstrings mention the switch. The old comment "Withoutdisplay, Claude redacts the reasoning it just billed for" is replaced:omitted thinking is not redacted thinking, and it is billed the same.
With
"omitted", Claude still returnsthinkingblocks, with empty text anda signature. They become thought parts with
text=""andthought_signature, and #7500 already sends them back asthinkingblocksrather than
redacted_thinking. This PR adds tests that pin that round tripin both paths.
Testing Plan
Unit Tests:
New and changed tests in
tests/unittests/models/test_anthropic_llm.py:test_build_anthropic_thinking_param_adaptive_display_follows_include_thoughts(
None,True→"summarized";False→"omitted")test_build_anthropic_thinking_param_manual_budget_omits_excluded_thoughts(
False+ budget 2048 →display: "omitted")test_build_anthropic_thinking_param_manual_budget_omits_display, now runfor
include_thoughtsNoneandTruetest_build_anthropic_thinking_param_disabled_ignores_include_thoughtstest_non_streaming_requests_omitted_display_without_thoughts(throughgenerate_content_async)test_omitted_thinking_block_is_sent_back_unchanged(non-streamingresponse → history → next request)
test_streaming_thinking_captures_signature_deltagains the[""]case,the event sequence the docs give for
"omitted": one emptythinking_delta, thensignature_deltaResults on macOS,
anthropic2.10.0,google-genai2.34.0, with eachversion's environment built from
uv.lock(uv sync --locked --extra test),the same as
tox.ini:Python 3.15 (listed in
pyproject.toml, not in CI): thetestextra doesnot install, because
fastuuid(pulled in bylitellm) has no 3.15 wheeland fails to build. With only the packages this test file imports installed,
pytest tests/unittests/models/test_anthropic_llm.pygives293 passedon3.15.2.
Checked that the tests catch regressions:
anthropic_llm.pychange reverted, 3 tests fail: theFalsecase of the adaptive test, the manual-budget
Falsetest, and thegenerate_content_asynctest. The rest pin unchanged behavior.if part.thought and part.text:), 4 testsfail:
test_omitted_thinking_block_is_sent_back_unchanged, the""caseof
test_part_to_message_block_thinking_roundtrip, and the[]and[""]cases of the streaming test.pre-commit run --fileson both files passes, andmypyreports the sametwo existing errors in
anthropic_llm.pybefore and after.Manual End-to-End (E2E) Tests:
Live, against the Claude API (
claude-haiku-5-5, 26 Nov 2026). OneLlmAgentwith two function tools runs two user turns in one session throughRunner, so each run makes six requests. The first reply's thinking blockgoes back to Claude in the following tool-loop requests, and then again in
the second turn's history. A request hook records each request body. The
script prints the
thinkingparameter of each request and the thinkingblocks it replays, then the thought parts stored in the session.
include_thoughtsunset: unchanged.display: "summarized", and thesession stores summary text.
include_thoughts=False, without and with streaming:display: "omitted". The session stores thought parts with empty text anda signature, and every later request replays them as
thinkingblocks withempty text. Claude accepts all twelve requests, and the answers match run A.
The script
Also an offline
Runnercheck: a realAsyncAnthropicclient with anhttpx2.MockTransportthat answers like Claude under"omitted"(signedthinking blocks with empty text, a tool call, then text). No API key, no
network. The agent sets
ThinkingConfig(thinking_budget=-1, include_thoughts=False)and calls onetool, so each run makes two requests. The script checks the
thinkingparameter on both requests and that the second request replays the first
reply's thinking block unchanged.
Output
Before (main, excerpt):
After:
Script
Run with the branch installed (
uv sync --all-extras):Checklist
Additional context
adk-docs
docs/agents/models/anthropic.mdsays "ADK returns Claude's reasoning as thought parts in the response". I
can send a docs PR adding one sentence: set
include_thoughts=Falseto getthe thought parts with empty text (Claude's
display: "omitted")."summarized"inbuildThinkingParam. ItsIncludeThoughtsis a plainbool, so the Go side needs a differentswitch; I'll raise that there separately.
🤖 Generated with Claude Code