In this article
  1. Before you start
  2. Why interviewers ask this
  3. Long-term memory from first principles
  4. The Staff-level answer
  5. The rubric
  6. Three variants of this question
  7. Common mistakes
  8. Follow-up questions
  9. Sources

Before you start

This page is part of the AI agent architecture learning path and builds on prompt engineering.

Why interviewers ask this

A candidate who answers "use a vector database" has named one tool, not a design. The question separates people who can list storage options from people who can say what is stored, when it is written, how it is recalled and what happens when the window is full.

A weak answer equates memory with a larger context window, or with retrieval-augmented generation alone. A strong answer names the memory types, gives at least two storage strategies, and says that recall must be ranked because only a few memories fit in the prompt. A Staff-level answer adds write timing, staleness and deletion, and how you would test the memory.

The question comes up in agent design rounds; see the agentic AI interview questions for its neighbours and how to design an AI agent system for the full loop.

Long-term memory from first principles

Long-term memory
Long-term memory is a store outside the model's context window that lets an agent keep information across conversations or sessions. The model reads it back only when something loads it into the prompt, so the memory lives in your system, not inside the model.
Namespace
A namespace is a label or path, such as one per user, under which memories are saved so that searches stay inside one scope and one user's memories never mix with another's. LangChain's documentation saves long-term memories in custom namespaces, kept apart from thread-scoped short-term memory.
Reflection
A reflection is a higher-level memory an agent writes by synthesizing many lower-level memories, then stores and retrieves like any other memory. It turns a pile of events into one insight that later retrieval can rank. The term comes from Park et al. (2023).

In plain words

Think of a desk and a filing cabinet. The desk is the context window: everything on it is visible at once, but it is small. The filing cabinet is long-term memory: large and durable, but you must walk over, pick a folder and put it on the desk. The analogy breaks in one place. A person remembers on their own, while a model is stateless: it sees only what your code places in the prompt.

In one precise sentence, long-term memory is a store plus read and write operations that decide what moves between the store and the context window. The LangChain documentation contrasts it with short-term memory, which is scoped to one thread, a single conversation.

Step 1: Decide what kind of memory you are storing

Memory types decide the storage form, so the first step is to classify what the agent must remember. LangChain's documentation borrows three types from human memory. Semantic memory is facts, such as facts about a user. Episodic memory is experiences, such as past agent actions. Procedural memory is rules and instructions, such as the agent's system prompt.

Each type has a common form. The DeepLearning.AI course on long-term agentic memory uses episodic memory as few-shot examples, procedural memory as system prompts improved with feedback, and semantic memory as facts saved in a store and searched later. Retrieval-augmented generation (RAG) is a pattern that retrieves relevant text from a store and adds it to the prompt; it is one common way to implement semantic memory. So RAG is one implementation of one memory type, not the whole answer. You now know what to store; next is how to get the right piece back.

Step 2: Retrieval ranks memories instead of dumping them all

Recall must be ranked, because only the top-ranked memories that fit the context window go into the prompt (Park et al., 2023). Their agents score every memory as a weighted sum of three parts: recency, importance and relevance, with every weight set to 1. Recency decays exponentially with a factor of 0.995 per game hour since the memory was last retrieved. Importance is a rating the language model gives. Relevance is cosine similarity, a measure of how closely two embedding lists point the same way, between the memory and the current query. The paper min-max scales each part to between 0 and 1; the example below uses simple scaling for readability, and the ranking is the same either way.

Worked scoring of three memories

Here is an illustrative example of three memories and the query "recommend dinner plans for my Berlin trip".1 Importance ratings on the paper's 1 to 10 scale are 9, 8 and 2, divided by ten, and the cosine values are made up.

In this illustrative example the flight-date memory ranks first with 2.5267, even though the train-times memory is the most recent.
MemoryHours since accessRecencyImportanceRelevanceTotal
Flight to Berlin on a set date240.88670.90.742.5267
User is vegetarian1000.60580.80.822.2258
Asked about train times20.99000.20.311.5

Here the flight-date memory ranks first at 2.5267, even though the train-times memory is the most recent one. Recency alone would rank the train-times memory first, since 0.995 to the power 2 is 0.9900. The total puts it last. With room for two memories, the flight and the diet go into the prompt and the train times stay in the store.1

Importance and relevance outrank recency in the example rankingBar chart of the illustrative total retrieval score of three memories: flight date 2.5267, vegetarian 2.2258 and train times 1.5, although train times is the most recent.Total score (score)0123Flight dateVegetarianTrain timesMemory2.52672.22581.5Diagram: Interview Clozo, CC BY 4.0 ·interview.clozo.ai/blog/what-different-strategies-could-you-use-for-long-term-memory.html
Importance and relevance lift older memories above a recent but trivial one.CC BY 4.0 — source: What different strategies could you use for long-term memory?
Text description of the diagram
  • In this illustrative example the flight-date memory ranks first with 2.5267, even though the train-times memory is the most recent.
  • With room for two memories, the flight and the diet go into the prompt and the train times stay in the store.

Stuffing everything into the window is not free either; the context rot page explains why more text can make answers worse. You now know that recall is a ranking problem.

Step 3: Choose where memories live and when they are written

Two storage strategies are common. The first is a store with search. LangGraph stores long-term memories as JavaScript Object Notation (JSON) documents, where JavaScript Object Notation (JSON) is a plain text format for structured data, under a namespace such as one per user, and the agent searches them later.

The second is file-based memory. In the Anthropic memory tool, Claude creates, reads, updates and deletes files in a memory directory. The tool is client-side: Claude requests a file operation and your application runs it. The /memories path is a prefix your handler maps onto real storage, such as a per-user directory or database keys, and the documentation says to restrict operations to that directory for security.

Semantic memory itself can take two shapes, as LangChain's documentation describes. A profile is one continuously updated document per user: easy to load, but each update needs a careful merge so new facts do not overwrite good ones. A collection is a growing set of small memories: easy to append to, but it needs search, deduplication and conflict resolution.

Writing is a separate choice. LangChain's memory documentation describes two ways to write memories: writing during the conversation, called the hot path, and writing in the background, after it. A reasonable design rule, offered as advice rather than a sourced finding: write urgent facts on the hot path and heavier summarizing in the background, so replies are not slowed by memory work.

Step 4: Page memory in and out, and reflect on it

Two further strategies manage scale. The first is self-managed tiers. In MemGPT, the context window acts as fast main memory and external storage as slow memory. The model uses function calls to read and write external data, retrieve relevant historical data and evict less relevant data from context. This gives the appearance of large memory; it does not enlarge the window.

The second is a memory stream with reflection. Park et al. (2023) store a complete record of the agent's experiences in natural language, synthesize them over time into reflections, and retrieve them dynamically to plan behavior. Reflection compresses many events into one lasting insight, so retrieval has fewer, richer items to rank.

The four strategies differ in who manages memory and in what each one risks.
StrategyWho decides what is savedStorageMain risk
Store plus searchYour code or the modelDocuments under a namespaceWeak ranking returns wrong memories; a profile needs careful merges, a collection needs deduplication and conflict resolution
Memory filesThe model, through file toolsA directory you controlMessy files and unsafe paths
Memory tiers (MemGPT)The model, through function callsContext plus external storagePoor eviction choices
Memory stream with reflectionScoring rules and reflectionFull experience logCost of scoring and summarizing
A memory design stacks four choices from what to remember to scaleLayer stack of four design choices for agent long-term memory: what to remember, how to recall it, where it lives, and how it scales with paging and reflection.What to remembersemantic, episodic, proceduralType sets the formHow to recall itrecency, importance, relevanceOnly the top fitWhere it livesstore or memory filesYour app owns itHow it scalespaging and reflectionWindow stays fixedDiagram: Interview Clozo, CC BY 4.0 ·interview.clozo.ai/blog/what-different-strategies-could-you-use-for-long-term-memory.html

A memory design is four choices stacked: what to remember, how to recall it, where it lives and how it scales.CC BY 4.0 — source: What different strategies could you use for long-term memory?
Step-by-step description
  1. Facts, experiences or rules.
  2. Rank, then load the top few.
  3. A store or memory files.
  4. Paging and reflection.
  • Four layers: what to remember, how to recall it, where it lives, how it scales.
  • Only the top-ranked memories that fit the context window go into the prompt.

Four layers: what to remember, how to recall it, where it lives, how it scales. The context-folding page covers a related way to keep long tasks inside the window.

Knowing it is half the job. Saying it is the other half.

Interview Clozo is an AI interview copilot for real interview rounds: it hears the question and puts a strong answer on your screen, and you say it in your own words. See the features or how it works.

Start Free Trial →

The Staff-level answer

Interviewer asks

What different strategies could you use for long-term memory?

A strong answer

I start from what the agent must remember. Facts about a user go in a semantic store, saved as documents under a per-user namespace and found by embedding similarity. Past experiences become episodic memory, often few-shot examples. Standing rules live in the system prompt as procedural memory. I never load everything: I rank by recency, importance and relevance and keep only what fits the window. For long tasks I add memory files the model edits, or MemGPT-style paging, and I write in the background when latency matters. What breaks is staleness or a wrong memory being retrieved, so newer facts update or delete older ones.

What makes it Staff-level: it ties each strategy to a memory type, names the ranking step that protects the window, and says when writes happen.

The rubric

A strong answer names types and storage, and a Staff answer adds ranking, write timing and failure handling.
DimensionWeak answerStrong answerStaff answer
Correctness"Use a bigger context window."Stores memory outside the window and loads it back.Also says the model is stateless; the application owns memory.
DepthNames only a vector database.Names semantic, episodic and procedural memory.Maps each type to a form: store, examples, prompt.
Trade-offsNone given.Notes that retrieval must be selective.Ranks by recency, importance and relevance; discusses write timing.
Follow-up readinessStalls on "what if it is wrong?"Mentions updating or deleting memories.Covers staleness, privacy and how to test recall.

Three variants of this question

How would you give a chatbot memory of a user across sessions?

Save facts about the user under a per-user namespace, search them at the start of each session, and load the top few into the prompt. The model forgets between calls, so the store carries the continuity.

What is the difference between semantic, episodic and procedural memory?

Semantic memory holds facts, episodic memory holds past experiences or actions, and procedural memory holds rules, such as the system prompt. The names come from human memory as used in LangChain's documentation.

What if the memory store grows large or goes stale?

Rank so only a few memories enter the prompt, write reflections that compress many events into one, and update or delete entries that are wrong. Memory files make deletion simple because the model can edit or remove a file.

Common mistakes

  • "A bigger context window is long-term memory." (wrong) The window is working memory that vanishes after the call. (right) "Long-term memory persists in storage and is loaded into the window when needed."
  • "The model remembers the user." (wrong) The model is stateless. (right) "My application stores memories and decides what to load; in Anthropic's memory tool Claude only requests the file operations."
  • "Long-term memory means RAG." (wrong) RAG covers semantic memory only. (right) "RAG is one way to implement semantic memory; episodic memory can be few-shot examples and procedural memory a system prompt."
  • "Store everything and retrieve everything." (wrong) Only a subset fits the window. (right) "I rank memories and load the top ones that fit."
  • "MemGPT makes the window bigger." (wrong) The window stays fixed. (right) "It pages information in and out so the window looks larger."

Follow-up questions

Is long-term memory the same as a bigger context window?

No. A window holds what the model reads in one call, while long-term memory is storage that survives across sessions. Even with a big window, you still choose what to load; see why agents fail on long tasks.

Is long-term memory the same as RAG?

No. RAG is a way to implement semantic memory by retrieving text from a store by similarity. Episodic and procedural memory take other forms, such as few-shot examples and prompt rules.

Should the agent write memories during the conversation or afterward?

Both exist, according to LangChain's memory documentation: the hot path writes during the conversation and a background process writes afterward. As a design choice, write urgent facts immediately and do heavier summarizing later so replies stay quick.

How do you stop stale or wrong memories from hurting answers?

Give each memory a time and a source, let newer facts update or delete older ones, and keep recency in the ranking score. Treat this as a design practice and test it.

How would you test an agent's memory?

Plant a fact in one session, ask for it in a later session, and check both the answer and which memories were retrieved. The agent evaluation page covers trajectories and reliability.

Key takeaways
  • Long-term memory is storage outside the context window that persists across sessions; the model itself stays stateless.
  • Match form to type: semantic facts in a store, episodic examples as few-shot examples, procedural rules in the system prompt.
  • Four strategies: a searchable store, memory files, MemGPT-style tiers, and a scored stream with reflection.
  • Recall is a ranking problem: score recency, importance and relevance, and load only what fits.
  • RAG is one implementation of semantic memory, not the whole of long-term memory.

Sources

  1. Memory overview (LangGraph concepts) — LangChain Docs (read 2026-10-26; page undated), 26 Oct 2026
  2. MemGPT: Towards LLMs as Operating Systems (arXiv 2310.08560 v2) — arXiv (Packer et al.), 12 Feb 2024
  3. Generative Agents: Interactive Simulacra of Human Behavior (arXiv 2304.03442) — arXiv (Park et al.), 7 Apr 2023
  4. Memory tool — Claude Platform Docs, Anthropic (read 2026-10-26; page undated), 26 Oct 2026
  5. Long-Term Agentic Memory With LangGraph — DeepLearning.AI (read 2026-10-26; page undated), 26 Oct 2026