Skip to content

Commit a86efa6

Browse files
ykumaraswamyGWeale
authored andcommitted
fix(runners): fall back to root agent when a resumed call author is not in the tree
`Runner._find_agent_to_run` is annotated `-> BaseAgent` and documents that it "falls back to root agent if no suitable agents are found". But on a resumable resume from a function response it returned `root_agent.find_agent(event.author)` unconditionally, and `find_agent` returns None when `event.author` is not a node in the agent tree (host integrations commonly hydrate resumed or external events with author='user'). That None then flowed into `build_node(agent_to_run)` in `run_async`, raising "ValueError: Invalid node type: <class 'NoneType'>". Fix: in the resumable branch, only short-circuit when `find_agent` resolves the author; otherwise fall through to the existing event scan and root-agent fallback. This matches the non-resumable branch and the method's documented contract, so the change only turns a guaranteed crash into the documented fallback. Also de-nests the TestRunnerFindAgentToRun tests, which were accidentally defined inside a module-level test function and never collected, and adds two regression tests. Change-Id: I7d64187be5e6443a185a20b0ad08bea3ae017fb1
1 parent a5fa3da commit a86efa6

2 files changed

Lines changed: 493 additions & 396 deletions

File tree

src/google/adk/runners.py

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1728,7 +1728,15 @@ def _find_agent_to_run(
17281728
# shouldn't trap the next turn on that same agent if it's not transferable.
17291729
# Falling through allows it to return to root.
17301730
if event and event.author and is_resumable:
1731-
return root_agent.find_agent(event.author)
1731+
# `find_agent` returns None when the author does not correspond to any
1732+
# agent in the current hierarchy (e.g. the author is "user" or a stale or
1733+
# foreign agent name carried over from a previous turn/session). Returning
1734+
# None here would propagate to `build_node`, raising a confusing
1735+
# "Invalid node type: <class 'NoneType'>" error. Fall through to the
1736+
# event-scan logic below (which ultimately falls back to the root agent)
1737+
# whenever the author cannot be resolved.
1738+
if (resumed_agent := root_agent.find_agent(event.author)) is not None:
1739+
return resumed_agent
17321740

17331741
def _event_filter(event: Event) -> bool:
17341742
"""Filters out user-authored events and agent state change events."""

0 commit comments

Comments
 (0)