Skip to 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.

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.

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:

Terminal window
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.

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

Keep this page’s proof of learning as a small evidence card:

Memory Type
short-term, long-term, episodic, or procedural
Write Rule
when memory is created or updated
Retrieve Rule
query, relevance, recency, and permission check
Failure Check
stale memory, privacy leak, contradiction, or over-retrieval
Cleanup Action
summarize, merge, expire, delete, or ask for confirmation

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.

Check reasoning and explanation
  1. A passing answer describes the agent loop: goal, plan, tool call, observation, memory or state update, and stop condition.
  2. The evidence should include a trace that another developer can inspect, not only the final answer.
  3. A good self-check names one safety or reliability control such as tool schemas, permission boundaries, retries, evaluation cases, or a human-review point.