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.

🪟Contextbufferthis chat📝Rollingsummarylong chats🧲Vectormemoryrecall bymeaning🕸️Graphmemoryfacts thatchange📁Filememorylasting rules
Five places an agent can keep memory, from minutes to the whole project. Store each fact in the cheapest place that still works.
Memory typeUse it forLastsTrade-offExamples
1. Context bufferKeeping the last few turns of the current chatMinutes (this session only)Gone when the session ends; long chats cost more tokensLast-N-turns, LangGraph threads
2. Rolling summaryVery long chats: old turns are squeezed into a short summaryHoursDetails can be lost when text is summarisedChat compaction in coding tools
3. Vector memoryRecalling past notes by meaning ("what did she say about budget?")Weeks to monthsSimilar-but-wrong or outdated notes can resurfaceMem0, pgvector, Pinecone
4. Knowledge graphFacts that change and relationships ("who is Priya's manager now?")Months to yearsExtracting facts costs extra calls and needs graph toolsZep / Graphiti, Neo4j
5. File memoryLasting rules, conventions and decisions written as plain textThe whole projectMust be kept short and edited by handCLAUDE.md, AGENTS.md, a memory/ folder

The memory loop

  1. Route: decide what is worth keeping and how long it must last.
  2. Retrieve: fetch only what's relevant to this turn.
  3. Inject: put it into the prompt, then the agent acts.
  4. 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 min

Design an agent's memory

  1. Imagine a personal fitness-coach agent.
  2. List 8 things it should remember, e.g. today's workout, your injuries, your goal weight, your trainer's name.
  3. 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.

Build it for real · guided projectBuild a document Q&A assistant (RAG, no code)About 60 min · No coding needed · step by step
Test what you learned

Take a quick quiz, or look up any word in the glossary.