KatInterview

Designing a Layered Memory System for a Long-Lived LLM Agent

Machine LearningModel answer
MediumModel answerMachine Learningllm-agentsmemoryretrieval

Last updated

Describe the layers of memory in a persistent LLM agent, what each holds, how it is written and read, and how the layers are managed, secured and evaluated across many sessions.

You are building an assistant that runs for months and talks to each user across many separate sessions. The model itself is stateless, so everything it "remembers" must be supplied by the surrounding system.

Question: Lay out the main components of such an agent's memory. For each component, explain:

  1. What kind of information it holds and how long it lives.
  2. How information gets written into it.
  3. How information is read back out and placed in front of the model.
  4. How the components cooperate over the agent's lifetime.

Also address how the memory stays healthy over time (merging, correcting and forgetting), how it is kept private and safe from tampering, and how you would tell whether it actually improves the agent.

Before answering, it is reasonable to state your assumptions about:

  • Whether the agent serves one user or many, and whether their memories must stay separate.
  • How long sessions are compared with the model's context window.
  • Whether memory exists to personalize responses, to improve task success, or both.
  • Whether users must be able to inspect or delete what is stored.

Hints

Hint 1

Start by splitting memory by lifetime: what lives only for one model call, what lives for one session, and what must survive across sessions. Then split long-term memory by content type (events, facts, skills).

Hint 2

For every layer, write down three policies: when to write, how to retrieve (recency, similarity, structured lookup, or always-on), and when to update or delete. Retrieval must respect a token budget.

Hint 3

Don't stop at the taxonomy. Cover contradictory facts, forgetting, per-user isolation, prompt-injection or poisoned memories, user deletion, and an ablation-style evaluation of memory on versus off.