
Mission 4 of 8
Give your agent memory it can trust, and see how it goes wrong.
Your agent has perfect recall for one task and total amnesia after it. You'll build short-term and long-term memory, feel the before and after, then poison it on purpose to see the controls that stop it.
What you'll do
Run the agent twice and see why the second run can't answer, then learn what memory actually has to do.
Add a token budget with compaction, and a SQLite long-term store with search, age, expiry and supersede.
Demonstrate stale memory and a poisoning attempt from a file, then switch on the controls that stop each.
- Run a session agent that recalls before each task and asks before it remembers
- Know what a memory=True flag would need to do to be safe
- Mission 3 done:
tools.py,toolbox.py,tools_v2.pyandexpenses.txtinagent-lab, venv active, key set - Python 3.10+ with SQLite FTS5 (standard in python.org builds; check in step 3)
- The willingness to type the same question into two terminals and compare. The before/after is the lesson
Your progress0/6
- 01The context window is the only memory. Prove it8 min
- 02Short-term: a token budget and a compaction step14 min
- 03Long-term: a SQLite store with search, age, expiry and supersede14 min
- 04The session agent: recall before, confirm before remembering, compact between14 min
- 05Failure mode 1: stale memory8 min
- 06Failure mode 2: memory poisoning, and the gate that stops it12 min
The context window is the only memory. Prove it
Everything called memory is a way of getting the right text into the next request. Once that is obvious, the design choices are obvious.
Before building any memory, it helps to see the problem for yourself. A short experiment with the agent you already have will show it better than an explanation.
Run mission 3's agent twice:
Terminalpython agent2.py "My name is Joe and I keep my expenses in expenses.txt. Remember that." python agent2.py "What file do I keep my expenses in?"The first run says something warm about remembering. The second has no idea.
Nothing was stored anywhere, because
run()builds a freshmessageslist each time and the API is stateless. The model's "I'll remember that" is a sentence, not an action.
Two different questions
So: the model sees exactly one thing, the request you send. Memory, of every kind, is code that decides what to put in that request. There are two questions and they are different:
- Short-term: what from this session stays in the request? The
messageslist grows with every tool call. Past about 30,000 tokens, quality drops, cost rises and old tool results crowd out the current task. You need a budget and a way to shrink. - Long-term: what from past sessions gets pulled back in? A store the agent writes facts to and reads facts from. The hard part is not storage. It is deciding what to write, what to trust, and when a fact stops being true.
Frameworks sell both as a memory=True flag. By the end of this mission you will know what that flag would have to do to be safe, and you will have seen that most do not.