Repository navigation
Gemini 3 and 4: sign handed-back tool calls in every engine that runs Gemini - #3
Closed
lorenzejay wants to merge 2 commits into
Closed
lorenzejay wants to merge 2 commits into
lorenzejay wants to merge 2 commits into
Conversation
… Gemini
Gemini 3 and later refuse a function call in the current turn without the thought signature the
model gave it ("Function call is missing a thought_signature in functionCall parts"). OpenBot runs
each tool between two runs and an AG-UI tool call has no field for a signature, so every engine
sent the handed-back call unsigned and every Bot on Gemini 3.x or 4 failed after its first tool.
- shared/gemini_signatures.py: every Python engine (ADK, AG2, CrewAI, LangChain, Langroid,
LlamaIndex, Strands) installs it beside run_model_key. It wraps httpx/httpx2 sends and aiohttp
requests and gives each unsigned call Google's documented placeholder,
`skip_thought_signature_validator`: on Gemini's own API (`functionCall` parts, any host) and on
Google's OpenAI-compatible endpoint or OpenBot's gateway for a Gemini model
(`extra_content.google.thought_signature`). A real signature is kept; any other provider's or
model's request is sent byte for byte.
- shared/gemini-signatures.ts: the same rules as a fetch wrapper, for LangGraph (TypeScript) and
Mastra's OpenAI-compatible clients. LangGraph's native path gets the placeholder in forGemini
when the thread brought no signature.
- LiteLLM engines (ADK, Strands, Langroid, CrewAI, LlamaIndex) address Gemini as `gemini/`, not
`google/` ("LLM Provider NOT provided"), through `litellm_model` in model_providers.py.
- AG2 answers `BOT_PROVIDER=google` with its GeminiConfig on the Google key, instead of the OpenAI
config that asked for OPENAI_API_KEY.
- scripts/model-compat.ts: the one run per model now hands back an unsigned tool call and its
result (`handBackRun`), so the lock no longer verifies a model a Bot cannot finish a tool call on.
- Tests: a hand-back test per engine against the shared fake provider (now also serving Gemini's
generateContent), signing-rule tests for both modules, model-compat's run body.
tests/compose.test.ts imports the LangChain harness with httpx stubbed as a bare module; the signer, installed at import, assumed httpx.Client and stopped the import. It now patches only a client that is there.
Owner
Author
|
Superseded by #4: the branch was renamed to |
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.
Why
Gemini 3 and later refuse a function call in the current turn that does not carry the thought
signature the model gave it:
OpenBot runs each tool between two runs, and an AG-UI tool call has no field for a signature, so
every engine handed the call back unsigned. Every Bot on Gemini 3.x or Gemini 4 failed as soon as a
tool's result came back. That happened with a Google AI Studio key saved in Settings or Desktop
(Google's OpenAI-compatible endpoint) and with
BOT_PROVIDER=google.Checked against the live API (2026-11-27) on
gemini-3.8-flashandgemini-4-hydrogen:generateContentskip_thought_signature_validator(raw or base64, one or two parallel calls)This PR stands alone. It does not depend on the default-model PR (#2).
What changes
Signing, once per language, at the HTTP request
shared/gemini_signatures.pyis installed by every Python engine (ADK, AG2, CrewAI, LangChain,Langroid, LlamaIndex, Strands), beside
run_model_key. It wrapshttpx/httpx2sends andaiohttprequests (google-genai sends throughaiohttpwhen that is installed). It gives eachunsigned call Google's documented placeholder in two places:
functionCallpart, on a POST to.../models/gemini-*:(stream)generateContent, on any host.extra_content.google.thought_signatureon the tool call.A real signature is kept. A request to any other provider, or for any other model, is sent byte
for byte.
shared/gemini-signatures.tshas the same rules as afetchwrapper. LangGraph (TypeScript) andMastra pass it to their OpenAI-compatible clients. On its native path, LangGraph (TypeScript)
adds the placeholder in
forGeminiwhen the thread brought back no signature. The real one stilltravels as
encryptedValuewhen the server keeps it.BOT_PROVIDER=googlereaches Gemini at allgoogle/<model>, but LiteLLM readsgemini/, so they failed with "LLM Provider NOT provided". Fixed throughlitellm_modelinshared/model_providers.py.OPENAI_API_KEY. It now uses AG2'sGeminiConfigwith the Google key. This adds theag2[gemini]extra, with google-genai held<3like the other engines. AG2's Gemini config also round-trips the real signature asREASONING_ENCRYPTED_VALUE.
CI catches it
scripts/model-compat.ts: the one run per model is now a hand-back (handBackRun): the user'sask, the assistant's unsigned call to
look_up_order, and its result. A model a Bot cannot finisha tool call on no longer passes, and so no longer gets into the lock.
model-lock.jsonisuntouched; CI writes it.
Not changed
call as a function call. It passed the live hand-back unchanged.
BOT_PROVIDER=googleat startup bydesign. Its Gemini path is Google's compatible endpoint, which is now signed.
real calls are covered if the router changes.
Tests
One
test_gemini_handback.pyper Python engine. Each runs the real AG-UI endpoint against theshared fake provider, which now also serves Gemini's
generateContent. It checks two things:BOT_PROVIDER=googleand on a compatible address with a Gemini model, the handed-back callreaches the model signed.
With the signer switched off, the compatible-path case fails in every engine.
agent-adk/tests/test_gemini_signatures.pyandshared/gemini-signatures.test.tscover thesigning rules: hosts, model names, keeping a real signature, leaving other providers alone, and
the wrapped clients.
LangGraph (TS)
hand-back.test.tsand Mastraindex.test.tsadd hand-back cases. They failwithout the fix.
scripts/model-compat.test.tscovers the run body.Live hand-back runs (2026-11-27, paid-tier key, images built from this branch's head)
Each run hands back an unsigned
look_up_ordercall and its result, and passes when the engineanswers "Order 42 has shipped" or similar. "Compatible" is Google's OpenAI-compatible endpoint,
which is how Desktop and Settings save a Gemini key. "Native" is
BOT_PROVIDER=google.Mastra loads no Google module and refuses
BOT_PROVIDER=googleat startup, as before. Its Geminipath is the compatible endpoint.
Before this change, the published
latestimages failed every compatible-path cell with "Functioncall is missing a thought_signature". On the native path, ADK, Strands, Langroid and CrewAI failed
with "LLM Provider NOT provided", and AG2 asked for an OpenAI key.
Checks run locally:
npm testandtypecheck;bun test;shared/andscripts/bun tests;tests/compose.test.ts;