> ## Documentation Index
> Fetch the complete documentation index at: https://docs.qredence.ai/llms.txt
> Use this file to discover all available pages before exploring further.

# Streaming protocol

> The event stream Fleet Prime Agent emits: AgentSessionEvent internally, ChatStreamEvent NDJSON to the web.

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:

| Event        | Meaning                                        |
| ------------ | ---------------------------------------------- |
| `start`      | New turn beginning                             |
| `delta`      | Streaming assistant text                       |
| `tool`       | Tool card update (start, progress, end)        |
| `thinking`   | Reasoning trace from a reasoning-capable model |
| `plan`       | The agent posted a plan                        |
| `state`      | Session state changed                          |
| `queue`      | Turn queued behind another                     |
| `compaction` | Compaction ran mid-turn                        |
| `retry`      | The agent retried a failing step               |
| `done`       | Turn finished successfully                     |
| `error`      | Turn ended with an error                       |

## 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](/fleet-prime-agent/reference/web-api) and [Daemon protocol](/fleet-prime-agent/reference/daemon-protocol) for the wire references.
