Streaming & UX

Streaming Typed Events

Push partial results to the client as typed events as they become available, rather than waiting for the full response.

Problem

Waiting until the full answer is generated before rendering anything feels sluggish even when the actual generation is fast, because the user has nothing to look at during the wait. Streaming a single channel of plain text helps with perceived latency but loses the structure the interface needs: the client receives a stream of characters with no way to tell apart a token of the main answer, the start of a tool call, a structured card, or an error. Without a typed event vocabulary on the stream, the client either waits for the end or guesses, and neither produces a good interface.

Solution

Use Server-Sent Events (or WebSocket) with a typed event vocabulary: text_delta (token), card (structured), suggestions, tool_start, tool_end, done, error. The client routes each event to the right UI component. Reconnect with last-event-id resumption.

When to use

  • User-facing agents where time-to-first-token is perceived latency.
  • The UI shows cards, suggestions, or progressive disclosure that need typed events.
  • A transport (SSE, WebSocket) supports event streams with reconnection.

Open the full interactive page

Diagram, neighbourhood map, code examples, related patterns and full provenance.

Related