fix(transport): omit thinking_config for Gemma on the gemini provider (#17426)#17904
Merged
Conversation
…#17426) The `gemini` provider also serves Gemma (e.g. `gemma-4-31b-it`) and historically other Google models like PaLM. Those reject `extra_body.thinking_config` with HTTP 400: Unknown name "thinking_config": Cannot find field `_build_gemini_thinking_config()` was unconditionally producing a config dict for any model on the `gemini` / `google-gemini-cli` provider, which `ChatCompletionsTransport.build_kwargs` then dropped into `extra_body["thinking_config"]`. The result: every chat turn for Gemma users on the gemini provider blew up at the API edge. The fix is the same shape Hermes already uses for the Gemini-2.5 vs Gemini-3 family clamping: normalise the model id, strip an `OpenRouter`-style `google/` prefix, and short-circuit early when the result doesn't start with `gemini`. We return `None` rather than `{"includeThoughts": False}`, because the API rejects the field name itself — even the polite "off" form trips the same 400. Three regression tests cover Gemma with reasoning enabled, Gemma with reasoning disabled, and the `google/gemma-…` OpenRouter-style id; the existing Gemini-2.5 / Gemini-3 / `google/gemini-…` cases keep passing because the Gemini guard fires after the prefix strip. Fixes #17426 Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
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.
Salvage of #17441 by @briandevans onto current main.
Summary
On the
geminiprovider, omitthinking_configfrom the request whenever the model isn't actually Gemini (Gemma, PaLM, etc.). The Gemini API rejects unknown field names with HTTP 400 — including the polite{"includeThoughts": False}shape — so the field must be absent entirely, not merely disabled.Regression from the 2026.4.23 release (thinking_config bridging): Gemma users on the
geminiprovider gotHTTP 400: Unknown name "thinking_config": Cannot find fieldon every chat and exited immediately.Changes
agent/transports/chat_completions.py: move model-family detection into_build_gemini_thinking_config()— normalize model id, strip OpenRouter-stylegoogle/prefix, returnNonewhen the result doesn't start withgemini. Covers all three call sites (native gemini, OpenAI-compat nested-under-google, google-gemini-cli) since they all funnel through this helper.tests/agent/transports/test_chat_completions.py: +3 regression cases (gemma enabled, gemma disabled,google/-prefixed gemma).Validation
scripts/run_tests.sh tests/agent/transports/test_chat_completions.py→ 59 passed (56 existing Gemini cases unchanged, 3 new Gemma cases green).Fixes #17426.
Closes #17441.