When to reach for it
- The agent needs to learn from past cases.
- Recurring tasks follow similar solution paths.
- Context including time, goal, and outcome is relevant.
Solved cases, kept so the agent can pull the right one back when a similar task returns.
Completed interactions are stored as discrete, timestamped episodes — a natural-language memory stream — and retrieved later by a combined recency, importance, and relevance score, so the agent can reuse what worked in a similar past situation.
In practiceA software-debugging agent stores each resolved bug as an episode, then retrieves the three closest past episodes by embedding similarity when it encounters a new error.
Two separate paths share one store. The write path runs at the end of every task, the read path at the start of the next.
1 · Write, after the task
2 · Recall, before the next task
| Episode | Recency | Importance | Relevance | Score | Loaded |
|---|---|---|---|---|---|
| Timeout in the payment client · 3 days ago · retry with backoff fixed it | 0.90 | 0.70 | 0.80 | 2.40 | Yes |
| Timeout in the auth service · 2 months ago · cause was DNS, production outage | 0.30 | 0.90 | 0.70 | 1.90 | Yes |
| Connection reset in the payment client · 2 weeks ago · connection pool enlarged | 0.60 | 0.60 | 0.60 | 1.80 | Yes |
| Timeout in the payment client, API v1 · 1 year ago · workaround, interface retired | 0.10 | 0.20 | 0.95 | 1.25 | No |
def score(episode, task, now):
recency = 0.995 ** hours_since(episode.last_access, now)
# rated once at write time, 1 to 10
importance = episode.importance / 10
relevance = cosine(episode.embedding, embed(task))
return recency + importance + relevance
def recall(store, task, now, k=3):
ranked = sorted(store, key=lambda e: score(e, task, now), reverse=True)
return ranked[:k]When to reach for it
When it backfires
Episodes from a deprecated tool surface stay matchable. The planner picks an old strategy and runs it against an API that no longer exists.
Countermeasure
Tag episodes with a tool-surface version. Filter or expire episodes when the surface they referenced changes.
Ranking by embedding similarity only, a superficially-worded match outranks the genuinely relevant recent success, and the agent replays a strategy that never applied here.
Countermeasure
Score retrieval by recency + importance + relevance combined (per Generative Agents), not similarity alone, and weight successful outcomes above mere textual match.
Threat exposure
Adopting this pattern opens these attack surfaces. Each links to its entry in the threat model.
Full threat model →EU law
Duties from EU law that this pattern helps meet, or that land on it. A reading aid, not legal advice.
An engineer's reading aid, not legal advice. The legal texts and their interpretation are authoritative.
Keep going
Search patterns, frameworks, and pages.