Skip to content

fix(models): forward generation config parameters in AnthropicLlm#5513

Open
sebastienc wants to merge 2 commits intogoogle:mainfrom
sebastienc:feat/anthropic-generation-config
Open

fix(models): forward generation config parameters in AnthropicLlm#5513
sebastienc wants to merge 2 commits intogoogle:mainfrom
sebastienc:feat/anthropic-generation-config

Conversation

@sebastienc
Copy link
Copy Markdown

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.

AnthropicLlm was silently ignoring temperature, top_p, top_k, and stop_sequences from GenerateContentConfig. This change wires them through to both the streaming and non-streaming messages.create calls, and adds output_config.effort support via a new AnthropicGenerateContentConfig escape hatch and a ThinkingLevel → effort mapping.

  • temperature / top_p / top_k / stop_sequences — forwarded to messages.create in both streaming and non-streaming paths; each is guarded by is not None so unset params remain NOT_GIVEN rather than None
  • Sampling params disabled when effort is settemperature, top_p, and top_k are suppressed (sent as NOT_GIVEN) when output_config.effort is active, since Anthropic does not allow sampling parameters alongside effort-based generation
  • _build_effort_param — maps ThinkingConfig.thinking_level to Anthropic's output_config.effort string (MINIMAL"low", LOW"medium", MEDIUM"high", HIGH"xhigh"); also reads AnthropicGenerateContentConfig.effort directly for cases needing "max"
  • AnthropicGenerateContentConfig — subclass of GenerateContentConfig that adds a single effort field accepting "low" | "medium" | "high" | "xhigh" | "max"; callers who need the "max" effort level (not expressible via ThinkingLevel) can pass this config instead

Testing plan

12 new tests added to tests/unittests/models/test_anthropic_llm.py. Full suite: 71 passed.

tests/unittests/models/test_anthropic_llm.py::test_non_streaming_forwards_generation_params PASSED
tests/unittests/models/test_anthropic_llm.py::test_non_streaming_omits_unset_generation_params PASSED
tests/unittests/models/test_anthropic_llm.py::test_streaming_forwards_generation_params PASSED
tests/unittests/models/test_anthropic_llm.py::test_streaming_omits_unset_generation_params PASSED
tests/unittests/models/test_anthropic_llm.py::test_thinking_level_maps_to_effort[MINIMAL-low] PASSED
tests/unittests/models/test_anthropic_llm.py::test_thinking_level_maps_to_effort[LOW-medium] PASSED
tests/unittests/models/test_anthropic_llm.py::test_thinking_level_maps_to_effort[MEDIUM-high] PASSED
tests/unittests/models/test_anthropic_llm.py::test_thinking_level_maps_to_effort[HIGH-xhigh] PASSED
tests/unittests/models/test_anthropic_llm.py::test_anthropic_config_effort_max_non_streaming PASSED
tests/unittests/models/test_anthropic_llm.py::test_anthropic_config_effort_max_streaming PASSED
tests/unittests/models/test_anthropic_llm.py::test_no_effort_when_thinking_level_unset PASSED
tests/unittests/models/test_anthropic_llm.py::test_effort_takes_priority_over_sampling_params PASSED

@adk-bot adk-bot added the models [Component] Issues related to model support label Apr 28, 2026
@rohityan rohityan self-assigned this Apr 30, 2026
@sebastienc sebastienc force-pushed the feat/anthropic-generation-config branch from 3770e28 to ac78062 Compare May 5, 2026 13:45
@sebastienc
Copy link
Copy Markdown
Author

Fixed the pyink issue and rebased.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

models [Component] Issues related to model support

Projects

None yet

Development

Successfully merging this pull request may close these issues.

AnthropicLlm silently ignores generation config parameters

3 participants