Zenaique

How is long term memory typically implemented in an agent?

Flashcard·Easy·4.0 · 0·~30s·Asked atFiddler AiRobloxTesla
Attempt it
TL;DR

Long-term memory persists across tasks in a vector store, key-value store, or database. The agent retrieves relevant entries each task and injects them into the prompt; the model weights stay frozen.

Memory aid
Sign in to see the mnemonic that makes this stick.
Easy to grasp

Imagine a friend you only see once a month. They cannot literally remember everything you ever told them, so they keep a small notebook with the important facts: 'allergic to peanuts, has a daughter named Mia, prefers tea to coffee.' Before they meet you again, they flip to your page. Long-term memory works that way for an agent. It cannot keep every conversation alive in its head. So important facts go into a notebook (a database). Before each new task, the agent looks up the relevant page and reads it. The model's brain has not changed at all. The notebook has just grown by a few lines.

Concept explanation~2 min read

Everything you need to truly understand this topic: intuition, mechanics, step by step explanation, code, formulas, and worked example. Click to expand.

Long-term memory is the persistent layer of an agent's memory: the bytes that survive after one task ends and are still available when the next task begins. Where short-term memory is the per-task scratchpad rendered into the prompt, long-term memory is the external store the runtime owns and queries selectively.

The distinction matters because of how the underlying model works. A language model at inference time is frozen. The user can talk to it for hours, and not one weight changes. Short-term memory exists only inside the prompt, and the prompt is rebuilt on each call. So every form of memory the user perceives across days, sessions, or weeks must live somewhere outside the model, in storage the runtime explicitly reads and writes.

This explanation builds up what long-term memory contains, the storage shapes used to implement it, the three operations (write, read, maintain) that govern it, and the production failure modes a serious design has to handle. By the end you should be able to look at any 'the agent remembers me' feature and decompose it into these pieces.

What long-term memory contains and where it lives

Three categories of content account for most production long-term memory.

The first is user profile data: stable facts about the user (name, language, role, preferences, allergies, dietary restrictions, account identifiers, locale). These tend to be small, structured, and updated rarely.

The second is interaction history summaries. A finished task is summarised down to a compact set of facts (the user planned a Tokyo trip arriving 9am Haneda, allergic to peanuts, asked about ramen restaurants) and the summary is persisted. Raw transcripts are usually too large to retrieve efficiently, so the summary is the primary artifact, with the trace remaining available in observability.

The third is learned heuristics or reflections. After repeated failure modes, the agent or a meta-agent writes down lessons like 'when the user says urgent, escalate to overnight shipping' or 'this customer's payment method fails on weekends'. These are the cross-task equivalent of Reflexion-style critiques and are explicitly retrieved when the agent decides what to do next.

Storage choices follow content shape. Free text and summaries go into a vector store for similarity retrieval; common 2026 choices are Pinecone, Chroma, pgvector (used heavily by teams already on Postgres), Weaviate, and Qdrant. Structured profile data goes into a relational or key-value store with exact lookup. Relationships between entities (this user belongs to this team, used these products) fit a graph or document store. Production systems often combine two or three: a relational user table joined with a pgvector table of summaries, queried together at retrieval time.

Three operations: write, read, maintain
How long-term memory reaches the model
Production failure modes and how to design against them
Sign in to unlock the full deep dive.

Situations where this technique stops working.

Sign in to see when this approach fails.

2–4 min · Everything important, quickly.

Sign in to see the quick scan of the deep dive.

Real products, models, and research that use this idea.

  • Personal assistants built on the OpenAI Agents SDK or Anthropic SDK store user-fact summaries in a vector store like Pinecone or Chroma, retrieved on each new session.
  • Coding agents like Cursor and Devin store prior project context and reflections in a per-project memory file or vector index that the agent retrieves on each new session.
Sign in to see more production examples.

What an interviewer would ask next. Try answering before peeking at the approach.

QLong-term memory and RAG both retrieve text and inject it into the prompt. What is the difference?
A

RAG retrieves from a static or shared knowledge base (docs, web pages, manuals) to answer questions. Long-term memory retrieves from a per-user write-back store of past interactions. The mechanics overlap (vector store + retrieval), but the source of the data and the write path differ sharply.

2 more follow-ups an interviewer would ask next. Sign in to reveal them.

Red flags & common mistakes

The phrases that signal junior thinking. Click to expand.

Most common mistake

Believing long-term memory updates the model. The model weights are frozen at inference. Long-term memory is an external store the runtime queries; nothing about the model itself ever changes.

Sign in to see all red flags and common mistakes.

60 second bullets to scan on the way to the call.

  • Define long-term memory as cross-task persistence external to the model.

  • Name the contents: user preferences, prior summaries, learned facts, trajectory reflections.

Sign in to unlock the revision sheet.

Primary sources. Browse if you want the original framing.

Similar questions

Same topic, related formats. Practice these next.

4 curated
Next question
What does RAG primarily help with in LLM based applications?
MCQ·Easy