MCPcopy Create free account
hub / github.com/google/adk-python / _run_async_impl

Method _run_async_impl

src/google/adk/agents/llm_agent.py:495–532  ·  view source on GitHub ↗
(
      self, ctx: InvocationContext
  )

Source from the content-addressed store, hash-verified

493
494 @override
495 async def _run_async_impl(
496 self, ctx: InvocationContext
497 ) -> AsyncGenerator[Event, None]:
498 agent_state = self._load_agent_state(ctx, BaseAgentState)
499
500 # If there is a sub-agent to resume, run it and then end the current
501 # agent.
502 if agent_state is not None and (
503 agent_to_transfer := self._get_subagent_to_resume(ctx)
504 ):
505 async with Aclosing(agent_to_transfer.run_async(ctx)) as agen:
506 async for event in agen:
507 yield event
508
509 ctx.set_agent_state(self.name, end_of_agent=True)
510 yield self._create_agent_state_event(ctx)
511 return
512
513 should_pause = False
514 async with Aclosing(self._llm_flow.run_async(ctx)) as agen:
515 async for event in agen:
516 self.__maybe_save_output_to_state(event)
517 yield event
518 if ctx.should_pause_invocation(event):
519 # Do not pause immediately, wait until the long-running tool call is
520 # executed.
521 should_pause = True
522 if should_pause:
523 return
524
525 if ctx.is_resumable:
526 events = ctx._get_events(current_invocation=True, current_branch=True)
527 if events and any(ctx.should_pause_invocation(e) for e in events[-2:]):
528 return
529 # Only yield an end state if the last event is no longer a long-running
530 # tool call.
531 ctx.set_agent_state(self.name, end_of_agent=True)
532 yield self._create_agent_state_event(ctx)
533
534 @override
535 async def _run_live_impl(

Callers

nothing calls this directly

Calls 8

_load_agent_stateMethod · 0.80
set_agent_stateMethod · 0.80
_get_eventsMethod · 0.80
run_asyncMethod · 0.45

Tested by

no test coverage detected