← govind p lal
AI and ML Bootcamp · Lecture 19 · lecture notes

Memory for Agents

In short — What is memory for an LLM agent, and how is it different from RAG? The lecture compares how Claude Code, Codex, Letta, Mem0 and Supermemory design memory. It covers the failure modes of simple file memory, time and forgetting, why current memory benchmarks mostly test retrieval, and why voice agents make memory hard.

What memory is, and how it differs from RAG

builds on Lecture 10: Week 9 - AI&ML | RAG from the Ground Up - Part 1 | 13/03/2026, Lecture 10: Week 9 - AI&ML | RAG from the Ground Up - Part 1 | 13/03/2026

Memory - an agent's ability to use facts gathered over earlier turns with a user, and to reason about how they changed.

Example

Project starts in PyTorch (March). Switch to JAX (April). Debugging pain, back to PyTorch (May). Ask the agent "which framework should I use?" The right answer is PyTorch, and JAX already failed. Detecting this -> Memory.

RAGMemory (state over time)
StorageConversations embedded in a vector DBFacts stored as state with time order
QueryTop-k similarity searchLatest state is the present truth
On the exampleTop hit is "started with PyTorch". Answer ignores JAX.March PyTorch, April JAX, May PyTorch. Answer is PyTorch.
EmbeddingsNeeded, and must be debuggedNot needed

Two problems overlap here. What do I know about this project? What do I remember about this user? The boundary between them is fuzzy. That is why memory is hard.

Human memory pipeline

TypeHoldsExample
EpisodicEventsWhat did I eat for lunch? Trip to Goa last summer
SemanticFacts, constantsValue of pi is 3.14
ProceduralSkillsRiding a bicycle, typing fast
reinforcedInput streamSensory filterdrops most noiseShort-term / workingLong-termepisodic, semantic,…
Human memory pipeline.

File-based memory in Claude Code, Codex and Hermes-style agents

Simple, yet it runs at huge production scale.

Failure modes of file memory

builds on Lecture 10: Week 9 - AI&ML | RAG from the Ground Up - Part 1 | 13/03/2026

Reasons to fail

Letta (MemGPT): the LLM manages its own memory

builds on Lecture 9: Week 8 - AI&ML | From APIs to Agents | 07/03/2026

Idea from operating systems: active data stays in RAM, idle data goes to disk. Map RAM -> context window, disk -> external storage. The LLM gets functions to evict from or load into the context.

Letta is the startup from the MemGPT researchers. It is the most opinionated design. The whole agent runtime is built on Letta. The underlying model must be smart enough to manage memory.

Mem0: a separate memory service

each turnadd/update/delete/noopfacts in next turnAgent conversationMemory service LLMMem0Fact store
Mem0 works beside the agent without touching it.

"I moved to Bangalore": the service finds the existing Delhi memory and updates it, instead of adding a second one. The cost: the old value is gone. Mem0 is open source.

Graph memory (Supermemory)

builds on Lecture 11: Week 10 - AI&ML | RAG Continuation - Part 2 | 23/03/2026

The Problem

After Mem0 overwrites Delhi with Bangalore, "where did I live last summer?" is unanswerable.

The Solution

Time and forgetting

Example

Joined Anthropic in January, left in October to start own lab. "Where did the user work last spring?" A relationship alone cannot answer.

Forgetting

"Explain transformer attention" asked before finals is stale six months later. It should not surface as a study habit.

Memory benchmarks test retrieval, not memory

builds on Lecture 11: Week 10 - AI&ML | RAG Continuation - Part 2 | 23/03/2026

Mem0, Zep and Supermemory each report 91-97% on LoCoMo, LongMemEval or ConvoMem. These give a very long conversation (e.g. 1M tokens), then ask questions.

The Problem

The Solution

Ingest conversationWrite scratchpadagent's own notesFreeze + removetranscriptAnswer from notesonly
One-pass ingestion with a frozen scratchpad.

The agent can take time to memorize. When it starts answering, it can only read what it wrote. This tests real memory. No proper memory evaluation exists yet.

Claude Code vs Codex memory architecture

ChatGPT: one memory file about the user, a markdown file per project, and summaries of roughly the last 15 chats, all loaded at the start of every chat.

Memory for voice agents

Speech to textMemory retrieval~100 ms budgetLLM responseText to speech
Voice round trip.

Chat tolerates a one-second lookup. Voice does not. One network call can eat the budget. A simple vector DB search takes about 80 ms.

!

No single correct memory solution exists. Pick the framework whose opinion fits: LLM self-managed (Letta), separate service (Mem0), graph across many sources (Supermemory).

Glossary

Memory
Tracking facts over time so the agent uses the current state, not just the most similar text.
Mem0
Separate background service that adds, updates, deletes or ignores facts after each turn.
Memory decay
Lowering a memory's weight over time instead of deleting it.