Fix ADK single-turn agent-as-tool hanging on Conductor - #468
Draft
ling-senpeng13 wants to merge 1 commit into
Draft
Fix ADK single-turn agent-as-tool hanging on Conductor#468ling-senpeng13 wants to merge 1 commit into
ling-senpeng13 wants to merge 1 commit into
Conversation
google-adk materialises a tool wrapper into the parent's `tools` for every
sub-agent declared `mode="single_turn"` or `mode="task"`, and leaves that
sub-agent in `sub_agents` as well. ADK reconciles the duplication per request,
when it assembles the model call; the server compiles from the serialized
snapshot, where no such step exists, so both survive.
The compiler then sees a coordinator with tools AND sub-agents and offers the
model two routes per sub-agent with incompatible semantics: the bare sub-agent
name, routed to FORK_JOIN_DYNAMIC as a SIMPLE task no worker is registered for
(SCHEDULED forever, JOIN never completes), or a transfer control signal that
ends the loop and hands off permanently to exactly one specialist. The
workflow either hangs with no error or returns a partial answer.
Two changes to the serializer:
- Emit ADK agent-tools under the public `AgentTool` shape. Detection is an
isinstance check against the exported base class, so it covers the private
subclasses ADK materialises for single_turn/task without naming them.
Serialization routes through the enclosing `_serialize` so the shared
`seen` set terminates ADK's `parent_agent` back-reference.
- Drop sub-agents already reachable as an agent-tool from `sub_agents`,
keyed on object identity since ADK wraps the very same instance.
Adds an e2e regression test, guarded by importorskip on google-adk.
Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
An ADK coordinator whose sub-agents declare
mode="single_turn"hangs on Conductor — status stays RUNNING, no error, no timeout, no answer. The identical agent runs correctly underadk web/adk run.Cause
ADK creates the duplicate itself. Declaring a sub-agent
mode="single_turn"auto-inserts a private tool wrapper into the parent'stoolswhile still listing that agent insub_agents. Serializing the reported coordinator shows both fields carrying the same two children:ADK reconciles this per request —
_get_transfer_targets()drops single-turn sub-agents when it assembles the model call. The server compiles from a serialized snapshot, where no such step exists, so both survive. It sees a coordinator with tools and sub-agents and offers the model two routes per child with incompatible semantics: the bare sub-agent name, forked as a SIMPLE task no worker is registered for (SCHEDULED forever, JOIN never completes), or a transfer signal that ends the loop and hands off permanently to one specialist. Hence either a hang or a partial answer.Compounding it, the serializer didn't recognise the wrapper at all: agent-as-tool detection gated on
_is_agent_tool, an OpenAI-SDK attribute the ADK wrapper lacks, so it fell through to generic pydantic walking and emitted the private class name as its_type.Fix
Two changes in
serializer.py, both keyed on oneisinstancecheck against ADK's exportedAgentToolbase class — which covers the private subclasses forsingle_turnandtaskwithout naming them, and won't break on an ADK rename:AgentToolshape.sub_agents, keyed on object identity since ADK wraps the very same instance.Adds an e2e regression test, guarded by
importorskipon google-adk.