Skip to content

fix(google): attach thought_signature to FunctionResponse parts#297

Closed
Cidan wants to merge 1 commit into
charmbracelet:mainfrom
Cidan:fix/gemini-thought-signature
Closed

fix(google): attach thought_signature to FunctionResponse parts#297
Cidan wants to merge 1 commit into
charmbracelet:mainfrom
Cidan:fix/gemini-thought-signature

Conversation

@Cidan

@Cidan Cidan commented Jun 25, 2026

Copy link
Copy Markdown
Contributor

Gemini models with reasoning enabled return a `thought_signature` alongside a `FunctionCall`. The Google API enforces that the subsequent `FunctionResponse` part must include this same `thought_signature`, or it will reject the request with a 400 `INVALID_ARGUMENT` (or 400 `bad request` on AI Studio).

This patch ensures that when mapping `MessageRoleTool` (ToolResults) into `FunctionResponse` parts, we search the conversation history for the matching `ReasoningContent` block and copy its `thought_signature` onto the `genai.Part`.

Fixes a crash when using tools with Gemini 3.1 Pro Preview and reasoning enabled.

@Cidan Cidan requested a review from andreynering as a code owner June 25, 2026 01:05
@Cidan

Cidan commented Jun 25, 2026

Copy link
Copy Markdown
Contributor Author

I misidentified the root cause during testing. Closing.

@Cidan Cidan closed this Jun 25, 2026
@Cidan Cidan deleted the fix/gemini-thought-signature branch June 25, 2026 01:15
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.

1 participant