The capability
What a memory is
There are mainly two types of memory when it comes to LLMs. The first is short-term memory, which is the list of messages the model gets on every call during the conversation you're in right now. Everything that's been said so far in that thread is in the list, and when the thread ends, the list goes away with it. M5 was all about managing that list.
The second is long-term memory, which is the kind that survives outside the current conversation. If you've used ChatGPT, you've probably already run into that kind of memory. You can open a new chat, ask about something you talked through weeks ago in a different chat, and it still knows. Or you tell it once that you write in British English and don't like bullet points, and every new chat follows that without you having to say it again. That second kind is what this module is about.
According to OpenAI, ChatGPT does this in two ways. The first is saved memories, which are things you ask it to remember, like "remember I'm vegetarian", and those get written down during the chat. And since April 2025 it also learns from your chat history, through a background process OpenAI calls dreaming. That process reads across your past conversations and keeps rewriting what ChatGPT knows about you, so new chats start with that context (OpenAI, June 2026). OpenAI doesn't publish how ChatGPT finds the relevant parts of old chats, so it isn't public whether it also embeds them and searches them the way RAG does (M19 covers that). What OpenAI does describe is the background job that keeps ChatGPT's notes about you up to date.
The same post explains why they rebuilt it. OpenAI says saved memories "tend to go stale over time and eventually become incorrect or irrelevant". Elsewhere in the post they list staying current as one of the goals, and the example they give is a memory that says you're planning a birthday party for next Saturday, which stops being true as soon as Sunday comes around. Most of this module is about keeping memory current when the facts behind it change.
When you build your own agent, none of that comes for free. The model doesn't keep anything between calls, which was the point M3 made, so something has to decide what's worth keeping and write it down, and then something has to load it back in later.
The writing can happen in one of two ways, and they're the same two that ChatGPT uses. The first is during the conversation. You give the model a tool with a name like remember_fact, and the model decides by itself when something the user said is worth keeping and calls that tool. The tool call is only a request, though, so it's your code that checks the value and writes the row, the same as with any other tool the agent has. That's how ChatGPT's saved memories work, and OpenAI's post says they "were only written during the conversation and relied on strong cues to decide when to trigger memory", like someone saying "remember I'm traveling to Singapore in July".
The second way is after the conversation. Once a session ends, a separate model call reads through the whole transcript and pulls out anything that's worth keeping, whether or not anyone asked for it to be saved. That's closer to what ChatGPT's dreaming does, and it catches the things the model didn't think to save while it was busy answering.
Loading it back is simpler. At the start of the next conversation, your code looks up what's stored for that user or project and puts it into the list the model sees. If a fact gets saved and never loaded, it doesn't do anything.
So you end up with a write policy, which is whatever decides what gets saved, in either of those two ways, and a read policy, which decides which saved facts get loaded on a later turn and where they go in the context. Those are separate pieces of code, and they break separately. M6 built a table keyed by customer id for exactly this, and the same shape works if you key it by a user or a project. But M6 left the question of what belongs in that table to this module.
The running example for this module is a coding agent. A small team uses it on the repo for their web app, and it remembers facts about the project from one session to the next, like which command runs the tests and where staging deploys go. The team and its repo are made up, and so are the numbers. In the figure below, a developer tells the agent in February where staging deploys go, and the agent reads that fact back in September.

The model itself still doesn't remember anything. All it does is read what's in the list on this call, so when an agent seems to remember you, that's your code loading the right fact. And when it forgets you, either the fact was never saved, or the query didn't fetch it, or it got fetched and never put in the list. There's a fourth way it can go wrong that M5 didn't cover, which is that the fact made it into the list and was wrong, and that's the one this module spends most of its time on.
Why this is a capability of its own
After M5 and M6 you might think there isn't much left to do here. The store lives outside the model, and reading from it is just a lookup by id. Writing a row and reading it back is a morning's work.
And it does stay that simple while you're testing it. But once real people are using the agent for months, memory gets complicated quickly, and if you don't design it properly, it starts working against you. Something has to decide what's worth saving and when, what to do when a new fact contradicts an old one, and which of everything you've saved gets loaded into this conversation. If you get those wrong, the agent confidently acts on things that aren't true anymore, or it fills its context with notes that have nothing to do with the task.
The clearest example is facts going out of date. A developer tells the agent one thing in February and something different in June, or the agent writes down that a form field is required and a month later someone changes the form. Every write was right at the time it happened, and the rows stop being true anyway. Nothing in the store notices, because an old row looks exactly the same as a current one.
Where it shows up
You'll find long-term memory pretty much anywhere an agent deals with the same person or the same system more than once.
- A coding agent's progress file, read at the start of a session so the next one carries on from the last one.
- A tutoring app's note of which topics a student has already covered and which ones they struggled with.
- An account record a sales assistant carries from one call into the next.
- An agent's own notes about a tool, like which field on an internal admin form fails silently when it's left blank.
All of them have the same write and read code behind them, and what's different between them is how much it costs when the agent acts on something that's gone out of date.
Keep reading
The rest of this lesson is free with an account
Create a free account to read the remaining 17 sections. It takes about twenty seconds and there's nothing to pay. The same account opens the slide decks and CV reviews.
- 02The deploy target that was true in February
- 03What deserves to become a memory
- 04Where long-term memory can live
- 05Deciding what gets saved
- 06Too little memory, and too much
- and 12 more
That's the last one written so far
Pick your next module from the board.
