Course file
week16_memory/README.md
Every agent you've built so far has amnesia. When you restart the script, it forgets everything. Ask it about something you discussed two minutes ago in a previous run — blank stare.
This week you fix that.
LLMs are stateless. Each API call is independent — Claude doesn't remember previous conversations unless you send them in the messages array. When you restart your script, that messages array is gone.
There are two kinds of memory you can give an agent:
The messages list you already know. As long as you keep appending to it, the agent remembers the current conversation. But it has limits — Claude's context window is large but not infinite.
Save information to a file or database so it survives between runs. This is what you built in Week 10 with RAG — retrieve stored knowledge before answering. This week we do a simpler version: a note-taking system.
Two files:
memory_store.py — A simple file-based note system. Functions: save_note(key, content), get_note(key), list_notes(). Stores everything in a JSON file.memory_agent.py — An agent that can save and retrieve notes, plus full conversation history within a session.cp .env.example .env
Install deps:
pip install anthropic python-dotenv
python memory_agent.py
Try this sequence:
Then try:
memory_store.py. It's short. Understand how notes are stored.delete_note tool. Add the function to memory_store.py and wire it into the agent.search_notes tool that finds notes containing a keyword.reflection.md.In Week 10 you built a RAG system that retrieved relevant chunks from a document before answering. That's the same idea as knowledge memory — look up stored info before generating a response. The difference is scale:
They're all the same pattern: retrieve, then generate.
memory_agent.py and memory_store.py with your improvementsreflection.md filled inagent_notes.json file with at least 3 saved notes"I'm building a memory system for an AI agent. Notes save fine but when I restart the agent, [describe problem]. Here's my memory_store.py: [paste code]. What's wrong?"