Skip to main content
Every agent turn streams as structured events. Understanding the stream is what lets you build custom clients, debug a stuck turn, or render tool activity in your own UI.

Two shapes of the same stream

Inside the agent runtime, sessions emit AgentSessionEvent:
  • message_start — a new assistant message is beginning
  • message_update — a partial assistant message (streaming text or a partial tool call)
  • message_end — the message is complete
  • tool_execution_start — the agent invoked a tool
  • tool_execution_update — the tool emitted progress
  • tool_execution_end — the tool returned a result
The web adapter (web/server/src/event-mapper.ts) maps those to ChatStreamEvent on the wire, serialized as NDJSON:

Errors are events, not exceptions

The adapter never throws mid-stream. Failures encode as done or error events so clients don’t need to distinguish between transport errors and agent errors — both arrive on the same channel.

Partial messages

While a model streams tokens, the runtime emits message_update events carrying the accumulated streamingMessage. UIs render the partial message as it grows and swap it for the final AgentMessage on message_end.

Where clients live

  • Web — the adapter emits NDJSON for chat and SSE for out-of-turn AgentSessionEvent. Only the adapter imports agent packages; browsers consume the wire format.
  • CLI json / rpc modes — the CLI emits the same events as JSON per line so shell scripts can pipe them.
  • Daemon — clients (DaemonClient) subscribe to AgentSessionEvent directly over the daemon socket.
See Web API and Daemon protocol for the wire references.
Last modified on August 17, 2026