| 33 | |
| 34 | |
| 35 | class _TestingAgent(BaseAgent): |
| 36 | |
| 37 | delay: float = 0 |
| 38 | """The delay before the agent generates an event.""" |
| 39 | |
| 40 | def event(self, ctx: InvocationContext): |
| 41 | return Event( |
| 42 | author=self.name, |
| 43 | branch=ctx.branch, |
| 44 | invocation_id=ctx.invocation_id, |
| 45 | content=types.Content( |
| 46 | parts=[types.Part(text=f'Hello, async {self.name}!')] |
| 47 | ), |
| 48 | ) |
| 49 | |
| 50 | @override |
| 51 | async def _run_async_impl( |
| 52 | self, ctx: InvocationContext |
| 53 | ) -> AsyncGenerator[Event, None]: |
| 54 | await asyncio.sleep(self.delay) |
| 55 | yield self.event(ctx) |
| 56 | if ctx.is_resumable: |
| 57 | ctx.set_agent_state(self.name, end_of_agent=True) |
| 58 | |
| 59 | |
| 60 | async def _create_parent_invocation_context( |
no outgoing calls