Skip to content

fix(gemini): preserve and replay thought signatures for tool calls#65

Merged
MegalithOfficial merged 1 commit into
LettuceAI:mainfrom
rppavan:fix/gemini-thought-signature
Jun 27, 2026
Merged

fix(gemini): preserve and replay thought signatures for tool calls#65
MegalithOfficial merged 1 commit into
LettuceAI:mainfrom
rppavan:fix/gemini-thought-signature

Conversation

@rppavan

@rppavan rppavan commented Jun 25, 2026

Copy link
Copy Markdown
Contributor

Gemini thinking models (3.x / 2.5) attach a thoughtSignature to every function call and reject the next request if you don't send it back. So any multi-turn tool loop on Gemini Express dies with:

400: function call `set_name` in the 4. content block is missing a `thought_signature`

Hit this in the AI Character Creator, and the companion soul writer has the same bug. Normal chat is fine since it doesn't replay function calls.

Fix is to keep the signature on the tool call when we parse it and echo it back in the Gemini adapter. While I was at it I pulled the three near-identical tool-call serializers into one shared helper so this can't drift again, and dropped the duplicate CreationToolCall type (persisted shape stays the same).

Tested with gemini-3.5-flash — soul gen ran 5 tool iterations, all 200, no more signature error. Added unit tests for the serializer too.

Gemini thinking models (3.x, 2.5) attach a thoughtSignature to each
functionCall part and require it echoed back when the call is replayed
in history, else the request fails with MISSING_THOUGHT_SIGNATURE. This
broke multi-turn tool loops on Gemini Express in both the AI Character
Creator and the companion soul writer.

Capture the signature on ToolCall and centralize tool-call message
serialization in a shared chat_manager::tooling::tool_call_message_payload
that echoes thoughtSignature for every agentic loop. Collapse the
duplicate CreationToolCall type into ToolCall and replace the per-module
serializers (creation_tool_call_payload and the soul writer's
tool_call_payload) so the fix applies uniformly and cannot drift again.
Add unit tests for the serializer.

By apparao.parwatikar

@MegalithOfficial MegalithOfficial left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good.

@MegalithOfficial MegalithOfficial merged commit 764d479 into LettuceAI:main Jun 27, 2026
3 of 4 checks passed
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.

2 participants