Agent Memory
Carrying context beyond one context window
Memory is what an agent carries beyond its current context: working context, episodic history of past tasks, and semantic knowledge retrieved on demand. Good memory design decides whether an agent feels coherent — or forgets mid-sentence.
What you will learn
- Enumerate the memory tiers
- Design recall that finds what matters
- Manage stale and private memories
What is this?
Memory tiers: working (in-context turn state), episodic (past tasks: inputs, decisions, outcomes), and semantic (extracted knowledge: user prefs, domain facts) — stored in vector DBs or tables and retrieved when relevant. Good memory retrieves precisely, expires stale entries, and never leaks across tenants.
Why do you need it?
- Long tasks outgrow the context window.
- Returning users expect continuity across sessions.
- Semantic memory reduces repeated tool calls and errors.
- Tiered memory keeps cost sane: only fetch what today's turn needs.
Mental model
A barista who knows your order
Semantic memory
Working memory is the order pad for THIS drink (current turn). Episodic memory: 'last time you grabbed a flat white at 9am'. Semantic memory: 'you prefer oat milk, double shot'. The good barista checks the working note, keeps the episodic trail, and consults the preference card — without paging through every order you've ever made.
How it works
- Working: assemble recent turns + current step context.
- Episodic: append completed tasks with outcomes to a store.
- Semantic: extract durable facts; embed and index.
- Recall: on turn start, fetch relevant memory (scored, bounded).
- Manage: expiry, privacy boundaries, tenant isolation.
Memory tiers.
In production
- Support agents recall user's equipment, history, and open issues.
- Coding agents recall repo conventions across sessions.
- Personal assistants fetch preferences on relevant turns.
Best practices
- Fetch little and high-precision: 3-6 memory hits max.
- Store with metadata (time, source, confidence) for expiry and attribution.
- Isolate memory by tenant/user; never cross-leak.
- Let users view/delete stored memories (privacy).
Common mistakes
- Dumping the whole memory store into every prompt.
- No expiry — 'you mentioned X last year' becomes wrong guidance.
- Cross-tenant memory bleed.
Common issues
Semantic recall misses the right factBad extraction or embedding
Improve extraction prompts; hybrid keyword+vector recall.
Memory contradicts current truthStale entries never expired
Timestamp and decay; deprecate on observed contradiction.
Debugging tips
- Agent forgets between turns → working memory assembled wrong; check what's included.
- Old facts mislead → expiry and confidence scoring absent.
- Recall noise → score threshold too low; tighten scoring.
Interview checkpoint
Hands-on lab
- Append observations into working memory
- Compact memory when it grows past a budget
- Recall facts from memory by keyword
Scratchpad and Rolling Summary
25 min · intermediate
Quick quiz
Semantic memory means…
Recalling the entire memory store is a fine strategy.