Description
** Please make sure you read the contribution guide and file the issues in the right place. **
Contribution guide.
Describe the bug
When a root agent invokes multiple sub-agents (each configured as an AgentTool with a distinct output_key) in parallel, the state_delta within the actions of the resulting merged FunctionResponse event does not correctly aggregate the state_delta contributions from all sub-agents. Instead, the final session state (and intermediate event logs) often reflects only the state_delta from one of the processed sub-agents, or an incorrectly merged state.
To Reproduce
Steps to reproduce the behavior:
- Define a
root_agent
and at least two sub-agents (e.g.,roll_agent
andprime_agent
). - Configure each sub-agent with a unique
output_key
(e.g.,output_key="result_roll_agent"
forroll_agent
andoutput_key="result_prime_agent"
forprime_agent
). - Add
AgentTool(roll_agent)
andAgentTool(prime_agent)
to thetools
list of theroot_agent
. - Provide an instruction to the
root_agent
that, upon a specific user request, it should call both sub-agents in parallel (e.g., user input: "Roll a 6-sided die and check if 2 is a prime number at the same time."). - Run the application and send the user request that triggers the parallel execution.
- Observe the final session state after the execution. The session state would typically contain only the
output_key
and result from one of the sub-agents (as shown in the "State" tab of the ADK Dev UI in the screenshot below), instead of both.
Expected behavior
The final session state should correctly aggregate all key-value pairs from the state_delta of each individual sub-agent's execution, as determined by their output_key. For the example "Roll a 6-sided die and check if 2 is a prime number at the same time.", the session state should contain both result_roll_agent (with the die roll result) and result_prime_agent (with the prime check result).
Screenshots
Desktop (please complete the following information):
- OS: macOS
- Python version(python -V): Python 3.12.10
- ADK version(pip show google-adk): 1.1.1
Additional context
Add any other context about the problem here.