Entry method to run an agent via text-based conversation. Args: parent_context: InvocationContext, the invocation context of the parent agent. Yields: Event: the events generated by the agent.
(
self,
parent_context: InvocationContext,
)
| 281 | return cloned_agent |
| 282 | |
| 283 | async def run_async( |
| 284 | self, |
| 285 | parent_context: InvocationContext, |
| 286 | ) -> AsyncGenerator[Event, None]: |
| 287 | """Entry method to run an agent via text-based conversation. |
| 288 | |
| 289 | Args: |
| 290 | parent_context: InvocationContext, the invocation context of the parent |
| 291 | agent. |
| 292 | |
| 293 | Yields: |
| 294 | Event: the events generated by the agent. |
| 295 | """ |
| 296 | |
| 297 | ctx = self._create_invocation_context(parent_context) |
| 298 | async with _instrumentation.record_agent_invocation(ctx, self): |
| 299 | if event := await self._handle_before_agent_callback(ctx): |
| 300 | yield event |
| 301 | if ctx.end_invocation: |
| 302 | return |
| 303 | |
| 304 | async with Aclosing(self._run_async_impl(ctx)) as agen: |
| 305 | async for event in agen: |
| 306 | yield event |
| 307 | |
| 308 | if ctx.end_invocation: |
| 309 | return |
| 310 | |
| 311 | if event := await self._handle_after_agent_callback(ctx): |
| 312 | yield event |
| 313 | |
| 314 | @override |
| 315 | async def _run_impl( |
no test coverage detected