Choosing the right memory for an AI agent: 5 options
An agent can keep what it learns in five different places, from "just this chat" to "the whole project". Each has a cost. The rule of thumb: store each fact in the cheapest place that can still recall it when needed, and keep memory short, factual and up to date.
Everyday analogy
Your own ways of remembering: holding a phone number in your head for a minute (context buffer), writing meeting minutes (rolling summary), a box of notes you search by topic (vector memory), an organisation chart that shows who reports to whom (knowledge graph), and the team handbook pinned on the wall (file memory).
Example
A study-buddy agent keeps today's chat in its context buffer, summarises last week's sessions into a short note, searches past notes when you ask "what did we say about tokens?", tracks that Priya now mentors Sam in a small graph, and reads a study-rules.md file at the start of every session.
| Memory type | Use it for | Lasts | Trade-off | Examples |
|---|---|---|---|---|
| 1. Context buffer | Keeping the last few turns of the current chat | Minutes (this session only) | Gone when the session ends; long chats cost more tokens | Last-N-turns, LangGraph threads |
| 2. Rolling summary | Very long chats: old turns are squeezed into a short summary | Hours | Details can be lost when text is summarised | Chat compaction in coding tools |
| 3. Vector memory | Recalling past notes by meaning ("what did she say about budget?") | Weeks to months | Similar-but-wrong or outdated notes can resurface | Mem0, pgvector, Pinecone |
| 4. Knowledge graph | Facts that change and relationships ("who is Priya's manager now?") | Months to years | Extracting facts costs extra calls and needs graph tools | Zep / Graphiti, Neo4j |
| 5. File memory | Lasting rules, conventions and decisions written as plain text | The whole project | Must be kept short and edited by hand | CLAUDE.md, AGENTS.md, a memory/ folder |
The memory loop
- Route: decide what is worth keeping and how long it must last.
- Retrieve: fetch only what's relevant to this turn.
- Inject: put it into the prompt, then the agent acts.
- Write back: save new facts, remove duplicates and expire old ones.
Start simple: every agent needs 1 (context buffer) and 2 (summary). Add 5 (a file) for lasting rules. Add 3 (vectors) only when fuzzy recall fails, and 4 (a graph) when relationships change over time. And always ask: are we allowed to keep this? Personal data needs consent and a way to delete it.
Try it yourself
About 15 minDesign an agent's memory
- Imagine a personal fitness-coach agent.
- List 8 things it should remember, e.g. today's workout, your injuries, your goal weight, your trainer's name.
- For each, choose one of the 5 memory types and how long to keep it.
What you should see: Only a few facts need long-term memory; most belong in the chat or a short summary.
Use any free AI chatbot (ChatGPT, Claude, Gemini or Copilot). Never paste private or confidential information.