Skip to content

Gemini 3 and 4: sign handed-back tool calls on every engine that runs Gemini - #2365

Closed
lorenzejay wants to merge 3 commits into
CopilotKit:mainfrom
lorenzejay:fix/gemini-thought-signatures
Closed

lorenzejay wants to merge 3 commits into
CopilotKit:mainfrom
lorenzejay:fix/gemini-thought-signatures

Conversation

@lorenzejay

@lorenzejay lorenzejay commented Nov 28, 2026 •

Copy link
Copy Markdown

Fixes #2363.

What this changes

Gemini 3 and later refuse a function call in the current turn that does not carry 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. #2334
and #2335 carry the real signature through the thread on the two LangGraph engines. Every other
engine still handed the call back unsigned, so a Bot on Gemini 3.x or Gemini 4 failed as soon as a
tool's result came back. That happens with a key saved as Google's OpenAI-compatible endpoint (how
OpenBot Desktop and Settings save a Gemini key), on ADK, AG2, CrewAI, Langroid, Mastra and Strands.

Checked against the live API (2026-11-27) on gemini-3.8-flash and gemini-4-hydrogen:

request native generateContent OpenAI-compatible
handed-back call, no signature 400 missing thought_signature 400 missing thought_signature
with skip_thought_signature_validator (raw or base64, one or two parallel calls) OK OK

Signing, once per language, at the HTTP request

  • shared/gemini_signatures.py: ADK, AG2, CrewAI, Langroid, LlamaIndex and Strands install it beside
    run_model_key. It wraps httpx/httpx2 sends and aiohttp requests (google-genai sends through
    aiohttp when that is installed). It gives an unsigned call Google's documented placeholder:

    • on Gemini's own API: a functionCall part, on a POST to
      .../models/gemini-*:(stream)generateContent, on any host;
    • on Google's OpenAI-compatible endpoint, or OpenBot's gateway asked for a Gemini model:
      extra_content.google.thought_signature on 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.ts: the same rules as a fetch wrapper, passed to Mastra's
    OpenAI-compatible client.

  • LangGraph (Python) installs the Python signer too, on top of LangGraph (Python): keep Gemini's thought signature on a tool call #2335. thought_signatures.py
    sends back the signature the thread carries. A thread without one (a conversation from before
    1.2.2, or a caller that drops encryptedValue) still reached the compatible endpoint unsigned and
    was refused; the signer fills in the placeholder only there. LangGraph (TypeScript) already does
    this in thought-signatures.ts and is not changed.

BOT_PROVIDER=google reaches Gemini at all

  • ADK, Strands, Langroid, CrewAI and LlamaIndex built google/<model>, but LiteLLM reads gemini/,
    so they failed with "LLM Provider NOT provided". Fixed through litellm_model in
    shared/model_providers.py.
  • AG2 fell through to its OpenAI config and asked for OPENAI_API_KEY. It now uses AG2's
    GeminiConfig with the Google key. This adds the ag2[gemini] extra, with google-genai held <3
    like the other engines.

The model check catches it

  • scripts/model-compat.ts: the one run per model is now a hand-back (handBackRun): the user's
    ask, the assistant's unsigned call to look_up_order, and its result. A model a Bot cannot finish
    a tool call on no longer passes, and so no longer gets into the lock. model-lock.json is
    untouched; CI writes it.

Not changed

  • Antigravity hands the thread to its Go harness as labelled text, so it never sends a handed-back
    call as a function call. It passed the live hand-back unchanged.
  • Mastra answers on OpenAI and Anthropic only, and refuses BOT_PROVIDER=google at start by design.
    Its Gemini path is Google's compatible endpoint, which is now signed.
  • LlamaIndex's AG-UI router replays a handed-back call as text today. The signer is installed so a
    call it sends as a call is covered.
  • Agno, Microsoft and Pydantic AI refuse every Gemini model, and are out of scope.

Where it runs

  • New state that outlives a request? None. The signer rewrites each outgoing request body;
    it keeps nothing between requests.
  • What happens on the second replica? The same: each engine process signs its own requests.
  • Anything serialised? No.
  • Anything fanned out to a browser? No.
  • New listener, port, or schedule? No. The model check's schedule is unchanged; only its run
    body changes.

Boundary and audit

  • Every acting call still goes through the gateway. Only the body of a model request to Gemini
    changes.
  • No new refusals or failures.
  • Nothing new is trusted from the client.

API and database

  • This changes nothing under api/, no app's requests, no database change and no
    release-policy.json.

Changelog

  • Three lines in CHANGELOG.md under Unreleased.

Proof

Live hand-back runs, every engine (2026-11-27, paid-tier key, images built from this branch's
head ba68f20b, on 1.2.2). Each run hands the engine an unsigned look_up_order call and its
result, as the server does after running a tool, and passes when the engine answers with the
order's status. "Compatible" is Google's OpenAI-compatible endpoint, which is how OpenBot Desktop
and Settings save a Gemini key; "native" is BOT_PROVIDER=google.

engine 4-hydrogen compatible 4-hydrogen native 3.8-flash compatible 3.8-flash native
Google ADK pass pass pass pass
AG2 pass pass pass pass
CrewAI pass pass pass pass
LangGraph (Python) pass pass pass pass
LangGraph (TypeScript) pass pass pass pass
Langroid pass pass pass pass
LlamaIndex pass pass pass pass
Mastra pass refused at start, by design pass refused at start, by design
Strands pass pass pass pass
Antigravity (Gemini's own API only) pass pass

38 runs passed and none failed. Mastra answers on OpenAI and Anthropic only, and refuses
BOT_PROVIDER=google at start, so its two native runs never reach a model. Antigravity always
talks to Gemini's own API, so its run marked compat in the output below is on that API too.

Run output
agent-adk [compat, gemini-3.8-flash, local]: PASS HTTP 200 reply="Order 42 has been shipped."
agent-adk [compat, gemini-4-hydrogen, local]: PASS HTTP 200 reply="Order 42 has been shipped."
agent-adk [native, gemini-3.8-flash, local]: PASS HTTP 200 reply="Order 42 has been shipped."
agent-adk [native, gemini-4-hydrogen, local]: PASS HTTP 200 reply="Order 42 has shipped."
agent-ag2 [compat, gemini-3.8-flash, local]: PASS HTTP 200 reply="Order 42 has been shipped."
agent-ag2 [compat, gemini-4-hydrogen, local]: PASS HTTP 200 reply="Order 42 has been shipped."
agent-ag2 [native, gemini-3.8-flash, local]: PASS HTTP 200 reply="Order 42 has shipped."
agent-ag2 [native, gemini-4-hydrogen, local]: PASS HTTP 200 reply="Order 42 has been shipped."
agent-antigravity [compat, gemini-3.8-flash, local]: PASS HTTP 200 reply="Order 42 has shipped."
agent-antigravity [compat, gemini-4-hydrogen, local]: PASS HTTP 200 reply="The status of order 42 is shipped."
agent-antigravity [native, gemini-3.8-flash, local]: PASS HTTP 200 reply="Order 42 has shipped."
agent-antigravity [native, gemini-4-hydrogen, local]: PASS HTTP 200 reply="Order 42 has been shipped."
agent-crewai [compat, gemini-3.8-flash, local]: PASS HTTP 200 reply="Order 42 has been shipped."
agent-crewai [compat, gemini-4-hydrogen, local]: PASS HTTP 200 reply="Order 42 has been shipped."
agent-crewai [native, gemini-3.8-flash, local]: PASS HTTP 200 reply="Order 42 has been shipped."
agent-crewai [native, gemini-4-hydrogen, local]: PASS HTTP 200 reply="Order 42 has been shipped."
agent-langgraph-agui [compat, gemini-3.8-flash, local]: PASS HTTP 200 reply="Order 42 has been shipped."
agent-langgraph-agui [compat, gemini-4-hydrogen, local]: PASS HTTP 200 reply="Order 42 has been shipped."
agent-langgraph-agui [native, gemini-3.8-flash, local]: PASS HTTP 200 reply="Order 42 has been shipped."
agent-langgraph-agui [native, gemini-4-hydrogen, local]: PASS HTTP 200 reply="Order 42 has been shipped."
agent-langgraph-ts [compat, gemini-3.8-flash, local]: PASS HTTP 200 reply="Order 42 has been shipped."
agent-langgraph-ts [compat, gemini-4-hydrogen, local]: PASS HTTP 200 reply="Order 42 has been shipped."
agent-langgraph-ts [native, gemini-3.8-flash, local]: PASS HTTP 200 reply="Order 42 has shipped."
agent-langgraph-ts [native, gemini-4-hydrogen, local]: PASS HTTP 200 reply="Order 42 has shipped."
agent-langroid [compat, gemini-3.8-flash, local]: PASS HTTP 200 reply="Order 42 has been shipped."
agent-langroid [compat, gemini-4-hydrogen, local]: PASS HTTP 200 reply="Order 42 has been shipped."
agent-langroid [native, gemini-3.8-flash, local]: PASS HTTP 200 reply="Order 42 has been shipped."
agent-langroid [native, gemini-4-hydrogen, local]: PASS HTTP 200 reply="Order 42 has shipped."
agent-llamaindex [compat, gemini-3.8-flash, local]: PASS HTTP 200 reply="Order 42 has been shipped."
agent-llamaindex [compat, gemini-4-hydrogen, local]: PASS HTTP 200 reply="Order 42 has been shipped."
agent-llamaindex [native, gemini-3.8-flash, local]: PASS HTTP 200 reply="Order 42 has been shipped."
agent-llamaindex [native, gemini-4-hydrogen, local]: PASS HTTP 200 reply="Order 42 has been shipped."
agent-mastra [compat, gemini-3.8-flash, local]: PASS HTTP 200 reply="Order 42 has shipped."
agent-mastra [compat, gemini-4-hydrogen, local]: PASS HTTP 200 reply="The status of order 42 is shipped."
agent-mastra [native, gemini-3.8-flash, local]: ERROR TypeError: ECONNREFUSED: Unable to connect. Is the computer able to access the url?
agent-mastra [native, gemini-4-hydrogen, local]: ERROR TypeError: ECONNREFUSED: Unable to connect. Is the computer able to access the url?
agent-strands [compat, gemini-3.8-flash, local]: PASS HTTP 200 reply="Order 42 has been shipped."
agent-strands [compat, gemini-4-hydrogen, local]: PASS HTTP 200 reply="Order 42 has been shipped."
agent-strands [native, gemini-3.8-flash, local]: PASS HTTP 200 reply="Order 42 has been shipped."
agent-strands [native, gemini-4-hydrogen, local]: PASS HTTP 200 reply="Order 42 has been shipped."

Before this change, the published images failed every compatible-path cell except LangGraph's with
"Function call 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.

Tests, run locally on this branch:

  • the full pytest suite of every changed Python engine: ADK 60, AG2 29, CrewAI 29, LangGraph (Python)
    215 (with LangGraph (Python): keep Gemini's thought signature on a tool call #2335's test_thought_signatures.py), Langroid 31, LlamaIndex 16, Strands 25, all pass;
  • bun test agent-mastra: 40 pass;
  • bun test shared/gemini-signatures.test.ts scripts/model-compat.test.ts tests/compose.test.ts: 80
    pass;
  • biome lint --error-on-warnings and biome format on the changed files: clean.

With the signer switched off, each engine's test_gemini_handback.py fails on the compatible path.
On LangGraph (Python) it fails on #2335 alone for a thread with no signature on record. LangGraph
(TypeScript) on 1.2.2 passes the same unsigned hand-back on both paths, so it is not changed here.

…s fix did not reach

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. 1.2.2 carries the
real signature through the thread on both LangGraph engines (CopilotKit#2334, CopilotKit#2335); every other engine
still sent the handed-back call unsigned, so a Bot on Gemini 3.x or 4 failed after its first tool.

- shared/gemini_signatures.py: ADK, AG2, CrewAI, Langroid, LlamaIndex and Strands install 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 Mastra's OpenAI-compatible
  client.
- 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.
…cord gets the placeholder

thought_signatures.py (CopilotKit#2335) sends back the signature Gemini gave a call, when the thread carries
it. A thread without one (a conversation from before it, or a caller that drops encryptedValue)
still reached Google's OpenAI-compatible endpoint unsigned and was refused with "Function call is
missing a thought_signature". The engine now installs shared/gemini_signatures.py like the other
Python engines: it fills in Google's placeholder only where a call has no signature, so a real one
still goes as it came, and nothing changes for another provider's model. The LangGraph (TypeScript)
engine already does this in thought-signatures.ts.
@lorenzejay lorenzejay closed this Nov 28, 2026
davidmckayv added a commit that referenced this pull request Nov 29, 2026
…every engine (#2397)

A Bot on Gemini 3 or later on Google ADK, AG2, CrewAI, Langroid, Mastra or Strands stopped once a
tool's result came back: Google refused the next request with "Function call is missing a
thought_signature in functionCall parts". The call comes back from the thread without the
signature Gemini gave it, and Gemini checks the first call of each step in the current turn.

- CrewAI keeps the real signature, as the LangGraph engines do: it leaves on the call as its
  AG-UI encryptedValue in the run's snapshot, and goes back to Gemini from the thread.
- ADK already keeps it within the process that made the call.
- Where an engine cannot carry it (and for a thread that has none), the call goes with Google's
  documented placeholder, skip_thought_signature_validator: shared/gemini_signatures.py for the
  Python engines, at the HTTP request as run_model_key.py does, and a fetch on Mastra's
  compatible-endpoint model client. Only a Chat Completions request for a Gemini 3+ model, on
  Google's host or OpenBot's model gateway, is changed; a real signature is kept.

First found by lorenzejay in #2365.
@davidmckayv

Copy link
Copy Markdown
Contributor

Thanks for finding this. It's fixed in #2397 and ships in the next release.

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Gemini 3 and 4 Bots fail after their first tool call: "Function call is missing a thought_signature"

2 participants