Module 4 — Memory: Context & Recall
In Module 3 the agent kept its whole Thought–Action–Observation trace in view to finish the task. But that trace lives in the model's context window — the fixed-size chunk of recent text the model can actually see at once. It is not unlimited. Push enough into it and the oldest material falls off the back, gone. An agent that runs for many steps, or holds a long conversation, will forget things it once knew unless you give it a second kind of memory.
Two kinds of memory
- Short-term (the context window) — the recent turns the agent can see right now. Fast and automatic, but capped: when it is full, the oldest turn is dropped to make room. This is the working memory from Module 3.
- Long-term (a memory store) — a place the agent can deliberately save a fact to and recall it later by key, even after that fact has scrolled out of the context window. In real systems this is often a database or a vector store.
The skill is knowing what to commit to long-term memory. Anything the agent must not forget — a user's name, a constraint, a result it will need ten steps later — should be saved, not left to drift out of the context window.
Fill the context window and watch it forget
The agent below has a small context window — it can hold only the last few turns. Add turns and watch the oldest ones fall off the back. Then try the same turns with a long-term store switched on: the agent saves key facts, so even after a fact leaves the window, it can still recall it.
This activity needs JavaScript. The lesson below still covers everything.
Ask the agent to recall
After loading some turns above, ask the agent a question that depends on an old fact. With only the context window, the fact may already be gone. With the store on, the agent recalls it. This is exactly why production assistants pair a context window with an external memory.
This activity needs JavaScript.
# short-term: a capped list — the context window def remember(turn): context.append(turn) while len(context) > WINDOW: # full? drop the oldest context.pop(0) # long-term: an explicit save / recall the agent controls store["user_name"] = "Mienie" # save a fact by key name = store.get("user_name") # recall it later, after it left the window
A real "memory" is fancier — embeddings let the agent recall by meaning rather than an exact key (the vectors from Course 2 and Course 5) — but the idea is identical: a store that outlives the context window.
Check your understanding
A few questions about context and recall. You will get a score.
This activity needs JavaScript.