learning-it by example

Back to the video

Agent Memory: What to Keep and What to Forget

My agent forgot my name after four messages. When I let it remember everything, it remembered my card number too.

Video #23 ยท AI agents and MCP

Steps in the video

  1. 0:00 It forgot my name
  2. 0:28 The idea
  3. 1:04 Setup
  4. 1:21 The store
  5. 1:39 Recall and forget
  6. 1:59 The guard
  7. 2:16 Filling the slots
  8. 2:33 The chat
  9. 2:54 The quiz
  10. 3:13 Three policies
  11. 4:23 The one it missed
  12. 4:42 What this does not show
  13. 5:09 Mistakes to avoid
  14. 5:30 My take and next steps
  15. 5:53 Recap

Files

  • agent.py (13 lines)
  • chat.py (65 lines)
  • extract.py (21 lines)
  • guard.py (9 lines)
  • memory.py (45 lines)

Download the code (zip)

Tested with

Python 3.12.15 | ollama==0.6.3

What this does not show

One small local model, one made-up ten-message chat and six questions written by the author, one run. Scoring is strict; the curated mode's one miss is a hedged answer, not a lost memory. No size cap or eviction is built. The guard is two patterns and is not enough for real sensitive data. The card number is a standard test number.

Sources

Learning IT by Example.