Episodic Memory

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.

Level
04 · Production
Subdomain
Memory Architecture
Also known as
Experience Memory, Task Episode Store, Interaction Memory
Trade-off
Experience-based adaptation is gained against high curation and data privacy maintenance efforts.
Native in
LangGraph, AutoGen / AG2, Microsoft Agent Framework, CrewAI
The mechanism

How it works.

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

  1. Task finishedGoal, steps and outcome are known
  2. Form an episodeTimestamp, importance rating, embedding
  3. Episode storeGrows with every case

2 · Recall, before the next task

  1. New taskBecomes the query
  2. Score every episodeRecency + importance + relevance
  3. Keep the top kThe rest stays out
  4. Into the contextThe agent plans with prior experience
Recency
How long ago was the episode last accessed? The value decays over time.
Importance
How consequential was the case? Rated once, when the episode is written.
Relevance
How similar is the episode to the current task? Embedding distance.
Walk it through

A real run, step by step.

TaskA debugging agent stores every solved bug as an episode. Now the payment client raises a TimeoutError: four episodes qualify, three are loaded.
Illustrative values, each 0 to 1. The score is the sum of the three columns.
EpisodeRecencyImportanceRelevanceScoreLoaded
Timeout in the payment client · 3 days ago · retry with backoff fixed it0.900.700.802.40Yes
Timeout in the auth service · 2 months ago · cause was DNS, production outage0.300.900.701.90Yes
Connection reset in the payment client · 2 weeks ago · connection pool enlarged0.600.600.601.80Yes
Timeout in the payment client, API v1 · 1 year ago · workaround, interface retired0.100.200.951.25No
What this shows: the last episode is the most similar to the new error and would win a pure similarity search. It is old and unimportant, so it stays out, and the agent gets no workaround for an API that no longer exists.
In code

The pattern in code.

Plain Pythonpython
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]
Fit

Use it, or not.

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.

When it backfires

  • Past cases quickly become obsolete.
  • Storing personal data is problematic.
  • A static semantic knowledge base suffices.
Pitfalls

Two ways this pattern will hurt you.

Stale episodes mislead the planner

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.

Similarity alone retrieves the wrong episode

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

What this pattern exposes

Adopting this pattern opens these attack surfaces. Each links to its entry in the threat model.

Full threat model →

EU law

Regulation

Duties from EU law that this pattern helps meet, or that land on it. A reading aid, not legal advice.

  • GDPR Art. 15A person can obtain confirmation that their data is processed, access to it, and the recipients it was disclosed to.Controllers · since 25 May 2018
  • GDPR Art. 17Personal data is erased without undue delay when a ground for erasure applies.Controllers · since 25 May 2018
  • GDPR Art. 35Before processing that is likely to result in a high risk, in particular with new technologies, the controller assesses its impact on the protection of personal data.Controllers · since 25 May 2018Explained on the DPIA page

An engineer's reading aid, not legal advice. The legal texts and their interpretation are authoritative.

Framework support

Where Episodic Memory is native.

LangGraphstore + similarity recallNative
AutoGen / AG2teachability / memoryNative
Microsoft Agent Frameworkepisodic storeNative
CrewAIlong-term memoryNative

Search

Search patterns, frameworks, and pages.