Repository navigation
fix(models): forward generation config parameters in AnthropicLlm - #5513
Closed
sebastienc wants to merge 3 commits into
Closed
sebastienc wants to merge 3 commits into
sebastienc wants to merge 3 commits into
Conversation
sebastienc
force-pushed
the
feat/anthropic-generation-config
branch
from
May 5, 2026 13:45
3770e28 to
ac78062
Compare
Contributor
Author
|
Fixed the pyink issue and rebased. |
Collaborator
|
Hi @xuanyang15 , can you please review this. |
Collaborator
|
@GWeale Could you please help take a look? |
Contributor
Author
|
Hi @rohityan , has someone else added these changes? Why has the PR been closed? Thanks. |
copybara-service Bot
pushed a commit
that referenced
this pull request
Jun 29, 2026
… propagation, and conflict mitigation
Key changes:
- Reasoning Effort Support for anthropic model: Introduces AnthropicGenerateContentConfig to allow users to set the effort field directly ("low", "medium", "high", "xhigh", "max") for Anthropic model effort level.
- the standard thinking_config.thinking_level was not passed to anthropic effort due to mapping inconsistencies between the 4-level standard enum and Anthropic's 5 effort levels. It will raise a warning.
- Conflict Mitigation: Automatically excludes sampling parameters (temperature, top_p, top_k) when thinking or reasoning effort is enabled, avoiding Anthropic API 400 errors. Emits a warning log if these parameters were provided but ignored.
- Unified Parameter Propagation: Propagates core GenerateContentConfig parameters (temperature, top_p, top_k, stop_sequences, and max_output_tokens [mapped to max_tokens]) to the Anthropic client using the new _build_anthropic_kwargs helper.
- Type Annotation Updates: Adds ThinkingConfigAdaptiveParam to the thinking parameter type annotations across streaming and non-streaming interfaces.
Note for callers:
- This is a behavior change for existing Anthropic
model callers. Previously, temperature, top_p, top_k, stop_sequences,
and max_output_tokens were ignored (dropped) for Claude. They are now
correctly propagated to the Anthropic client, and max_output_tokens
will now correctly override the default max_tokens (8192).
Fixes: #5393
Closes: #5513
Co-authored-by: Yi Liu <yiliuly@google.com>
COPYBARA_INTEGRATE_REVIEW=#5513 from sebastienc:feat/anthropic-generation-config 0276484
PiperOrigin-RevId: 940074181
FrigaZzz
pushed a commit
to FrigaZzz/adk-python
that referenced
this pull request
Aug 11, 2026
… propagation, and conflict mitigation
Key changes:
- Reasoning Effort Support for anthropic model: Introduces AnthropicGenerateContentConfig to allow users to set the effort field directly ("low", "medium", "high", "xhigh", "max") for Anthropic model effort level.
- the standard thinking_config.thinking_level was not passed to anthropic effort due to mapping inconsistencies between the 4-level standard enum and Anthropic's 5 effort levels. It will raise a warning.
- Conflict Mitigation: Automatically excludes sampling parameters (temperature, top_p, top_k) when thinking or reasoning effort is enabled, avoiding Anthropic API 400 errors. Emits a warning log if these parameters were provided but ignored.
- Unified Parameter Propagation: Propagates core GenerateContentConfig parameters (temperature, top_p, top_k, stop_sequences, and max_output_tokens [mapped to max_tokens]) to the Anthropic client using the new _build_anthropic_kwargs helper.
- Type Annotation Updates: Adds ThinkingConfigAdaptiveParam to the thinking parameter type annotations across streaming and non-streaming interfaces.
Note for callers:
- This is a behavior change for existing Anthropic
model callers. Previously, temperature, top_p, top_k, stop_sequences,
and max_output_tokens were ignored (dropped) for Claude. They are now
correctly propagated to the Anthropic client, and max_output_tokens
will now correctly override the default max_tokens (8192).
Fixes: google#5393
Closes: google#5513
Co-authored-by: Yi Liu <yiliuly@google.com>
COPYBARA_INTEGRATE_REVIEW=google#5513 from sebastienc:feat/anthropic-generation-config 0276484
PiperOrigin-RevId: 940074181
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 #5393
Disclaimer: I'm using Claude Code to generate the following text. I find the summary is better than what I would've wrote.
AnthropicLlmwas silently ignoringtemperature,top_p,top_k, andstop_sequencesfromGenerateContentConfig. This change wires them through to both the streaming and non-streamingmessages.createcalls, and addsoutput_config.effortsupport via a newAnthropicGenerateContentConfigescape hatch and aThinkingLevel→ effort mapping.temperature/top_p/top_k/stop_sequences— forwarded tomessages.createin both streaming and non-streaming paths; each is guarded byis not Noneso unset params remainNOT_GIVENrather thanNonetemperature,top_p, andtop_kare suppressed (sent asNOT_GIVEN) whenoutput_config.effortis active, since Anthropic does not allow sampling parameters alongside effort-based generation_build_effort_param— mapsThinkingConfig.thinking_levelto Anthropic'soutput_config.effortstring (MINIMAL→"low",LOW→"medium",MEDIUM→"high",HIGH→"xhigh"); also readsAnthropicGenerateContentConfig.effortdirectly for cases needing"max"AnthropicGenerateContentConfig— subclass ofGenerateContentConfigthat adds a singleeffortfield accepting"low" | "medium" | "high" | "xhigh" | "max"; callers who need the"max"effort level (not expressible viaThinkingLevel) can pass this config insteadTesting plan
12 new tests added to
tests/unittests/models/test_anthropic_llm.py. Full suite: 71 passed.