Skip to slide
Chapter 8 · Streaming and Real-Time UX
68 / 191

CHAPTER 08 · Streaming and Real-Time UX · 2 / 10

The transport: SSE vs WebSockets

Two common transports:

  • Server-Sent Events (SSE): a one-way stream of text events from server to client over plain HTTP. Simple, works through most proxies, auto-reconnects, and fits the agent case perfectly because the data flow is overwhelmingly server→client. The request carries the user's message; the response is the stream of events.
  • WebSockets: full-duplex. Worth it only if you need rich client→server messaging mid-turn (e.g. interrupting, live collaboration). For most agents, that's overkill.

SSE is the pragmatic default. Set the right headers (event-stream content type, no caching, disable proxy buffering), flush immediately, and write events as data: frames. End with a sentinel ([DONE]) so the client knows the turn is complete.

← → arrow keys work too