fix(gemini): preserve and replay thought signatures for tool calls#65
Merged
MegalithOfficial merged 1 commit intoJun 27, 2026
Merged
Conversation
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
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.
Gemini thinking models (3.x / 2.5) attach a
thoughtSignatureto 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: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
CreationToolCalltype (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.