AgentTurn is the advanced agent primitive for interactive runtimes.
Use it when chat() and stream() are too flat and your application needs lifecycle events, a structured final result, cancellation, or the ability to steer the model while it is working.
Why Turns Exist
Agents already provide simple methods:- emit text as it streams
- show step status
- display reasoning events
- cancel a run
- inject new user guidance before the next model step
- wait for the structured final result after streaming events
agent.turn() is for.
Basic Turn
turn.events() starts the turn lazily. turn.result() also starts it if it has not started yet.
Event Stream
Current turn events:Steering
Usesend() to steer a live turn.
steer() is an alias for send():
Cancellation
SSE Example
The stockAgentServer exposes the complete turn stream:
TurnEvent. The SSE event name and JSON
type match:
?stream=true when a client only needs the legacy start, chunk, and
end text stream. Use ?stream=events for reasoning, retries, steps, tools,
usage, structured completion, and typed failures.
The /events endpoint is different: it replays durable application events
created with Agent.emit(). Chat turn events are transient and belong to the
single POST response that started the turn.
Python clients reconstruct the wire payloads into the same event dataclasses:
CLI Example
When Not To Use Turns
Do not start withAgentTurn for simple apps.
Use:
chat()when you only need textstream()when you only need streamed textrun()when you need metadata after completionturn()when you need a live runtime