Skip to main content
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:
Those are great for apps that only need a response. Live runtimes need more:
  • 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
That is what 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

Use send() to steer a live turn.
Steering is safe-boundary control. The message is queued and injected before the next model call. It does not mutate a provider request already in flight, and it does not interrupt a tool that is already running. steer() is an alias for send():

Cancellation

Aborting signals the active turn. Providers and tools must honor abort signals to stop immediately; otherwise cancellation happens at the next point the runtime checks the signal.

SSE Example

The stock AgentServer exposes the complete turn stream:
Each SSE frame contains one public TurnEvent. The SSE event name and JSON type match:
Use ?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 with AgentTurn for simple apps. Use:
  • chat() when you only need text
  • stream() when you only need streamed text
  • run() when you need metadata after completion
  • turn() when you need a live runtime