Skip to content

# Bug Report: Event History Corruption in Nested ADK Agent Workflows #1805

Closed

Description

@davisma20

Bug Report: Event History Corruption in Nested ADK Agent Workflows

Summary

This report details a reproducible bug in the Google Agent Development Kit (ADK) where a ValueError is raised due to apparent event history corruption during a nested, multi-agent workflow. Specifically, when a sub-agent is invoked via an AgentTool, the framework incorrectly processes the function_response event, claiming it cannot find the corresponding function_call event in the parent agent's history.

The error occurs consistently in a test case involving a root agent delegating to a sub-agent, which in turn delegates to another sub-agent. The error message is ValueError: No function call event found for function responses ids: {'call-2'}.

Environment

  • Python Version: 3.12
  • Framework: Google Agent Development Kit (ADK) for Python

Steps to Reproduce

  1. Set up the project environment.
  2. Run the isolated test case for the multi-agent workflow:
    python3 -m unittest jira_agent_suite/tests/test_multi_agent_workflow.py

Expected Behavior

The test should complete successfully, with the final response from the root agent being returned to the user. The event history should be correctly maintained across all agents in the hierarchy.

Actual Behavior

The test fails with a ValueError. The traceback points to an internal ADK function responsible for processing event history.

Traceback

Traceback (most recent call last):
  ...
  File "/Library/Frameworks/Python.framework/Versions/3.12/lib/python3.12/site-packages/google/adk/flows/llm_flows/contents.py", line 239, in _get_contents
    result_events = _rearrange_events_for_latest_function_response(
                    ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Library/Frameworks/Python.framework/Versions/3.12/lib/python3.12/site-packages/google/adk/flows/llm_flows/contents.py", line 169, in _rearrange_events_for_latest_function_response
    raise ValueError(
ValueError: No function call event found for function responses ids: {'call-2'}

Root Cause Analysis & Diagnostic Patch

The root cause appears to be a bug in how the ADK framework manages and propagates event history between parent and sub-agents in a nested AgentTool chain. The official documentation mentions a concept of "event branching", where each event has a branch property to control conversation history visibility among sub-agents. The _rearrange_events_for_latest_function_response function, which is the source of the error, is likely responsible for using this branch information to correctly assemble the event history for the current agent's context. The failure indicates that the history it's seeing is inconsistent, pointing to a bug in the framework's implementation of this event branching and history management.

This hypothesis was confirmed by applying a diagnostic patch to the test. By patching the problematic function to be a no-op, the test passes successfully.

The root cause appears to be a bug in how the ADK framework manages and propagates event history between parent and sub-agents in a nested AgentTool chain. The _rearrange_events_for_latest_function_response function fails because the event history it receives from the parent agent's context seems to be incomplete or out of order.

This hypothesis was confirmed by applying a diagnostic patch to the test. By patching the problematic function to be a no-op, the test passes successfully.

Diagnostic Patch

The following patch, when applied to the test test_root_agent_ticket_creation_workflow, allows the test to pass:

@patch("google.adk.flows.llm_flows.contents._rearrange_events_for_latest_function_response", lambda events: events)

This demonstrates that bypassing the event rearrangement logic prevents the crash, strongly indicating the issue lies within that specific part of the framework's state management.

Conclusion

This bug represents a significant issue for developing complex, multi-agent systems using the ADK. The provided test case in jira_agent_suite/tests/test_multi_agent_workflow.py serves as a minimal, reproducible example of the problem. It is recommended that this report and the associated test case be forwarded to the Google ADK development team for further investigation and resolution.

Activity

  1. added
    core
    on Jul 6, 2025
  2. davisma20 commented on Jul 6, 2025

    @davisma20
    Author

    Bug Report: Event History Corruption in Nested ADK Agent Workflows

    Summary

    This report details a reproducible bug in the Google Agent Development Kit (ADK) where a ValueError is raised due to apparent event history corruption during a nested, multi-agent workflow. Specifically, when a sub-agent is invoked via an AgentTool, the framework incorrectly processes the function_response event, claiming it cannot find the corresponding function_call event in the parent agent's history.

    The error occurs consistently in a test case involving a root agent delegating to a sub-agent, which in turn delegates to another sub-agent. The error message is ValueError: No function call event found for function responses ids: {'call-2'}.

    Environment

    • Python Version: 3.12
    • Framework: Google Agent Development Kit (ADK) for Python

    Steps to Reproduce

    1. Set up the project environment.
    2. Run the isolated test case for the multi-agent workflow:
      python3 -m unittest jira_agent_suite/tests/test_multi_agent_workflow.py

    Expected Behavior

    The test should complete successfully, with the final response from the root agent being returned to the user. The event history should be correctly maintained across all agents in the hierarchy.

    Actual Behavior

    The test fails with a ValueError. The traceback points to an internal ADK function responsible for processing event history.

    Traceback

    Traceback (most recent call last):
      ...
      File "/Library/Frameworks/Python.framework/Versions/3.12/lib/python3.12/site-packages/google/adk/flows/llm_flows/contents.py", line 239, in _get_contents
        result_events = _rearrange_events_for_latest_function_response(
                        ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
      File "/Library/Frameworks/Python.framework/Versions/3.12/lib/python3.12/site-packages/google/adk/flows/llm_flows/contents.py", line 169, in _rearrange_events_for_latest_function_response
        raise ValueError(
    ValueError: No function call event found for function responses ids: {'call-2'}
    

    Root Cause Analysis & Resolution

    A deeper investigation revealed several distinct issues in the test's interaction with the Google ADK framework, leading to the ValueError.

    1. Missing id on FunctionResponse: The primary root cause is a bug or design oversight in the Google ADK. The ADK runner requires google.generativeai.types.FunctionResponse objects to have an id attribute to link them back to the originating FunctionCall. However, the object as provided by the google-generativeai library does not have this field, causing the runner to fail when it cannot find a match.

    2. Incorrect Event author: The author for a FunctionCall event must be the specific string name of the agent making the call (e.g., author='root_agent'). The test was previously using the generic author='model', which prevented the ADK runner from correctly routing the subsequent FunctionResponse back to the right agent.

    3. Improper Session History Loading: The test was attempting to pass the conversation history directly to the runner.run_async() method, which is not supported. The correct procedure is to load events into the session before execution.

    Resolution Workaround

    A stable workaround was developed by manually constructing the entire conversation history. This approach bypasses the ADK's internal history management bugs by providing a complete and correctly formatted event log.

    The solution consists of four key steps:

    1. Manually Construct Event History: Create a list of Event objects representing the complete, nested conversation flow.

    2. Monkey-Patch FunctionResponse: For each FunctionResponse in the history, manually add the id attribute and set its value to match the id of the corresponding FunctionCall.

      # Example of monkey-patching the ID
      function_response_obj = genai.types.FunctionResponse(name="tool_name", response=...)
      function_response_obj.id = "matching_call_id" # Manually add the required ID
    3. Set Correct Event Authors: Ensure the author of each FunctionCall event is the name of the calling agent (e.g., 'ticket_creator_agent') and the author of each FunctionResponse is 'tool'.

    4. Load History with append_event: Before calling run_async, iterate through the constructed history and load each event into the session using runner.session_service.append_event(session, event).

    Conclusion

    The underlying bug in the Google ADK remains a significant issue for developers building multi-agent systems. However, the comprehensive workaround detailed above provides a reliable solution. By taking full control of the event history, developers can ensure test stability and correct agent behavior.

    It is strongly recommended that this report, along with the final, working test case in jira_agent_suite/tests/test_multi_agent_workflow.py, be forwarded to the Google ADK development team for a permanent resolution.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    core

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions