> ## 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 chat

> How agent turns stream to your client, and how to consume the stream in the web UI, CLI, or your own code.

Fleet Prime Agent streams every turn as structured events instead of returning a single blob at the end. That's what makes the web UI feel live and what lets scripts react to progress before a turn finishes.

## What you see in a turn

A typical turn produces:

1. `start` — the turn began.
2. `thinking` (only for reasoning models) — the model's plan or reasoning trace.
3. `delta` — streaming assistant text, one chunk at a time.
4. `tool` — one card per tool call, updated as the tool runs.
5. `state` — session state changed (branch, resume, compaction).
6. `done` — turn finished. Errors arrive here or as an `error` event.

For the full event list see [Streaming protocol](/fleet-prime-agent/concepts/streaming-protocol).

## Consuming the stream

**In the web app:** the browser subscribes to NDJSON over an HTTP route (`web/app/src/routes/api/`). The BEUI renderer in `web/design` turns each event into a card.

**From the CLI:** run in `json` mode to get one JSON object per line on stdout, or `rpc` mode for a JSON-RPC framing:

```bash theme={null}
prime-agent --mode json --provider openai --model gpt-4o "Summarize this repo"
```

Pipe the output into `jq` for a quick shell UI:

```bash theme={null}
prime-agent --mode json "..." | jq -rc 'select(.type=="delta") | .text'
```

**From your own code:** attach to the daemon with `DaemonClient` and subscribe to `AgentSessionEvent`. See [Daemon](/fleet-prime-agent/interfaces/daemon).

## Partial messages

The runtime emits `message_update` events carrying the growing `streamingMessage` as the model streams tokens. On `message_end` you get the final `AgentMessage`. Render the partial one until the final one arrives.

## Errors are events

The stream never throws mid-turn. Failures arrive as `done` (with an error status) or as an explicit `error` event. Clients don't need to distinguish between transport and agent errors — both are on the same channel.
