Skip to content

fix(google): prevent parallel tool calls from dropping thought_signature#298

Merged
andreynering merged 1 commit into
charmbracelet:mainfrom
Cidan:fix/gemini-parallel-tool-signatures
Jun 25, 2026
Merged

fix(google): prevent parallel tool calls from dropping thought_signature#298
andreynering merged 1 commit into
charmbracelet:mainfrom
Cidan:fix/gemini-parallel-tool-signatures

Conversation

@Cidan

@Cidan Cidan commented Jun 25, 2026

Copy link
Copy Markdown
Contributor

When Gemini models return parallel tool calls with reasoning enabled (e.g. `gemini-3.1-pro-preview`), the model returns a `thought_signature` alongside the `FunctionCall`. The Google API strictly enforces that the subsequent `FunctionResponse` part must include this same `thought_signature` by validating the echoed history.

There was a bug in `mapResponse` where it iterated through the parallel tool calls but blindly overwrote the `ProviderMetadata` on the exact same `ReasoningContent` block for every tool call. As a result, the first tool call lost its metadata completely, causing its `thought_signature` to be omitted when the history was reconstructed for the next API request. This led the Vertex API to immediately reject the request with a `400 INVALID_ARGUMENT` (`Request contains an invalid argument`).

This patch ensures that `mapResponse` only attaches metadata to a `ReasoningContent` block if it does not already have a signature, forcing it to append a new `ReasoningContent` block for the subsequent parallel tool calls just like the streaming logic correctly does.

Tested and verified that this completely resolves the `INVALID_ARGUMENT` error when agents execute parallel tool calls.

@andreynering andreynering left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Thank you!

@andreynering andreynering enabled auto-merge (squash) June 25, 2026 17:29
@andreynering andreynering merged commit ceb45c4 into charmbracelet:main Jun 25, 2026
9 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants