Modules 4 and 7 treated context management as a problem inside one session: the context grows, fills, and has to be trimmed or compacted. This module turns to a different problem. When a session ends, everything in its context is gone. An agent that a person returns to day after day needs some way to carry knowledge from one session to the next. That durable store is called memory. This lecture defines memory, separates it from context, names the main kinds of memory, and builds the simplest working form: a notes file the agent reads and writes.
A single LLM call is one transaction. The model receives one input and returns one response. A session groups many such calls: an agent loop sends the user's messages and the model's replies back to the model, turn after turn, usually on one topic. A chat window in a consumer app is a session. Keeping a session to one topic keeps its context coherent.
Persistent agents work across many sessions. A person might talk to the same agent several times a day, every day for a month, through chat or through some other workflow. Each of those conversations is a new session with a new context window, and the model sees only what is in that window. Nothing from yesterday's session is there unless something puts it there.
This gives an agent two separate ways to lose what it knew:
Memory addresses the second problem.
Context and memory differ on every axis that matters:
| Context | Memory | |
|---|---|---|
| Lifespan | One session | Across sessions |
| Location | In every API call | On disk, outside the prompt |
| Cost | Every token, every call | Only the parts injected into context |
| Managed by | Truncation and compaction | Curation |
| Failure mode | Fills up and rots | Grows and goes stale |
Context is the working set for one session. Memory is a durable store, and its relevant parts are copied into context when needed.
A large context window is not memory. A million-token window still disappears when the session ends, and every token in it is paid for on every call. Memory lives on disk or in a database, costs nothing to hold, and costs tokens only for the parts that are injected into a given call. The two solve different problems, and an agent needs both.
The model reads only its context. Memory has to be copied in. Every memory system therefore performs three operations:

The retrieve step is RAG, as defined in Module 8: get external information into the context for one generation. Everything known about retrieval applies to memory. The difference is the source. A RAG system retrieves from documents someone else wrote. A memory system retrieves from a store the agent built for itself. Curation matters as much as retrieval, because a store that only grows fills with entries that are outdated or wrong. The last lecture of this module covers curation in detail.
Memory systems usually distinguish four kinds of memory:
range(1, n) and missed the last item; a hint about the end value fixed it."The next two lectures cover episodic and semantic memory. The rest of this lecture covers the simplest durable memory, which needs none of this machinery.
The simplest durable memory is a text file that the agent reads and writes, such as NOTES.md. Anthropic calls this pattern structured note-taking: the agent writes notes to a store outside the context window and reads them back into the context later.
In a notes file, the agent records decisions, facts, open questions, and progress. The file lives outside the context window, so it survives truncation, compaction, and the end of the session. No embeddings, database, or retrieval scoring are involved.
The agent works with the file through ordinary tools. Two are enough:
save_note(content) appends a note to the file.read_notes() returns the file so its contents enter the context.An agent might add more, such as a tool that reads only one section of the file. The mechanism is the tool-calling loop from Module 6. Nothing new is needed.
The value of the file depends on what the agent writes. A file that records everything is as hard to use as no file at all. Curation starts at the moment of writing: "The user prefers tabs" is worth keeping, and a dump of the project's file tree is not. As a rule, the agent should write something down if it must survive past the current session, or if the context might be truncated before the agent needs it again. Information that matters only for the next few turns can stay in the context.
A tutoring agent that helps a student learn to program works with that student over many sessions. Each session starts with a new context. During a session, the agent calls save_note when something is worth keeping: the student finished a topic, struggled with a concept, or reached a natural stopping point. After a few sessions, the file might look like this:
# NOTES.md
## Finished
- Loops and lists
## Struggles
- Off-by-one errors in loop bounds
- Confuses append() and extend()
## Next session
- Start functions
- Review range() first
When the student returns, the agent reads the notes and picks up where it left off. Without them, every session would begin with "What have we covered so far?" With them, the agent opens with the range() review the student needs. The file leaves things out on purpose. It holds no session transcript and no list of every exercise. It keeps only what changes how the agent teaches next time. In effect, the notes file is a distillation of the whole series of conversations: small, but built from all of them.
A tool by itself does nothing. The model calls save_note only when something cues it to, and that cue comes from the prompt. The tutoring agent's system prompt already describes how to teach: guide the student instead of giving answers, and so on. One section of that prompt covers memory:
## Memory
You keep notes in NOTES.md. They persist between sessions.
- Start every session by calling read_notes, before anything else.
- Call save_note when the student finishes a topic, struggles with
a concept, or when you decide what to do next session.
- Save one fact per note. Do not save the conversation itself.
- Your context can be reset at any time. Anything not saved is lost.
The section tells the model when to read, when to write, what to keep, and why it matters. The line about what to keep does most of the curation. Without it, the model tends to save too much or too little. The last line follows Anthropic's memory tool, which automatically adds a similar warning to the system prompt: the context window "might be reset at any moment," and progress that is not recorded in memory is lost.
The tool description repeats the cue. The save_note description might read, "Save a note that persists to future sessions." Models are good at this task. Given clear instructions, they pick out what matters from a conversation and leave useful notes for their own later sessions.
Leaving every memory decision to the model has a weakness. The model cannot see when a session will end or when its context is about to be compacted. The harness, the code that runs the agent loop, can. Two jobs belong in the harness:
NOTES.md and places it in the system prompt before the first call. The model cannot forget to read its notes, because they are already in its context.The division of labor is simple. The prompt tells the model what to remember. The harness makes sure it reads and writes at the right moments. Production systems work this way. Claude Code loads its memory index at the start of every session, and OpenClaw runs a silent memory turn just before it compacts the context. Both systems return in the last lecture of this module.
A notes file works well while it is small. As it grows, two problems appear. The agent can read the whole file or none of it, and loading all of it starts to crowd the context. And the file holds conclusions, such as "struggles with off-by-one errors," while dropping the specific events behind them. A semester of tutoring produces far more history than one flat file can hold usefully.
The next lecture addresses both problems with episodic memory: individual records of past events, and ways to choose which of them to bring into the context.
Context lasts one session; memory persists across sessions. Memory reaches the model only when it is injected into the context, through a cycle of writing, curating, and retrieving that mirrors RAG. Memory comes in four kinds: conversation, episodic, semantic, and procedural. The simplest memory is a notes file that the agent reads and writes through two ordinary tools. The system prompt tells the model what to save, and the harness loads the notes at startup and asks for an update before context is lost.