[Bug] Gemini 3 tool calls fail with HTTP 400: thought signature not sent back
Found while testing LLM provider integrations in agent frameworks: an automated tool flags candidates and each one is reproduced before it is reported. Reproduced on 45fc701.
Pre-checks
- [x] I have searched existing issues and this is not a duplicate.
Deployment Method
Source (setup.sh)
Steps to Reproduce
Version 1.11.4-fix.1.
- Add a model with provider Gemini and a Gemini 3 model such as
gemini-3.8-flash, default base URL. The model test passes because it only checks that one tool call comes back; it never sends a tool result. - Ask an agent something that needs a tool, for example "read notes.md".
- The tool runs, then the next model step fails and the Run ends.
The request can be seen without a key:
from app.services.llm.client import GeminiClient, LLMMessage
client = GeminiClient(api_key="x", model="gemini-3.8-flash")
reply = client._parse_response_data({"candidates": [{"finishReason": "STOP", "content": {"parts": [{
"functionCall": {"name": "read_file", "args": {"path": "notes.md"}},
"thoughtSignature": "CsUB...",
}]}}]})
history = [
LLMMessage(role="user", content="read notes.md"),
LLMMessage(role="assistant", content=reply.content, tool_calls=reply.tool_calls),
LLMMessage(role="tool", tool_call_id=reply.tool_calls[0]["id"], content="hello"),
]
print(client._build_payload(history, None, None, None)["contents"][1])
# {'role': 'model', 'parts': [{'text': ''}, {'functionCall': {'name': 'read_file', 'args': {'path': 'notes.md'}}}]}
I also ran a full tool turn through RuntimeModelStepService, complete_llm_once and the checkpoint message reducer against a local fake endpoint that applies Gemini's documented rule. No real API was called. The result is the same for complete(), for stream() (Web chat) and for a Gemini model on a .../v1beta/openai base URL, where extra_content.google.thought_signature is lost.
Expected vs Actual Behavior
Expected: the thoughtSignature returned on the functionCall part goes back in that same part, and the Run continues with the tool result.
Actual: the part goes back without it. Google's docs say "you must pass back thought signatures during function calling" for Gemini 3 and "Failure to include signatures will result in a 400 error", so the Run stops at the first tool result with Model provider rejected the request (HTTP 400).
Logs / Screenshots
Cause: the signature sits next to functionCall on the part, but GeminiClient only copies keys from inside functionCall into _gemini_extra. stream() keeps it as reasoning_signature, which LLMCompletionStep has no field for. _gemini_extra would not survive either, because Runtime tool calls go through LangChain messages, which keep only id, name and args.
Fix idea: keep the signature on the normalized tool call, store it in additional_kwargs next to provider_call_ids, put it back in _prompt_messages, and write it as part-level thoughtSignature in GeminiClient._build_payload.