MIRIX icon indicating copy to clipboard operation
MIRIX copied to clipboard

Gemini 3: second step of a tool loop fails, thoughtSignature is not sent back

Open swf1996120 opened this issue 1 month ago • 1 comments

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 39e2411 against a local generateContent endpoint, not against the real API.

gemini-2.0-flash from the README quick start and the example configs is shut down, and Google names gemini-3.6-flash as its replacement. With that model the first step of an agent works and the next one does not, because the thoughtSignature on the function call is never sent back.

config = LLMConfig(model="gemini-3.6-flash", model_endpoint_type="google_ai", model_endpoint=URL, context_window=1000000)
client = LLMClient.create(config)
reply = (await client.send_llm_request(messages=history, tools=tools)).choices[0].message
# the server's part: {"functionCall": {...}, "thoughtSignature": "EpoGCpcG..."}

history.append(Message.dict_to_message(agent_id="a1", openai_message_dict=reply.model_dump()))
history.append(Message.dict_to_message(agent_id="a1", openai_message_dict={
    "role": "tool", "name": "open_drawer", "content": '{"status": "OK"}', "tool_call_id": reply.tool_calls[0].id}))
await client.send_llm_request(messages=history, tools=tools)

The model turn in the second request is:

{"role": "model", "parts": [{"functionCall": {"name": "open_drawer", "args": {"number": 3}}}]}

What happens

Google's thought signature docs say "omitting a required thought_signature for the first functionCall part in any step of the current turn results in a 400 error", and people report exactly that on Gemini 3 models, for example Function call is missing a thought_signature in functionCall parts. on gemini-3.6-flash.

With the local endpoint returning that 400, Agent._get_ai_reply sent the full history three times and then fell back to sending only the last message. The agent then carried on with a reply from a model that had seen neither the system prompt nor the memory input, so a run can look like it worked.

gemini-2.5-flash still works without the signature, but Google is limiting 2.5 access to users who have actively used those models before.

I expected the signature to go back with its function call on every later step.

Cause

convert_response_to_chat_completion builds the ToolCall from the functionCall alone, so the part's thoughtSignature is lost there and Message.to_google_ai_dict has nothing to send.

Fix idea

Add an optional thought_signature to both ToolCall schemas, set it from the part, copy it in dict_to_message, write it as thoughtSignature in to_google_ai_dict, and leave it out of to_openai_dict. The tool call JSON column then stores it with no migration.

swf1996120 avatar Oct 30 '26 20:10 swf1996120

Thanks for tracing where the signature was lost. Fixed in https://github.com/Mirix-AI/MIRIX/pull/148, now merged into main.

Function-call thoughtSignature values now survive response parsing, Message.dict_to_message, JSON database storage, and replay on the corresponding Gemini function-call part. They are omitted from OpenAI request serialization. No database migration is needed. The Gemini example and README quick start now use gemini-3.6-flash.

Validation: offline regression tests cover a two-step tool loop, a round trip through the actual SQLAlchemy JSON column, per-call signatures on parallel calls, and older unsigned calls. No live Gemini API was used. Please pull the latest main and retry the tool loop.

Mirix-AI avatar Nov 08 '26 08:11 Mirix-AI