Agent Memory

An LLM is, fundamentally, stateless — it remembers nothing between calls except what you put in its context window. For an agent that takes many steps or works across many sessions, that's a serious problem: without memory, every step starts from scratch, and nothing is ever learned. Memory is how agents overcome statelessness — holding the context of the current task, and carrying knowledge across tasks and time. Understanding the kinds of agent memory, and their limits, is essential to building agents that can handle real, extended work.

Memory is how agents maintain state — remembering within a task and across tasks. This post covers why memory matters (LLM statelessness), the distinction between short-term and long-term memory, the types of long-term memory, and the practical realities (the context window and its limits). Memory is what lets agents work over many steps and sessions rather than treating each moment in isolation, and it’s a core agent design area.

Why agents need memory

The fundamental reason agents need memory: LLMs are stateless — a model call remembers nothing except what’s in its input (context). For an agent, this is a real limitation:

Agents need memory because LLMs are stateless (remembering only what’s in the current context) — so memory is what provides continuity, both within a task (across the loop’s steps) and across tasks/sessions (over time). Memory overcomes statelessness to let agents do extended, multi-step, and ongoing work. The two kinds of continuity map to two kinds of memory: short-term and long-term.

Short-term vs long-term memory

Agent memory divides into short-term (within-task, the working context) and long-term (across-task, persistent) — a fundamental distinction:

The short-term (working context, transient, in the context window) vs long-term (persistent, external storage, retrieved when relevant) distinction is the foundation of agent memory — analogous to human working vs long-term memory. Short-term makes multi-step tasks coherent; long-term lets agents remember and learn across time. Long-term memory has further useful structure.

Types of long-term memory

Long-term memory is often broken into types (borrowing from cognitive science), each serving a different role — a useful framing for designing agent memory:

The types of long-term memory — episodic (past experiences), semantic (facts/knowledge), and procedural (how-to) — provide a useful structure for what an agent should remember, and they’re typically implemented via retrieval over external storage (vector stores, like RAG) that brings relevant memories into the context. This structure helps design what an agent persists and recalls. But all memory ultimately funnels through one constraint: the context window.

The context window and its limits

A crucial practical reality shapes all agent memory: the context window — the LLM’s finite input — is limited, and managing it is central to agent memory:

Agent memory overcomes LLM statelessness to provide continuity — short-term (working context, transient) for within-task coherence, and long-term (persistent external storage, retrieved when relevant, in episodic/semantic/procedural types) for across-task knowledge — all constrained by the finite context window, which makes context management central. Memory is what lets agents do extended and ongoing work. Next: reflection and self-correction — how agents evaluate and improve their own work.

Key takeaways

Further reading

Sources & References

Retrieval behind long-term memory