Skip to content

feat: enhance Google agent to merge parallel tool results into single…#127

Merged
Iamsdt merged 3 commits into
10xHub:mainfrom
suchith83:main
May 30, 2026
Merged

feat: enhance Google agent to merge parallel tool results into single…#127
Iamsdt merged 3 commits into
10xHub:mainfrom
suchith83:main

Conversation

@suchith83

Copy link
Copy Markdown
Contributor

This pull request introduces improvements to the handling of tool result messages for Google Vertex AI integration, ensuring compatibility with Gemini's requirements for parallel tool calls. The main change is the merging of consecutive tool results into a single user content block, which aligns the number of function-call and function-response parts. Additional refactoring and tests support this new behavior.

Google Vertex AI / Gemini tool message handling:

  • Consecutive tool result messages are now merged into a single user content block in _convert_to_google_format, ensuring that the number of function-response parts matches the number of function-call parts in the preceding assistant turn. This is required for correct Gemini parallel tool call support.
  • Refactored the tool message handling by introducing _tool_response_part to build individual function-response parts, and updated _handle_tool_message for backward compatibility.
  • Added a new test test_parallel_tool_results_merged_into_single_content to verify that multiple tool results are correctly merged into a single content block.

Vertex AI integration:

  • Added use_vertex_ai as a member of MyState to track whether Vertex AI is being used.
  • Passed the use_vertex_ai flag to the client creation logic in _call_llm_with_retry to ensure correct provider behavior.

Copilot AI review requested due to automatic review settings May 29, 2026 17:14

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Pull request overview

Note

Copilot was unable to run its full agentic suite in this review.

This PR updates the Google (Gemini) message conversion to correctly handle parallel tool calls by merging consecutive tool results into a single user turn, and threads a use_vertex_ai flag through client creation.

Changes:

  • Merge consecutive "tool" messages into one Google Content(role="user") containing multiple function-response parts.
  • Refactor tool-result handling by extracting _tool_response_part and keeping _handle_tool_message for compatibility.
  • Pass use_vertex_ai into _create_client(...) on fallback client creation, and add a regression test for parallel tool results.

Reviewed changes

Copilot reviewed 4 out of 4 changed files in this pull request and generated 3 comments.

File Description
tests/graph/test_agent_internal.py Adds regression test ensuring parallel tool results collapse into a single user content.
agentflow/core/graph/agent_internal/google.py Implements merging of consecutive tool messages and refactors tool response part construction.
agentflow/core/graph/agent_internal/execution.py Passes use_vertex_ai to _create_client when creating fallback client.
agentflow/core/graph/agent.py Stores use_vertex_ai on the agent/state for later use in execution/client creation.

Comment thread agentflow/core/graph/agent_internal/google.py Outdated
Comment thread agentflow/core/graph/agent_internal/execution.py
Comment thread agentflow/core/graph/agent_internal/google.py Outdated
@codecov

codecov Bot commented May 29, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.

📢 Thoughts on this report? Let us know!

@Iamsdt

Iamsdt commented May 30, 2026

Copy link
Copy Markdown
Collaborator

#130

@Iamsdt Iamsdt merged commit 63b0cab into 10xHub:main May 30, 2026
2 checks passed
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.

3 participants