Stateful vs stateless AI agents
A stateless AI agent treats every conversation as fresh — it has no memory of past sessions, no per-user history, no relationship continuity. A stateful AI agent remembers users across sessions, evolves over time, and stays in character. The difference is the presence of a memory layer and (optionally) a personality, mood, and relationship model. Stateless is simpler and cheaper. Stateful is required for any product where users come back.
What "stateless" means in practice
A stateless agent is just a function: prompt in, response out. The model doesn't remember anything between calls. If you want continuity within a conversation, you stuff the message history into the prompt. If you want continuity across conversations, you'd have to stuff the entire user history into every prompt — which gets expensive fast and doesn't scale past a few sessions.
ChatGPT was famously stateless until OpenAI added memory in 2024. Most LLM API integrations are still stateless by default.
What "stateful" means in practice
A stateful agent has external storage that persists across conversations: facts about the user, summaries of past sessions, relationship context, and (in richer systems) personality and mood. Before each LLM call, the relevant slice of state is retrieved and injected into the prompt. After the call, new information is written back.
The state lives outside the model — usually in a memory layer like Sonzai, Mem0, Zep, or Letta. The LLM itself stays the same.
When stateless is enough
- →One-shot completions (translation, summarization, classification).
- →Document Q&A where every query is independent.
- →Anonymous, single-session chatbots.
- →Internal tools where users don't expect continuity.
When you need stateful
- →AI companions and characters — users expect to be remembered.
- →Tutors — the agent needs to know what each student has learned.
- →Customer-facing agents — context across support tickets, prior purchases, and history.
- →Voice agents — picking up where the last call left off.
- →Game NPCs — characters who remember the player.
- →AI employees — anything that handles a relationship over weeks or months.
How to turn a stateless agent stateful
Three steps:
- →1. Pick a memory layer. Use a hosted service (Sonzai, Mem0, Zep) or build your own. Building your own takes months to do well.
- →2. Wire it into your LLM call path. Before each call, fetch context. After each call, write new state.
- →3. Add a stable identifier per user. The memory layer needs to know which user is which. A hashed external ID works.
With Sonzai, this is three API calls: create an agent, post a chat turn, and the memory tree is built and maintained for you.
Stateful is more than memory
The biggest mistake people make is thinking "stateful" means "remembers facts." Real statefulness includes:
- →Memory — facts, episodes, summaries.
- →Personality — stable traits that don't drift between sessions.
- →Mood — emotional state that fluctuates and recovers.
- →Relationships — knowing who the user is and how the agent feels about them.
- →Knowledge — facts about the world the agent inhabits.
A truly stateful agent has all five. Most "memory layers" only provide the first one. Sonzai bundles all five into one API.
Build a stateful agent with Sonzai
Memory, personality, mood, relationships, and a knowledge base in one API. SDKs for TypeScript, Python, and Go.