Home / Insights / AI Agents and Automation
AI Agents and Automation
Stateful or Stateless AI Agents? A Product Architecture Decision
Every language model call is stateless; agents only remember what your system stores and sends back. This guide separates the four kinds of agent state, shows when stateless designs are enough, when memory pays off, and how to handle the privacy, cost and correctness risks of agents that remember.
TopicsAI Agents and AutomationAI and Machine LearningArchitecture and Modernization
Key takeaways
- Language models do not remember anything between calls. “State” is what your application stores and chooses to send back.
- Separate four kinds of state: conversation context, task or workflow state, long-term user memory and shared knowledge. Each has different storage, lifetime and privacy needs.
- Stateless agents suit single-shot tasks, high-volume APIs and sensitive data. They are simpler to scale, test and secure.
- Stateful agents suit long conversations, multi-step tasks that pause for people or systems, and personalised experiences.
- Most production systems are hybrid: stateless workers with durable workflow state and carefully scoped memory, all under explicit retention rules.
On this page
- The model is always stateless
- Four kinds of agent state
- When stateless is enough
- When you need state
- Design patterns that work
- Worked example: a B2B procurement assistant
- The cost of carrying state
- Choosing storage
- Privacy, security and correctness risks of memory
- A decision checklist
- Measuring the trade-off
- Frequently asked questions
- Sources and methodology
“Should our agent be stateful or stateless?” sounds like a simple architecture question. In practice it hides several separate decisions: what the agent needs to see during one request, what must survive while a task is in progress, what — if anything — it should remember about a user next week, and who is allowed to see each of those things.
This guide untangles those decisions. If you are still deciding whether you need an agent at all, start with our guide to what AI agents are.
The model is always stateless
A language model call takes input and returns output. It does not retain anything afterwards. When a chatbot appears to remember earlier messages, your application — or the provider’s conversation feature — is storing those messages and sending them back with each new request.
That has two consequences. First, “stateful agent” really means “agent whose surrounding system stores and reuses state”. Second, every piece of state you send back costs tokens and latency, and every piece you store is data you must secure, retain correctly and be able to delete.
Four kinds of agent state
| State | What it holds | Typical lifetime | Typical storage |
|---|---|---|---|
| — | — | — | — |
| Conversation context | Recent messages, tool results and the current goal | Minutes to hours | Session store or cache; summarised as it grows |
| Task or workflow state | Progress through a multi-step task: completed steps, pending approvals, intermediate results | Hours to weeks | Database or durable workflow engine with checkpoints |
| Long-term user memory | Preferences and facts about a user that improve later interactions | Months, subject to retention rules | Profile store or vector store, scoped per user |
| Shared knowledge | Documents, policies and product data available to all users with permission | Long-lived; versioned | Search or retrieval index |
Designing these separately avoids most memory-related bugs and privacy problems.
Shared knowledge is usually provided through retrieval rather than memory, and it is not personal. The other three are where the stateful-versus-stateless decision really lies.
When stateless is enough
A stateless agent receives everything it needs in the request and keeps nothing afterwards. It suits:
- Single-shot tasks: classify a ticket, extract fields from a document, summarise an article, draft a reply from a supplied thread.
- High-volume APIs where any instance can serve any request and horizontal scaling must be simple.
- Sensitive data where retaining inputs creates risk — for example, processing documents that contain personal or health information.
- Deterministic pipelines where reproducibility and testing matter more than personalisation.
Benefits are significant: no session affinity, easier load balancing, simpler failure recovery (just retry), smaller attack surface and straightforward testing with fixed inputs.
The limits appear when tasks span multiple turns or steps. A stateless design either asks the client to send the whole history each time — which moves the burden and the risk to the client — or forces users to repeat themselves.
When you need state
State becomes necessary when:
- Conversations are long or multi-turn, and users expect the agent to follow the thread.
- Tasks pause for human approval, a customer reply, a payment or a slow external system, and must resume exactly where they stopped.
- Personalisation adds clear value, such as remembering a user’s preferred language, product configuration or recurring requests.
- Work is expensive to redo, so losing progress after a crash or deployment would waste time and money.
The costs are real too: storage, more complex scaling, the need to keep state consistent with the systems of record, larger prompts as context grows, and privacy obligations for anything remembered.
Design patterns that work
Stateless workers with durable workflow state
Keep the agent’s reasoning steps stateless, but record task progress in a durable workflow engine or database with checkpoints. Any worker can pick up the next step. This combines easy scaling with reliable resumption, and is the pattern behind frameworks that offer checkpointing and human-in-the-loop pauses.
Rolling summaries for long conversations
Keep the last few turns verbatim and replace older turns with a summary that preserves decisions, facts and open questions. Store the full transcript separately if you need it for audit, not in the prompt.
Explicit, scoped long-term memory
Rather than letting an agent store anything it likes, define what may be remembered — for example, “preferred delivery address label” or “product edition in use” — with a schema, a source and an expiry. Show users what is remembered and let them correct or delete it.
Reference, do not copy
Store references to records in your systems of record (an order ID, a ticket ID) rather than copies of their data. Fetch the current values when needed. This avoids an agent acting on a stale order status or price.
Worked example: a B2B procurement assistant
Consider a hypothetical assistant that helps buyers at business customers reorder supplies, check contract prices and track deliveries.
| Need | State type | Design |
|---|---|---|
| — | — | — |
| Follow a 10-turn conversation about a reorder | Conversation context | Session store; last six turns verbatim plus a rolling summary |
| Wait two days for a manager to approve an order above the buyer’s limit | Workflow state | Durable workflow with a checkpoint; resumes when the approval event arrives |
| Remember the buyer’s usual delivery site and preferred pack sizes | Long-term memory | Structured profile fields with source, last-confirmed date and a 12-month expiry; visible and editable by the buyer |
| Know contract prices and product specifications | Shared knowledge and live data | Retrieved from the catalogue and pricing service on each request; never stored in memory |
| Show what was ordered and approved, by whom | Audit record | Append-only log, separate from working memory |
Each need maps to a different store with its own lifetime and access rules.
The design deliberately keeps prices out of memory. If the assistant “remembered” last month’s contract price, it could quote a figure that has since changed. It also makes the approval pause durable: if the service restarts while waiting, the workflow resumes from its checkpoint rather than asking the buyer to start again.
The cost of carrying state
State has a direct token cost. Suppose each turn adds about 400 tokens of user message and agent response, and the system prompt and tool definitions take 3,000 tokens. Replaying the full history, the twentieth turn sends roughly 3,000 + 19 × 400 = 10,600 tokens of input. Over a 20-turn conversation the input totals around 136,000 tokens. With the last six turns kept verbatim and older turns replaced by a 500-token summary, no turn exceeds about 3,000 + 500 + 6 × 400 = 5,900 tokens, and the conversation total falls to roughly 106,000 — about 22% less input, with a larger saving the longer conversations run. Prompt caching of the stable prefix can reduce cost further. Test summaries against your evaluation set, because a summary that drops a key fact costs more than the tokens it saves.
Choosing storage
| Store | Good for | Watch out for |
|---|---|---|
| — | — | — |
| In-memory cache (for example Redis) | Short-lived session context | Loss on eviction; set time-to-live deliberately |
| Relational database | Workflow state, structured memory, audit logs | Schema changes as memory types evolve |
| Durable workflow engine | Long-running tasks with waits, retries and human steps | Operational overhead; learning curve |
| Vector store | Retrieving relevant unstructured memories or knowledge | Tenant filtering, deletion and stale entries |
| Provider-managed threads | Quick start for conversation history | Data location, retention terms and portability |
Many systems use two or three of these, each for a different kind of state.
Privacy, security and correctness risks of memory
- Cross-user leakage. Memory must be strictly scoped by user and tenant; a retrieval query that forgets the filter can expose another person’s data.
- Retention and deletion. Memory is personal data in many jurisdictions. Apply retention periods and make deletion requests remove it from every store, including caches and vector indexes.
- Poisoned memory. Content from documents or other users can plant false “facts” that the agent later trusts. Only write memory from trusted sources or after confirmation, and record where each memory came from.
- Stale facts. Preferences and circumstances change. Expire memories and prefer live system data for anything transactional.
- Context bloat. Sending all memory with every request raises cost and can distract the model. Retrieve only what is relevant to the current task.
A decision checklist
| Question | If yes |
|---|---|
| — | — |
| Does the task finish within one request? | Start stateless |
| Must work resume after a pause, crash or deployment? | Add durable workflow state with checkpoints |
| Does the conversation exceed a few turns? | Add session context with rolling summaries |
| Would remembering preferences measurably improve outcomes? | Add scoped long-term memory with user controls |
| Does the data include sensitive personal information? | Minimise retention; prefer references over copies; document lawful basis |
| Must decisions be auditable later? | Store an immutable audit log separate from working memory |
Answer each question separately; most products need some, not all, forms of state.
Measuring the trade-off
Before adding memory, measure what it buys. Compare task success rate, number of turns to completion, user satisfaction and cost per completed task with and without each form of state on an evaluation set. Memory that does not improve these metrics is cost and risk without benefit.
Frequently asked questions
Do provider conversation features make our agent stateful?
They store conversation history on the provider side, which is convenient but means your data lives there under their retention terms. Check those terms and whether you can delete conversations on request.
Is a vector database the same as agent memory?
A vector database is one storage option. Memory is the policy about what to store, for whom, for how long and how it is retrieved. Many memories are better stored as structured fields.
Are stateless agents more secure?
They have a smaller attack surface because they keep nothing between requests. Security still depends on how inputs, tools and permissions are handled.
How do we test stateful agents?
Test scenarios end to end, including pauses, resumption after failure, memory updates and deletion, using fixed seed data so results are reproducible.
Sources and methodology
Facts in this article were checked against the sources below on 6 November 2026. Directory data (ratings, review counts, rate bands and team sizes) changes over time and is shown as published on the date accessed. Illustrative examples are labelled as such and are not quotes.
- Anthropic Engineering: Building effective agents (19 December 2024) — accessed 6 November 2026. Augmented LLM with retrieval, tools and memory as the basic building block; workflows versus agents
- OWASP: Top 10 for LLM Applications 2025 — accessed 6 November 2026. LLM02 Sensitive Information Disclosure, LLM04 Data and Model Poisoning, LLM08 Vector and Embedding Weaknesses
Related reading
Continue your research
Deciding what your agent should remember?
Share your use case and data constraints. We will help you design session state, durable workflows and long-term memory that are useful, affordable and compliant.
