class CodingAgent(Agent[dict[str, Any]]):
async def run_cli_turn(self, message: str) -> str:
turn = self.turn(message)
self._current_turn = turn
try:
async for event in turn.events():
if event.type == "text.delta":
print(event.text, end="", flush=True)
elif event.type.startswith("reasoning."):
await self.emit("reasoning", {
"kind": event.event.kind,
"text": event.event.text,
"data": event.event.data,
})
elif event.type.startswith("tool_"):
await self.emit("tool", {
"type": event.type,
"step": event.step_number,
"index": event.index,
})
elif event.type == "step.started":
await self.emit("status", {"step": event.step_number})
result = await turn.result()
return result.text
finally:
if self._current_turn is turn:
self._current_turn = None
async def steer_current_turn(self, message: str) -> None:
if self._current_turn and not self._current_turn.done:
await self._current_turn.send(message)