Memory, State, and Context Management
Why Memory Matters
Context Is Not Enough
The model context window is limited, but many tasks require continuity across time. Memory helps an agent remember user preferences, task history, intermediate results, and unresolved questions.
Kinds of Memory
Short-term memory stores the current conversation and working notes. Long-term memory stores durable facts, preferences, and episodic traces. Retrieval memory brings back only the most relevant information for the current step.
Memory Types Compared
| Type | Purpose |
|---|---|
| Working memory | Holds active reasoning state |
| Episodic memory | Stores events and past interactions |
| Semantic memory | Stores stable facts and concepts |
| Retrieval memory | Fetches relevant items on demand |
Memory Design Tip
Store less than you think, but retrieve better than you expect. Relevance ranking often matters more than raw storage size.
What is the main benefit of retrieval memory in an agent?
Retrieval supports context efficiency by fetching relevant information when needed.
Correct answer: It brings back the most relevant information for the current task
Why can long tasks fail if an agent relies only on the immediate context window?
Memory is needed to preserve state across many steps.
Correct answer: Because important information may fall out of context over time.
A Simple Memory Update Cycle
-
1
Step 1: Observe the new interaction or tool result.
-
2
Step 2: Decide whether it is important enough to store.
-
3
Step 3: Compress it into a useful representation.
-
4
Step 4: Save it with metadata such as time and source.
-
5
Step 5: Retrieve it later only when it is relevant.
Which memory type is most appropriate for stable user preferences?
Stable preferences are a form of durable knowledge.
Correct answer: Semantic memory