How is long-term memory typically implemented in an agent?
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.
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.
Detailed answer & concept explanation~8 min readEverything you need to truly understand this topic: intuition, mechanics, step by step explanation, code, formulas, and worked example. Click to expand.
Everything you need to truly understand this topic: intuition, mechanics, step by step explanation, code, formulas, and worked example. Click to expand.
Everything you need to truly understand this topic: intuition, mechanics, step by step explanation, code, formulas, and worked example.
Everything important, quickly.
Define long-term memory as cross-task persistence external to the model. Name the contents and the contrast with short-term memory and weights. Describe the storage shapes (vector store, key-value, relational) and when each fits. Walk through the three operations (write, read, maintain). Close on multi-tenant scoping and aging as load-bearing production concerns.
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.
- Enterprise support agents often combine pgvector for semantic memory with a relational user table for structured profile data, joined at retrieval time.
- LangGraph supports checkpointed long-term memory through its store interface, with implementations for pgvector, Postgres, and Redis.
- LlamaIndex offers built-in memory modules that bridge a vector index (the long-term memory) with the live chat session (the short-term memory).
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?
QWhat goes wrong when long-term memory has no aging or contradiction-handling policy?
Don't say thisRed flags and common mistakes that signal junior thinking. Click to expand.
Red flags and common mistakes that signal junior thinking. Click to expand.
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.
The night-before-the-interview bullets. Scan these on the way to the call.
Primary sources. Skim if you want the original framing.
Same topic, related formats. Practice these next.