The messages list from Module 1 only lasts for one run of the program — close it and Claude forgets everything. This module adds memory that survives between separate runs, by having the agent read and write a JSON file on disk.
remember, recall, forget, forget_all, update_factdef build_system_prompt() -> str:
facts = load_memory()
...
return base + "\n\nWhat you already know about this user:\n" + "\n".join(lines)
Every time the agent starts, it loads agent_memory.json and folds it into the system prompt before the conversation begins. Claude then decides — using the remember tool — when something is worth saving for next time. There’s no special “memory API”; it’s the same tool-use pattern from Module 2, applied to a JSON file instead of a calculator.
Note forget operates by index, not by exact text match — update_fact uses partial, case-insensitive matching to find the right entry to replace. Both are deliberate choices: index-based removal avoids ambiguity when two facts are similar; partial-match updates make it easy for the user to say “actually, it’s…” without repeating the whole original fact.
pip install -r requirements.txt
export ANTHROPIC_API_KEY=your_key_here
python agent.py
Try: "My name is Sam and I prefer concise answers.", then quit and restart — the agent still knows.
Module 4 — Skills & Specialization — instead of remembering facts, the agent loads an entire persona from a file.