|
14 | 14 | RuntimeAvailability, |
15 | 15 | ToolCallAudit, |
16 | 16 | ) |
| 17 | +from agent_runtime_kit.events import ( |
| 18 | + output_delta_event, |
| 19 | + safe_emit, |
| 20 | + task_completed_event, |
| 21 | + task_failed_event, |
| 22 | + task_started_event, |
| 23 | + tool_completed_event, |
| 24 | + tool_requested_event, |
| 25 | + vendor_turn_event, |
| 26 | +) |
17 | 27 |
|
18 | 28 |
|
19 | 29 | class FakeAgentRuntime: |
@@ -49,20 +59,52 @@ def availability(self) -> RuntimeAvailability: |
49 | 59 | async def run(self, task: AgentTask) -> AgentResult: |
50 | 60 | """Return a deterministic result after validating capabilities.""" |
51 | 61 |
|
52 | | - _ensure_supported(self.kind, self.capabilities, task) |
53 | | - output = self._output if self._output is not None else f"Fake result for: {task.goal}" |
54 | | - parsed = {"output": output} if task.output_schema is not None else None |
55 | | - tool_calls = ( |
56 | | - ToolCallAudit(tool_name="fake", arguments={"goal": task.goal}, result_preview=output), |
57 | | - ) |
58 | | - return AgentResult( |
59 | | - output=output, |
60 | | - parsed_output=parsed, |
61 | | - tool_calls=tool_calls, |
62 | | - session_id=task.session_id or task.task_id, |
63 | | - rounds=1, |
64 | | - metadata={"task_id": task.task_id, **self._metadata}, |
65 | | - ) |
| 62 | + await safe_emit(task, task_started_event(task, self.kind)) |
| 63 | + try: |
| 64 | + _ensure_supported(self.kind, self.capabilities, task) |
| 65 | + output = self._output if self._output is not None else f"Fake result for: {task.goal}" |
| 66 | + parsed = {"output": output} if task.output_schema is not None else None |
| 67 | + tool_call = ToolCallAudit( |
| 68 | + tool_name="fake", |
| 69 | + arguments={"goal": task.goal}, |
| 70 | + result_preview=output, |
| 71 | + ) |
| 72 | + await safe_emit( |
| 73 | + task, |
| 74 | + output_delta_event(task, self.kind, text=output), |
| 75 | + ) |
| 76 | + await safe_emit( |
| 77 | + task, |
| 78 | + tool_requested_event( |
| 79 | + task, |
| 80 | + self.kind, |
| 81 | + tool_name="fake", |
| 82 | + arguments=tool_call.arguments, |
| 83 | + ), |
| 84 | + ) |
| 85 | + await safe_emit(task, tool_completed_event(task, self.kind, tool_call)) |
| 86 | + await safe_emit( |
| 87 | + task, |
| 88 | + vendor_turn_event( |
| 89 | + task, |
| 90 | + self.kind, |
| 91 | + payload={"runtime": "fake", "round": 1}, |
| 92 | + summary="fake runtime completed one turn", |
| 93 | + ), |
| 94 | + ) |
| 95 | + result = AgentResult( |
| 96 | + output=output, |
| 97 | + parsed_output=parsed, |
| 98 | + tool_calls=(tool_call,), |
| 99 | + session_id=task.session_id or task.task_id, |
| 100 | + rounds=1, |
| 101 | + metadata={"task_id": task.task_id, **self._metadata}, |
| 102 | + ) |
| 103 | + except Exception as exc: |
| 104 | + await safe_emit(task, task_failed_event(task, self.kind, error=str(exc))) |
| 105 | + raise |
| 106 | + await safe_emit(task, task_completed_event(task, self.kind, result)) |
| 107 | + return result |
66 | 108 |
|
67 | 109 | async def cancel(self, task_id: str) -> None: |
68 | 110 | """Record cancellation requests for assertions.""" |
|
0 commit comments