Required Information
Describe the Bug
When using bidi_stream_query() on Agent Engine, any agent that registers sub-agents via sub_agents=[...] crashes with a 1011 (internal error) WebSocket close when the model calls the built-in transfer_to_agent function. The sub-agent never executes. The session is terminated immediately.
Crash rate: 100% when transfer_to_agent fires (10/10 trials in isolated reproduction).
This is specific to the bidi/live path on Agent Engine. The same agent with the same sub-agents works correctly via Runner.run_async locally (10/10 PASS — sub-agent delegation succeeds, response is produced).
Workaround: Wrapping the sub-agent in AgentTool(agent) instead of registering it via sub_agents=[] avoids the crash. AgentTool registers a regular function call (not transfer_to_agent) that works on the bidi path.
Steps to Reproduce
- Create
subagent_crash/agent.py:
fromgoogle.adk.agentsimportAgentfromgoogle.adk.modelsimportGeminifromgoogle.genai.typesimportGenerateContentConfigfaq_agent=Agent(
name="faq_agent",
description="Answers all user questions",
model=Gemini(model="gemini-2.5-flash"),
instruction="Answer the user's question concisely in 1-2 sentences.",
tools=[],
)
root_agent=Agent(
model=Gemini(model="gemini-live-2.5-flash-native-audio"),
name="root_agent",
instruction=(
"You are a routing agent. You MUST delegate ALL user messages to faq_agent ""using the transfer_to_agent function. ""NEVER answer any question yourself. NEVER respond directly. ""For EVERY single user message, immediately call transfer_to_agent with ""agent_name='faq_agent'. No exceptions."
),
sub_agents=[faq_agent],
tools=[],
generate_content_config=GenerateContentConfig(temperature=0.0),
)
- Create
subagent_crash/agent_engine_app.py:
fromvertexai.preview.reasoning_engines.templates.adkimportAdkAppfromsubagent_crash.agentimportroot_agentclassAgentEngineApp(AdkApp):
defregister_operations(self):
operations=super().register_operations()
operations["bidi_stream"] = ["bidi_stream_query"]
returnoperationsagent_engine=AgentEngineApp(agent=root_agent)
- Deploy to Agent Engine, connect via bidi, and send any message:
importasyncioimportvertexaiasyncdeftest():
client=vertexai.Client(project="YOUR_PROJECT", location="us-central1")
asyncwithclient.aio.live.agent_engines.connect(
agent_engine="projects/.../reasoningEngines/..."
) assession:
awaitsession.send(query_input={"user_id": "test"})
awaitsession.send(query_input={
"content": {"role": "user", "parts": [{"text": "Hello"}]}
})
whileTrue:
event=awaitasyncio.wait_for(session.receive(), timeout=15)
print(event)
asyncio.run(test())Expected Behavior
The model calls transfer_to_agent(agent_name="faq_agent"), ADK transfers control to faq_agent, the sub-agent responds, and the response is streamed back via the bidi session.
Actual Behavior
Event 1: function_call: transfer_to_agent(agent_name="faq_agent")
Event 2: function_response: transfer_to_agent → result: null
→ ConnectionClosedError: received 1011 (internal error)
→ "Reasoning Engine Execution failed"
The WebSocket closes immediately after the transfer_to_agent function response. Only 4 events are produced. No content is delivered to the user.
Key Distinction: sub_agents vs AgentTool
This crash is specific to the sub_agents=[] parameter, which registers the built-in transfer_to_agent function. Wrapping the same agent in AgentTool() and placing it in tools=[] registers a regular function call and does not crash:
# CRASHES on bidi — uses transfer_to_agent internallyroot_agent=Agent(
sub_agents=[faq_agent],
...
)
# WORKS on bidi — uses regular function callfromgoogle.adk.toolsimportAgentToolroot_agent=Agent(
tools=[AgentTool(faq_agent)],
...
)
Both patterns work identically via Runner.run_async locally. The crash is only on the Agent Engine bidi path.
Local Baseline
Same agent tested locally via Runner.run_async with gemini-2.5-flash: 10/10 PASS. transfer_to_agent is called, the sub-agent runs, a response is produced. The crash is specific to Agent Engine's bidi_stream_query.
Environment
google-adk==1.28.1google-cloud-aiplatform==1.145.0- Model:
gemini-live-2.5-flash-native-audio (root), gemini-2.5-flash (sub-agent) - Path:
bidi_stream_query on Vertex AI Agent Engine - Python 3.10
- Region: us-central1
Related Issues
Required Information
Describe the Bug
When using
bidi_stream_query()on Agent Engine, any agent that registers sub-agents viasub_agents=[...]crashes with a1011 (internal error)WebSocket close when the model calls the built-intransfer_to_agentfunction. The sub-agent never executes. The session is terminated immediately.Crash rate: 100% when
transfer_to_agentfires (10/10 trials in isolated reproduction).This is specific to the bidi/live path on Agent Engine. The same agent with the same sub-agents works correctly via
Runner.run_asynclocally (10/10 PASS — sub-agent delegation succeeds, response is produced).Workaround: Wrapping the sub-agent in
AgentTool(agent)instead of registering it viasub_agents=[]avoids the crash.AgentToolregisters a regular function call (nottransfer_to_agent) that works on the bidi path.Steps to Reproduce
subagent_crash/agent.py:subagent_crash/agent_engine_app.py:Expected Behavior
The model calls
transfer_to_agent(agent_name="faq_agent"), ADK transfers control tofaq_agent, the sub-agent responds, and the response is streamed back via the bidi session.Actual Behavior
The WebSocket closes immediately after the
transfer_to_agentfunction response. Only 4 events are produced. No content is delivered to the user.Key Distinction:
sub_agentsvsAgentToolThis crash is specific to the
sub_agents=[]parameter, which registers the built-intransfer_to_agentfunction. Wrapping the same agent inAgentTool()and placing it intools=[]registers a regular function call and does not crash:Both patterns work identically via
Runner.run_asynclocally. The crash is only on the Agent Engine bidi path.Local Baseline
Same agent tested locally via
Runner.run_asyncwithgemini-2.5-flash: 10/10 PASS.transfer_to_agentis called, the sub-agent runs, a response is produced. The crash is specific to Agent Engine'sbidi_stream_query.Environment
google-adk==1.28.1google-cloud-aiplatform==1.145.0gemini-live-2.5-flash-native-audio(root),gemini-2.5-flash(sub-agent)bidi_stream_queryon Vertex AI Agent EngineRelated Issues
run_live(): Fire-and-forget tool calls cause duplicate model responses via orphaned function response reinjection #4902 — Duplicate responses from orphaned tool re-entry (fixed in 1.28.1, different mechanism)bidi_stream_query(fix merged, pending release)