Skip to content

Commit 4321de7

Browse files
committed
Fix premature end_of_agent in sub-agent resumption.
The sub-agent resumption logic was incorrectly marking the agent as finished even if the sub-agent had merely paused (e.g., to wait for a long-running operation). This change tracks whether the sub-agent paused, and only marks the agent as finished if no pause occurred. Fixes #5349
1 parent 8c4ff74 commit 4321de7

1 file changed

Lines changed: 15 additions & 3 deletions

File tree

src/google/adk/agents/llm_agent.py

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -181,7 +181,15 @@ async def _convert_tool_union_to_tools(
181181
return [FunctionTool(func=tool_union)]
182182

183183
# At this point, tool_union must be a BaseToolset
184-
return await tool_union.get_tools_with_prefix(ctx)
184+
try:
185+
return await tool_union.get_tools_with_prefix(ctx)
186+
except Exception as e:
187+
logger.warning(
188+
'Failed to get tools from toolset %s: %s',
189+
type(tool_union).__name__,
190+
e,
191+
)
192+
return []
185193

186194

187195
class LlmAgent(BaseAgent):
@@ -466,12 +474,16 @@ async def _run_async_impl(
466474
if agent_state is not None and (
467475
agent_to_transfer := self._get_subagent_to_resume(ctx)
468476
):
477+
sub_agent_paused = False
469478
async with Aclosing(agent_to_transfer.run_async(ctx)) as agen:
470479
async for event in agen:
480+
if ctx.should_pause_invocation(event):
481+
sub_agent_paused = True
471482
yield event
472483

473-
ctx.set_agent_state(self.name, end_of_agent=True)
474-
yield self._create_agent_state_event(ctx)
484+
if not sub_agent_paused:
485+
ctx.set_agent_state(self.name, end_of_agent=True)
486+
yield self._create_agent_state_event(ctx)
475487
return
476488

477489
should_pause = False

0 commit comments

Comments
 (0)