A Fake Runner that delegates run_async to a provided function.
| 33 | |
| 34 | |
| 35 | class FakeRunner(Runner): |
| 36 | """A Fake Runner that delegates run_async to a provided function.""" |
| 37 | |
| 38 | def __init__(self, run_async_fn): |
| 39 | agent = Mock(spec=BaseAgent) |
| 40 | agent.name = "FakeAgent" |
| 41 | |
| 42 | session_service = InMemorySessionService() |
| 43 | super().__init__( |
| 44 | app_name="FakeApp", |
| 45 | agent=agent, |
| 46 | session_service=session_service, |
| 47 | ) |
| 48 | self.run_async_fn = run_async_fn |
| 49 | |
| 50 | mock_artifact_service = Mock() |
| 51 | mock_artifact_service.load_artifact = AsyncMock( |
| 52 | return_value=types.Part(text="artifact content") |
| 53 | ) |
| 54 | self.artifact_service = mock_artifact_service |
| 55 | |
| 56 | async def run_async(self, **kwargs): |
| 57 | async for event in self.run_async_fn(**kwargs): |
| 58 | yield event |
| 59 | |
| 60 | |
| 61 | agent_card = AgentCard( |