Agent Memory —
Context, Short‑Term,
Long‑Term
The context window is RAM. Vector stores are disk. Episodic memory is the event log. Understanding the stack is the prerequisite for everything else.
When you interact with an AI agent — the kind that can book your flights, write code, or manage a research pipeline — it's doing something that looks like thinking. But underneath, it's doing something more mechanical: deciding what to keep in mind, what to look up, and what to throw away. That decision is memory management. It's the foundation of everything else.
An agent's most fundamental memory is its context window — the desk where everything currently in play lives. Your question, the conversation history, the tools it can use, the instructions it was given. It's finite: frontier models range from 128k to over a million tokens. That sounds enormous, but when documents load in, tool results accumulate, and intermediate outputs multiply, the desk fills fast.
The context window is RAM. Fast, immediately accessible, but volatile. When the session ends, it's gone. This is why short-term memory management matters.
Short-term memory is the structured information the agent keeps within a single session. Good architectures summarize completed sub-tasks, compress redundant information, and track decisions to avoid re-deriving them. Some systems use a scratchpad — a dedicated context section where the agent writes intermediate reasoning. This is the philosophy behind ReAct (Reason + Act): reason, act, observe the result, update, reason again.
But short-term memory alone makes an agent amnesiac. Every new session starts from zero. That's fine for simple tasks. It's catastrophic for anything continuous — a research assistant that forgets yesterday's findings, a customer service agent that doesn't remember you called last week.
Long-term memory lives outside the model itself: vector databases (Pinecone, Weaviate, MongoDB Atlas), relational stores, graph databases. Vector databases are especially suited to semantic memory. You embed a piece of information as a high-dimensional vector. When the agent needs relevant information, it embeds the query and finds the closest matches — retrieval by meaning, not by keyword. This is the retrieval mechanism behind RAG.
Design around retrieval, not storage. For every piece of information stored, ask: what's the retrieval key? When will I want this back? A fact stored without a clear retrieval path is effectively lost.
What belongs in long-term memory? Three categories: facts and knowledge (domain, product, user context), procedural memory (how to do things — successful patterns, tool call sequences), and episodic memory (what happened — summaries of past interactions, errors, decisions). All three serve different retrieval patterns and should be stored accordingly.
The cognitive science distinction between semantic memory (facts without context: water boils at 100°C) and episodic memory (events with context: last Thursday's API failure and how we resolved it) is not academic — they're stored differently, retrieved differently, and confusing them is a common failure mode in agent design.
A numerical representation of meaning in high-dimensional space. Semantically similar items cluster together, enabling retrieval by meaning rather than keyword match.
Retrieval-Augmented Generation. The pattern of fetching relevant documents from a store at query time and injecting them into the context before generation.
Reason + Act. A prompting strategy where the agent alternates between explicit reasoning steps and tool/action calls, updating its scratchpad after each observation.