Agent memory has three layers: short-term state in the context window, long-term facts and preferences retrieved later, and episodic records of past interactions and their outcomes.
Context window, summaries and durable stores
Short-term memory is the current conversation, bounded by the model's context window. As the window fills, the agent summarizes earlier exchanges to make room, so the relevant details stay reachable.
Long-term memory lives outside the model in a vector database or key-value store. The agent retrieves entries that match the current context, which is how it remembers that a user keeps asking about one product. Libraries such as Mem0 or Zep manage the extraction and retrieval.
Episodic memory logs past interactions and how they ended. An agent that recalls an approach failing before can change its strategy now.
Memory compared with registers, databases and event logs
| Agent layer | Software analogue | Holds |
|---|---|---|
| Short-term | CPU registers | Current context window |
| Long-term | Database | Durable facts and preferences |
| Episodic | Event log | Past interactions and outcomes |
The analogy breaks on fidelity. Writes and reads here are lossy and model-mediated: what gets stored is a summary or an embedding, and details can be lost or misrepresented.
For example, in a customer service session the agent can summarize earlier queries and answers to keep the dialogue smooth, while a long-term entry records which product the user keeps asking about.
Why appending the full history fails
The simple approach appends every previous exchange to the prompt. That fills the context window, degrades attention, and costs more because every token is paid for on each call. The agent can lose the thread of the conversation.
Externalizing memory and retrieving only what is relevant keeps the context lean and lets knowledge outlast a session. It adds its own risk: the retriever can return the wrong memory or miss the right one.
Choosing memory layers for a task
- Single-shot tasks where context does not matter: short-term memory is enough.
- Returning users or personalization: add long-term memory.
- Agents that should learn from past successes and failures: add episodic memory.
- Skip memory infrastructure you do not plan to query. It adds maintenance cost.
Retrieval failure and lost context
Example scenario: context accuracy drops by 75% (an illustrative figure) after memory retrieval starts failing. A likely cause is stale episodic memory, a full store or a bug in the retrieval logic, so the agent never sees critical past interactions.
- Check the memory update logs to confirm recent interactions are recorded.
- Measure the episodic store size against its limits.
- Run test queries for known past interactions and check that the expected results come back.
Fix the retrieval logic and raise the store limit if it is capped, accepting higher memory use. Track user satisfaction and retrieval accuracy to confirm the fix worked.