fix(gemini): group parallel tool responses - #2353
Conversation
There was a problem hiding this comment.
Pull request overview
This PR fixes Gemini function-calling formatting by ensuring multiple tool results produced in a single tool message are emitted as a single Content(role="user"), matching Gemini’s contract for parallel function responses.
Changes:
- Buffer
ToolResultBlockconversions perMsgand emit one groupeduserContentcontaining allFunctionResponseparts in original order. - Preserve existing conversion behavior for non-tool blocks while keeping tool responses separated into their own
Content. - Add a regression test covering two tool results in one message.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.
| File | Description |
|---|---|
.../GeminiMessageConverter.java |
Groups tool-result parts from a single Msg into one user Content instead of emitting one per ToolResultBlock. |
.../GeminiMessageConverterTest.java |
Adds a test asserting two tool results become one user Content with two FunctionResponse parts in order. |
58a81cb to
82b4e3f
Compare
Codecov Report✅ All modified and coverable lines are covered by tests. 📢 Thoughts on this report? Let us know! |
oss-maintainer
left a comment
There was a problem hiding this comment.
LGTM. Looks good.
Automated review by "github-manager-bot"
AgentScopeJavaBot
left a comment
There was a problem hiding this comment.
🤖 AI Review
This PR fixes a Gemini API compatibility issue: when the model issues parallel function calls, the framework previously emitted each ToolResultBlock as a separate user-role Content object. The Gemini API requires all function_response parts for parallel calls from a single model turn to be sent in one user turn. The fix collects all function_response parts from a single Msg into one user-role Content.
(inline comments could not be attached — line numbers fell outside PR hunks. See archived report.)
AgentScopeJavaBot
left a comment
There was a problem hiding this comment.
🤖 AI Review
This PR fixes a Gemini API compatibility issue: when the model issues parallel function calls, the framework previously emitted each ToolResultBlock as a separate user-role Content object. The Gemini API requires all function_response parts for parallel calls from a single model turn to be sent in one user turn. The fix collects all function_response parts from a single Msg into one user-role Content.
(inline comments could not be attached — line numbers fell outside PR hunks. See archived report.)
AgentScopeJavaBot
left a comment
There was a problem hiding this comment.
🤖 AI Review
This PR fixes a Gemini API compatibility issue: when the model issues parallel function calls, the framework previously emitted each ToolResultBlock as a separate user-role Content object. The Gemini API requires all function_response parts for parallel calls from a single model turn to be sent in one user turn. The fix collects all function_response parts from a single Msg into one user-role Content.
(inline comments could not be attached — line numbers fell outside PR hunks. See archived report.)
eb8a257 to
0c7a597
Compare
5e06d15 to
e0fc68e
Compare
e0fc68e to
dec726d
Compare
Description
Gemini expects responses to parallel function calls in one
userContent. Previously, the formatter emitted one Content perToolResultBlock, which can split a valid parallel tool-response batch.This change buffers tool-result parts while converting one
Msg, then emits oneuserContent containing the ordered function responses.Changes
Testing
mvn -pl agentscope-extensions/agentscope-extensions-model/agentscope-extensions-model-gemini -am -q -Dtest=GeminiMessageConverterTest -Dsurefire.failIfNoSpecifiedTests=false testmvn -pl agentscope-extensions/agentscope-extensions-model/agentscope-extensions-model-gemini -am -q testmvn -pl agentscope-extensions/agentscope-extensions-model/agentscope-extensions-model-gemini -q spotless:checkgit diff --checkCloses #2351
Checklist