When do you need sessions?
A bareDialogMachine holds its conversation state in memory for the lifetime of the instance. This works perfectly for:
- Voice calls (one machine per call, ephemeral)
- CLI testing (single conversation, short-lived)
- Simple single-user demos
SessionWorker when:
- Multi-user: multiple concurrent conversations hit the same process
- Multi-worker: requests are load-balanced across FastAPI workers or pods
- Long-lived chat: conversations span hours or days and must survive restarts
The Agent Protocol
SessionWorker works with any brain that implements this Protocol - not just DialogMachine:
DialogMachine, LLMAgent, and LangChainAgent all implement this.
SessionWorker
acquire does:
- Loads or creates the session for
session_id - Acquires a per-session lock (serialises concurrent requests for the same id)
- Yields a
SessionHandle - On exit: persists state to the store and releases the lock
session_ids run fully in parallel.
FastAPI multi-user example
Session stores
| Store | Status | Use case |
|---|---|---|
InMemorySessionStore | ✅ v0.2 | Development, single-process |
NullSessionStore | ✅ v0.2 | Voice (ephemeral, no persistence) |
RedisSessionStore | 🔜 v0.3 | Multi-process, distributed |
FileSessionStore | 🔜 v0.3 | Lightweight persistence |
SQLiteSessionStore | 🔜 v0.3 | Local single-server |
Lock backends
| Backend | Status | Use case |
|---|---|---|
AsyncioLockBackend | ✅ v0.2 | Single-process (default) |
RedisLockBackend | 🔜 v0.3 | Multi-process / distributed |
Non-DM agent brains
When you want sessions and persistence but not the flow/state-machine opinion:pip install superdialog[langchain]):
ChatContext and FlowState
Internally, each session stores:-
ChatContext- message history (LiveKit-aligned) -
FlowState- DM-specific runtime state (current node, slot values). Present only when the brain is aDialogMachine;NoneforLLMAgent/LangChainAgent.
Voice (ephemeral) pattern
For voice calls where each call is a fresh conversation and no persistence is needed:NullSessionStore keeps the single-call lifecycle of a bare DialogMachine while still giving you the multiplexing and locking of SessionWorker.