fix: Aggregate state_delta from parallel AgentTool calls #1155
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.
Previously, when a root agent executed multiple sub-agents (AgentTools) in parallel, the
state_delta
from each sub-agent was not correctly aggregated. Themerge_parallel_function_response_events
function would often result in the session state reflecting only the output from one of the sub-agents, as theirstate_delta
s (containingoutput_key
results) could overwrite each other.Before fix:

This commit updates
merge_parallel_function_response_events
insrc/google/adk/flows/llm_flows/functions.py
to properly initialize and update amerged_state_delta
dictionary. It iterates through each function response event from parallel tool calls and updates this dictionary with each sub-agent'sstate_delta
. This ensures that alloutput_key
results from parallel AgentTool calls are preserved and correctly reflected in the final session state.After fix:

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