Skip to content

_find_agent_to_run selects an older agent instead of the most recently active one #1807

Closed

Description

@devevignesh

Description
The _find_agent_to_run method in the Google ADK Runner exhibits incorrect behavior when determining which agent should handle a new user message. It selects an agent from earlier in the conversation history instead of the most recently active agent, causing the conversation to be routed incorrectly.

Root Cause
The core of the issue is the current implementation of the _find_agent_to_run method.

Current Behavior:
The method searches backward through all events in the session history. It returns the first agent it encounters that meets the following criteria:

It is the root agent, OR

It is an LlmAgent that can transfer to other agents (i.e., _is_transferable_across_agent_tree returns True).

The Problem:
In a session where multiple transferable agents have been active (e.g., a x_agent followed by an y_agent), the backward search encounters the x_agent's events first because they are earlier in the history. Since both agents are transferable LlmAgents, the search incorrectly concludes that the x_agent should handle the message, even though the y_agent was the most recent one to interact with the user.

The search logic does not prioritize the most recently active agent.

Expected Behavior
The _find_agent_to_run method should identify and return the most recently active agent that is capable of handling the new message. The search should prioritize recency to ensure the conversation continues with the correct context.

Desktop (please complete the following information):

  • OS: [e.g. iOS]
  • Python version(python -V): 3.13.3
  • ADK version(pip show google-adk): 1.5.0

Model Information:
For example, which model is being used.

Additional context
Add any other context about the problem here.

Activity

  1. changed the title [-]_find_agent_to_run selects an older agent instead of the most recently active one[/-] [+]`_find_agent_to_run selects` an older agent instead of the most recently active one[/+] on Jul 6, 2025
  2. changed the title [-]`_find_agent_to_run selects` an older agent instead of the most recently active one[/-] [+]`_find_agent_to_run` selects an older agent instead of the most recently active one[/+] on Jul 6, 2025
  3. added
    core[Component] This issue is related to the core interface and implementation
    on Jul 6, 2025
  4. devevignesh commented on Jul 8, 2025

    @devevignesh
    Author

    @DeanChensj could you please look into this?

  5. added this to the 08/11 FixIt Week milestone on Aug 8, 2025
  6. hangfei commented on Oct 28, 2025

    @hangfei
    Collaborator

    It should be fixed. Please retry with latest version. If you still find this issue, please re-open.

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

Metadata

Metadata

Labels

core[Component] This issue is related to the core interface and implementation

Type

Projects

No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions