Skip to content

fix: Aggregate state_delta from parallel AgentTool calls #1155

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

ystory
Copy link
Contributor

@ystory ystory commented Jun 4, 2025

Previously, when a root agent executed multiple sub-agents (AgentTools) in parallel, the state_delta from each sub-agent was not correctly aggregated. The merge_parallel_function_response_events function would often result in the session state reflecting only the output from one of the sub-agents, as their state_deltas (containing output_key results) could overwrite each other.

Before fix:
Screenshot 2025-06-05 at 01 18 58

This commit updates merge_parallel_function_response_events in src/google/adk/flows/llm_flows/functions.py to properly initialize and update a merged_state_delta dictionary. It iterates through each function response event from parallel tool calls and updates this dictionary with each sub-agent's state_delta. This ensures that all output_key results from parallel AgentTool calls are preserved and correctly reflected in the final session state.

After fix:
Screenshot 2025-06-05 at 01 19 19

A new parallel_agent_tool_state_merge sample has been added to contributing/samples.

Fixes #1153

Previously, when a root agent executed multiple sub-agents (AgentTools)
in parallel, the `state_delta` from each sub-agent was not correctly
aggregated. The `merge_parallel_function_response_events` function
would often result in the session state reflecting only the output from
one of the sub-agents, as their `state_delta`s (containing `output_key`
results) could overwrite each other.

This commit updates `merge_parallel_function_response_events` in
`src/google/adk/flows/llm_flows/functions.py` to properly initialize
and update a `merged_state_delta` dictionary. It iterates through each
function response event from parallel tool calls and updates this
dictionary with each sub-agent's `state_delta`. This ensures that all
`output_key` results from parallel AgentTool calls are preserved and
correctly reflected in the final session state.

A new parallel_agent_tool_state_merge sample has been added to contributing/samples.

Fixes google#1153
@ystory ystory force-pushed the fix/1153-parallel-state-delta-aggregation- branch from 1d3ebb5 to 4ef2177 Compare June 4, 2025 16:46
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: state_delta from parallel AgentTool calls not aggregated
1 participant