fix(google): route Gemma 4 thinking through thinking_level - #7095
Merged
Conversation
_is_gemini_3_model() matches the substring "gemini-3", so gemma-4-* models fell into the thinking_budget branch and chat() raised a ValueError on the first turn for any caller that set thinking_level. The Gemini API rejects thinking_budget for Gemma 4, so thinking could not be controlled at all. A new _supports_thinking_level() predicate routes Gemma 4 down the same level branch as Gemini 3. _is_gemini_3_model() itself is unchanged, so provider/function tool mixing and thought signatures still stay off for Gemma. The level is sent as given, because only the API knows which levels a model accepts, and a default level is only chosen for Gemini 3, whose accepted levels are known. The shared level branch now also keeps include_thoughts, which it discarded before for Gemini 3 as well.
davidzhao
approved these changes
Sep 2, 2026
_is_gemma_4_model and _is_gemini_3_flash_model matched on a prefix while _is_gemini_3_model matched on a substring, so a qualified name split them. models/gemma-4-31b-it fell past the level branch and raised ValueError before any request, and models/gemini-3-flash-preview lost its minimal default. Both now match on a substring. Gemma 4 answers thinking_level low and medium with 400 INVALID_ARGUMENT; it toggles thinking with minimal and high only. The level is checked in __init__ against those two, so a wrong one fails at construction instead of on the first turn. google-genai 2.13, the declared floor, already carries ThinkingConfig.thinking_level, so drop the getattr fallbacks and build the config with types.ThinkingConfig like the budget branch does. refs #7071
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.
Problem:
_is_gemini_3_model()matches the substringgemini-3, sogemma-4-*models land in thethinking_budgetbranch andchat()raisesValueErroron the first user turn when the caller setsthinking_level. The Gemini API rejectsthinking_budgetfor Gemma 4, so no caller can control thinking on those models through the plugin.Fix:
_supports_thinking_level()sends Gemma 4 down the same level branch as Gemini 3, which now also keepsinclude_thoughts, and every model predicate matches on a substring so a qualified name such asmodels/gemma-4-31b-itcannot fall out of it. Gemma 4 acceptsminimalandhighonly, so__init__rejects the other two levels instead of letting the API answer the first turn with 400.Replaces #7080, whose predicate split this keeps. Close #7071.
Context for reviewing and coding agents