-
Notifications
You must be signed in to change notification settings - Fork 80
Description
** Please make sure you read the contribution guide and file the issues in the
right place. **
Contribution guide.
Describe the bug
- This occurred due to a bug in how Google ADK handles agent tree initialization. When subAgents are initialized independently before their parent (e.g. orchestrator), their
rootAgentproperty is computed immediately and incorrectly points to themselves . Even though the orchestrator later sets itself as their parent, the rootAgent reference remains stale. Consequently, when a sub-agent tries to find another agent in the tree, it searches only within its own isolated scope and fails. - The parent agent (orchestrator) calls setParentAgentForSubAgents() during its own initialization.
- This method updates the parentAgent of the sub-agents, but it fails to update their rootAgent.
The rootAgent property is critical for the getAgentByName method, which is used to locate the target agent when transferring control (a "handoff").
Here is the flow in @google/adk:
1.The agent's runAsyncImpl loop detects the transfer action
2. The getAgentByName helper uses rootAgent as the starting point for the search
To Reproduce
Steps to reproduce the behavior:
- Instantiate sub-agents before the parent. This is possible because
BaseAgent.config.parentAgentis optional. - Add sub-agent to parent inside the
subAgentsarray - Try to interact again with the parent agent.
- An error with
"type":"RUN_ERROR","message":"Run ended without emitting a terminal event","code":"INCOMPLETE_STREAM"}
Expected behavior
The subAgent should be able to find its rootAgent hence being able to transfer back the control.
Screenshots
If applicable, add screenshots to help explain your problem.
Desktop (please complete the following information):
- OS: macOS
- TS version/environment: 5.9.3
- ADK version(see maven dependency): 0.2.4
Additional context
data: {"type":"RUN_STARTED","threadId":"81d658fe-bb82-4691-814a-543e4204a800","runId":"dd20ecc0-0e5b-446b-b030-e7f12fa82e56","input":{"threadId":"81d658fe-bb82-4691-814a-543e4204a800","runId":"d255752d-e866-476c-a619-0ce6af9c3ae5","state":{},"messages":[{"id":"57327d3b-d7a8-4321-a862-6af4428928a8","role":"user","content":"what is the weather in barcelona?"}],"tools":[],"context":[],"forwardedProps":{}}}
data: {"type":"TEXT_MESSAGE_START","messageId":"451b8295-b4fe-495e-a9a5-e2968966ebe1","role":"assistant"}
data: {"type":"TEXT_MESSAGE_END","messageId":"451b8295-b4fe-495e-a9a5-e2968966ebe1"}
data: {"type":"RUN_ERROR","message":"Run ended without emitting a terminal event","code":"INCOMPLETE_STREAM"}