fix(google): prevent parallel tool calls from dropping thought_signature#298
Merged
andreynering merged 1 commit intoJun 25, 2026
Merged
Conversation
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.
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.