Skip to main content

9.4.1 Memory Roadmap: Write, Retrieve, Forget

Memory is not there to make an Agent feel human. It should help the task: reduce repeated questions, preserve useful context, reuse experience, and avoid stale or private information leaks.

See the Memory Loop First

Layered diagram of the Agent memory system

Learning order diagram for the Agent memory systems chapter

Closed loop diagram of Agent memory writing and retrieval

The core decision is not “save everything.” It is what to save, when to retrieve it, when to update it, and when to forget it.

Run a Memory Write Filter

Only stable preferences and reusable facts should become long-term memory.

events = [
{"type": "preference", "text": "prefers short examples"},
{"type": "temporary", "text": "debugging one local error"},
{"type": "fact", "text": "project uses Python"},
]

memory = []
for event in events:
if event["type"] in {"preference", "fact"}:
memory.append(event["text"])

print("saved:", memory)
print("count:", len(memory))

Expected output:

saved: ['prefers short examples', 'project uses Python']
count: 2

If a memory is not useful, current, permitted, and retrievable, it can hurt the Agent more than it helps.

Learn in This Order

StepReadPractice Output
1Memory overviewDistinguish context window, short-term memory, long-term memory
2Short-term memoryTrack current task state across turns
3Long-term memorySave durable preferences, facts, and project background
4Episodic and procedural memorySeparate what happened from how to do it next time
5Memory engineeringDesign write, retrieve, update, expire, and delete rules

Pass Check

You pass this chapter when you can explain why “remember more” is not the same as “perform better.”

The exit mini project is a learning-planning assistant memory rule set: what to save, what to confirm, what to keep temporary, and what to delete.