Skip to content

fix(gemini): group parallel tool responses#2353

Open
Zbhbb wants to merge 5 commits into
agentscope-ai:mainfrom
Zbhbb:codex/gemini-tool-response-grouping
Open

fix(gemini): group parallel tool responses#2353
Zbhbb wants to merge 5 commits into
agentscope-ai:mainfrom
Zbhbb:codex/gemini-tool-response-grouping

Conversation

@Zbhbb

@Zbhbb Zbhbb commented Jul 22, 2026

Copy link
Copy Markdown

Description

Gemini expects responses to parallel function calls in one user Content. Previously, the formatter emitted one Content per ToolResultBlock, which can split a valid parallel tool-response batch.

This change buffers tool-result parts while converting one Msg, then emits one user Content containing the ordered function responses.

Changes

  • Group tool-result parts from a single message into one user Content.
  • Preserve the original tool-result order.
  • Add a regression test for two tool results in one message.

Testing

  • mvn -pl agentscope-extensions/agentscope-extensions-model/agentscope-extensions-model-gemini -am -q -Dtest=GeminiMessageConverterTest -Dsurefire.failIfNoSpecifiedTests=false test
  • mvn -pl agentscope-extensions/agentscope-extensions-model/agentscope-extensions-model-gemini -am -q test
  • mvn -pl agentscope-extensions/agentscope-extensions-model/agentscope-extensions-model-gemini -q spotless:check
  • git diff --check

Closes #2351

Checklist

  • Code has been formatted with Spotless.
  • Relevant module tests are passing.
  • Code is ready for review.

Copilot AI review requested due to automatic review settings July 22, 2026 08:50
@CLAassistant

CLAassistant commented Jul 22, 2026

Copy link
Copy Markdown

CLA assistant check
All committers have signed the CLA.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

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 ToolResultBlock conversions per Msg and emit one grouped user Content containing all FunctionResponse parts 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.

@Zbhbb
Zbhbb force-pushed the codex/gemini-tool-response-grouping branch from 75acb34 to 58a81cb Compare July 22, 2026 08:52
@Zbhbb
Zbhbb force-pushed the codex/gemini-tool-response-grouping branch from 58a81cb to 82b4e3f Compare July 22, 2026 08:56
@codecov

codecov Bot commented Jul 22, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.

📢 Thoughts on this report? Let us know!

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.

[Bug]: Gemini formatter splits parallel function responses into multiple user contents

3 participants