fix(gemini): coalesce parallel tool responses into a single Content#2959
Merged
dgageot merged 1 commit intoJun 3, 2026
Merged
Conversation
dgageot
approved these changes
Jun 2, 2026
8f76d0d to
614275c
Compare
Contributor
Author
|
Rebased onto the latest |
Member
|
Sorry @t-mizumoto1203 we require all the contributors to sign and verify their commits. Could you sign your commit? |
When a Gemini model returns parallel function calls, the tool responses must be returned together as multiple functionResponse parts within a single Content (role=user), matching the number of functionCall parts. convertMessagesToGemini emitted one Content per tool response, which Vertex AI rejects with "the number of function response parts is equal to the number of function call parts" (INVALID_ARGUMENT). Coalesce consecutive tool responses into one Content and add a regression test. Fixes docker#2958 Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com> Signed-off-by: t.mizumoto <56530282+t-mizumoto1203@users.noreply.github.com>
614275c to
d516fdf
Compare
Contributor
Author
|
@dgageot Apologies for the late update. I've signed and pushed the commit now |
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.
Fixes #2958.
Problem
When a Gemini model (via Vertex AI) returns parallel function calls (multiple
functionCallparts in one assistant turn),convertMessagesToGeminireturned each tool result as its owngenai.Content(onefunctionResponsepart perContent). Vertex AI requires the response turn to carry the same number offunctionResponseparts as the preceding turn'sfunctionCallparts, so the request fails with:This is deterministic for a given turn, so retries reproduce it and the run eventually aborts. There is no opt-out: Vertex Gemini exposes no parameter to disable parallel function calling (
go-genaiFunctionCallingConfigonly hasMode).Change
convertMessagesToGemininow coalesces consecutive tool-response messages into a singleContent(roleuser) with NfunctionResponseparts, flushing on the next non-tool message and at the end of the loop — instead of emitting oneContentper response. Single (non-parallel) tool calls are unaffected (one response → one Content).Added regression test
TestConvertMessagesToGemini_ParallelToolResponsesCoalesced(fails onmain, passes with this change).Reference
Per the Vertex AI function-calling docs, parallel results are returned together as one
Content(role="user", parts=function_response_parts)with the part count matching the calls:Verification
go build ./...— okgo vet ./pkg/model/provider/gemini/...— okgo test ./pkg/model/provider/...— okgolangci-lint run(repo.golangci.yml, v2.12.2) — 0 issues