Agent infrastructure
Agents in production
Stateful vs stateless AI agents: how each architecture works, where session state should live, and which one fits production agent workloads.

Every agent project hits the same architectural fork inside the first month. The agent works fine for one turn, then a second turn arrives that depends on the first, and the team has to decide where memory lives. Do you carry state inside the agent's process, or do you rebuild context on every call?
This comparison is for engineering and AI leads who are past the demo and staring at a real deployment. The short version: stateless agents win on scale, recovery, and horizontal deployment. Stateful agents win on latency, coherence across long tasks, and any workflow where the model needs to reason about what it just did. Most production systems end up hybrid — the question is which side of the line each part of your workflow lives on.
A stateful agent holds session context in memory between turns. The conversation history, tool call results, intermediate reasoning, and any working variables sit inside the agent process — or in a session store keyed to that process. When the next request comes in, the agent already knows what it did last time. Nothing needs to be rehydrated from disk or replayed from a log.
The classic stateful agent architecture pins a session to a worker. The router sends every request for session X to the same process, which keeps the context object alive across turns. Frameworks like LangGraph (with its checkpointers and threads) support this pattern directly, and platform runtimes like AWS Bedrock AgentCore provide managed session state so the team doesn't build the pinning layer themselves. The trade-off is real: the worker holding the session can't be replaced without losing what it knows, and the router has to route consistently, which limits how you scale and how you recover from failure.
A stateless agent carries nothing between invocations. Every request arrives with the full context it needs — conversation history, tool results, user identity, whatever the model needs to reason. The agent processes the request, returns a response, and forgets everything. State lives outside the agent: in a database, a session store, or the client's own message history.
This is the same model that made REST scale on the web. Any worker can handle any request, because no worker knows anything the others don't. Horizontal scaling is a load balancer decision, not an architectural one. Recovery is trivial — a crashed worker gets replaced and nothing is lost, because nothing was held. The cost is that every turn carries the full context on the wire and through the model, which makes long conversations expensive and slow. Agents built on OpenAI's Chat Completions or Anthropic's Messages API default to this pattern with client-managed history. The provider landscape has since split: OpenAI's newer Responses API is stateful by design, hosting conversation state server-side via previous_response_id and the Conversations API, while Anthropic offers a Memory Tool primitive and SDK-level session store hooks that expect the developer to supply the backing storage.
Stateful architecture wins when the cost of rebuilding context is higher than the cost of pinning sessions. Three situations qualify.
Long multi-turn tasks with dense working memory. Coding agents, research agents, and any workflow where the model builds up intermediate artefacts (drafts, plans, partial results) benefit from holding those artefacts in-process. Serialising a 40-turn conversation with tool outputs into every subsequent call gets expensive fast — both in latency and tokens.
Latency-sensitive interactive workflows. If the user is waiting for a response and every turn adds 200ms of context reassembly, statefulness pays for itself. This is the case for voice agents, live copilots, and anything embedded in a UI where the user expects sub-second response.
Workflows where the agent needs to reason about its own history. Reflection, planning, and self-correction patterns work better when the previous reasoning is a first-class object in memory, not a serialised blob to be re-parsed. Our own context window management guide covers the trade-offs when the working set gets large.
The cost is operational. You need session affinity in the router, a strategy for when workers die, and a plan for scaling that respects the pinning. Managed runtimes handle most of this, but if you're rolling your own, budget for it.
Stateless architecture wins when scale, reliability, and simplicity matter more than per-turn latency. This is most production systems.
High-concurrency workloads. If you're running thousands of concurrent sessions across a fleet, statelessness lets you scale workers linearly. No routing complexity, no session drain during deploys, no cold-start problem when a worker dies. This is why most public agent APIs are stateless underneath.
Short-lived task-oriented workflows. A tool call, a form filled, a query answered — anything that completes in one or two turns doesn't benefit from held state, and pays no penalty for statelessness. This describes most agent tool calls in production SaaS.
Systems that need deterministic replay. If every request is fully specified by its inputs, you can replay any interaction from logs, which makes debugging and agent evals enormously easier. Stateful agents make this harder — the state that produced a bug is often gone by the time you go looking for it.
Anywhere identity matters per-call. When each agent action needs to execute as the authenticated user — with fresh token validation, current permissions, and per-call audit — statelessness aligns with the security model. A held session that outlives a permission change is a security problem, not a feature. We covered this trade-off in agent identity vs user identity.
The honest answer for most production systems is neither pure stateful nor pure stateless — it's stateless agents talking to stateful stores. The agent process holds nothing. Every request arrives with a session ID. The agent fetches whatever context it needs from a session store, does its work, writes back what should persist, and returns.
This pattern gets you the scalability and recovery properties of statelessness with the coherence properties of statefulness. The agent workers are cattle, not pets. The session store is the thing that scales differently — it's a database problem, and databases are a solved category. Deploys don't drain sessions. Failures don't lose state.
The cost is that every turn does read and write I/O against the session store, which adds latency the pure stateful pattern doesn't have. For most workflows, the trade is worth it. For the ones where it isn't (voice, live copilots), the stateful pattern still holds.
The state question is really a runtime question. Wherever state lives — in the process, in a session store, or reconstructed per call — the agent still needs to reach the product it's acting on, and it needs to reach it as the authenticated user with the current permissions. That's the part most teams underestimate.
Pontil is a Tools-as-a-Service platform. We sit in the tools layer of the agent stack, generating and running the connectors that let agents act on the products behind them. Our runtime executes every tool call as the authenticated user — not a shared service account — which means the identity and permission model works the same whether your agent architecture is stateful, stateless, or hybrid. You can pick the state pattern that fits your workload without giving up per-user audit trails or token lifecycle handling. If your agent project has stalled on the access side rather than the memory side, that's the layer we solve.
Default to stateless agents with an external session store. Get the scaling, recovery, and debugging properties for free. Move to stateful only for the specific workflows that need it — long interactive sessions, latency-critical UIs, reflection-heavy reasoning — and be honest that you're taking on operational cost to get the latency win.
The variable that determines the answer is turn depth. Short interactions (one to three turns) don't justify the operational cost of session affinity. Long interactions (twenty-plus turns with dense working memory) do. Most production agent systems have both, which is why the hybrid pattern keeps winning — stateless agents doing the work, a stateful store holding what needs to survive between turns. Pick the pattern per workflow, not per company.
Stay up to date on the ever changing agentic landscape.