Skip to main content

Multi-Turn Chat

This guide shows how to build a stateful conversation with streaming output, history management, and proper turn lifecycle.

The History Pattern

SimpleLLMFunc agents are stateless by default — they don’t store conversation history internally. You pass history in, you get updated history back. This makes state management explicit and testable.
The parameter named history (or chat_history) is special — the framework uses it to carry conversation state between turns.

Streaming Responses

Each output.messages contains the full updated conversation. Pass it back for the next turn.

Event-Aware Consumption

For richer UX, handle individual events:

Non-Streaming Mode

For simpler use cases where you just want the final response:

Why History is External

This is a deliberate design choice:
  • Testable — You can snapshot and replay any conversation state
  • Flexible storage — Store in memory, Redis, disk, database — your choice
  • Fork-friendly — Branch a conversation by copying the history list
  • No hidden state — The agent has no memory you don’t control
For agents that need durable, self-modifying context (experiences, compaction, forking), see SelfRef.

What’s Next

Design Philosophy

Understand why the framework is designed this way.

Context Model

Learn how context is structured, mutated, and compiled.