Skip to content

fix(transport): omit thinking_config for Gemma on the gemini provider (#17426)#17904

Merged
teknium1 merged 1 commit into
mainfrom
hermes/hermes-4d399a1b
Apr 30, 2026
Merged

fix(transport): omit thinking_config for Gemma on the gemini provider (#17426)#17904
teknium1 merged 1 commit into
mainfrom
hermes/hermes-4d399a1b

Conversation

@teknium1

Copy link
Copy Markdown
Contributor

Salvage of #17441 by @briandevans onto current main.

Summary

On the gemini provider, omit thinking_config from 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 gemini provider got HTTP 400: Unknown name "thinking_config": Cannot find field on 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-style google/ prefix, return None when the result doesn't start with gemini. 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.py59 passed (56 existing Gemini cases unchanged, 3 new Gemma cases green).

Fixes #17426.
Closes #17441.

…#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>
@alt-glitch alt-glitch added type/bug Something isn't working P2 Medium — degraded but workaround exists comp/agent Core agent loop, run_agent.py, prompt builder provider/gemini Google Gemini (AI Studio, Cloud Code) labels Apr 30, 2026
@teknium1 teknium1 merged commit cc5b9fb into main Apr 30, 2026
11 of 12 checks passed
@teknium1 teknium1 deleted the hermes/hermes-4d399a1b branch April 30, 2026 11:29
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

comp/agent Core agent loop, run_agent.py, prompt builder P2 Medium — degraded but workaround exists provider/gemini Google Gemini (AI Studio, Cloud Code) type/bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug]: Model calls to google provider return 400 error with Invalid JSON payload on thinking_config

3 participants