Skip to main content

The Problem

Users hate waiting. A 3-second response feels like an eternity when you’re staring at a blank screen. Traditional request/response patterns make your agent feel sluggish, even when the LLM is fast. The UI waits for the entire response before showing anything.
Streaming changes everything. Users see tokens appear in real-time, making responses feel instant even when they take seconds to complete.

Quick Start

ElizaOS supports three response modes out of the box:

HTTP Streaming

Send a message with stream: true to get Server-Sent Events:

WebSocket Connection

For bidirectional communication and voice conversations:

Stream Events

The streaming API emits these event types:

Chunk Event

Complete Event

Custom Stream Extractors

ElizaOS uses stream extractors to filter LLM output for streaming. The framework provides several built-in extractors:

PassthroughExtractor

Streams everything as-is. Use for plain text responses.

XmlTagExtractor

Extracts content from a specific XML tag. Use when LLM outputs structured XML.

ResponseStreamExtractor

Action-aware extraction used by DefaultMessageService. Understands <actions> to decide what to stream.

Custom Extractor

Implement IStreamExtractor for custom filtering logic:

Stream Error Handling

The streaming system provides typed errors for robust handling:

Performance Tips

Keep extractors simple

Complex parsing logic in push() blocks the stream. Do heavy processing after streaming completes.

Use appropriate margins

XML extractors keep a safety margin to avoid splitting closing tags. Default is 10 characters.

Handle backpressure

If your UI can’t keep up, chunks queue up in memory. Consider throttling or dropping old chunks.

Clean up resources

Call extractor.reset() between conversations to clear buffers and state.

Architecture

Data Flow:
  1. LLM Provider generates tokens via async iterator
  2. Stream Extractor filters output, extracts streamable content, buffers for tag boundaries
  3. SSE/WebSocket sends chunks to client progressively
  4. UI updates in real-time as chunks arrive

Next Steps

Message Service

Learn how DefaultMessageService uses streaming internally

Model Types

Configure streaming behavior per model type

WebSocket API

Full WebSocket API reference

Types Reference

Complete streaming type definitions