Skip to content
AgenticAIWiki
  1. Learn
  2. Part 10
  3. 54. The memory types map
  4. 54.2

Lesson 54.2 · 2 of 5 · 4 min read · Reviewed 24 Nov 2026

Episodic memory: what happened

By the end, you can

  • Describe episodic memory for agents.
  • Store episodes so they're useful later.

Episodic memory answers: what happened before?

Examples

  • “On 3 Nov the user asked for a refund on order 1042; approved, 40 dollars.”
  • “Last session we tried fixing the flaky test by adding a retry. It didn’t work; the cause was a shared temp folder.”
  • “The user rejected the first draft as too formal.”

How to store episodes

Field Example
When 2026-11-03
Who or what User C-2201, support
What happened Refund request for damaged item
Outcome Approved, 40 dollars
Lessons Customer prefers email follow-up

Generate the summary at the end of a session (or when context is compacted, chapter 60), and store it with the user or project id and the date.

Using episodes

At the start of a new session, load the few most recent or most relevant episodes, not all of them. “Relevant” can come from a search over summaries (57.2).

Agents learning from mistakes

Episodes that record failures and their fixes are especially valuable for coding and research agents: they stop the agent from trying the same dead end twice. Claude CodeClaude Code: Anthropic’s agentic coding tool that works in your terminal, IDE and CI, reading and editing code and running commands. users often keep this kind of note in a project notes file.

Key points

  • Episodic memory records what happened: past conversations, tasks, outcomes and mistakes.
  • Raw transcripts are too long to reload; store short summaries with time, participants and outcome.
  • Episodes help agents stay consistent with past decisions and avoid repeating failures.
Hands-on labRuns in the Playground

Turn transcripts into episode records

Convert raw session transcripts into short episodes with date, owner, what happened, outcome and lesson, then load only the most recent ones.

You will have: A function that builds episode records and a printout comparing tokens for transcripts versus episodes.

Steps

  1. Read the three sample transcripts in the starter.
  2. Write make_episode: pull out the date, the issue (first user line), the outcome (the line starting 'Outcome:') and any 'Lesson:' line.
  3. Store the episodes per user, newest first.
  4. Load the two most recent episodes for user C-2201 and print them.
  5. Estimate tokens (about 4 characters each) for the full transcripts and for the episodes.

Done when

  • Three episodes are stored, each with date, issue and outcome.
  • Only two episodes are loaded for the new session.
  • Episodes use at least 2x fewer tokens than the transcripts.

Open in the Playground No API key needed.

Starter code (Python)
TRANSCRIPTS = [
    {"user": "C-2201", "date": "2026-10-02", "lines": ["user: my invoice shows a double charge", "agent: checking", "agent: found a duplicate line", "Outcome: refund of 40 credits approved", "Lesson: customer prefers email follow-up", "user: thanks, bye"]},
    {"user": "C-2201", "date": "2026-11-03", "lines": ["user: parcel arrived damaged", "agent: sorry to hear that", "agent: photo received", "Outcome: replacement sent", "user: great"]},
    {"user": "C-2201", "date": "2026-11-20", "lines": ["user: how do I change my delivery address", "agent: here is the link", "Outcome: address updated by customer", "user: done"]},
]

def tokens(text):
    return max(1, len(text) // 4)

def make_episode(t):
    # TODO: return {"date", "user", "issue", "outcome", "lesson"} built from the transcript
    return {"date": t["date"], "user": t["user"]}

STORE = {}
for t in TRANSCRIPTS:
    STORE.setdefault(t["user"], []).append(make_episode(t))
# TODO: sort each user's episodes newest first, then load the two most recent
loaded = []
print("episodes stored:", sum(len(v) for v in STORE.values()))
print("loaded:", loaded)
Show a solution
TRANSCRIPTS = [
    {"user": "C-2201", "date": "2026-10-02", "lines": ["user: my invoice shows a double charge", "agent: checking", "agent: found a duplicate line", "Outcome: refund of 40 credits approved", "Lesson: customer prefers email follow-up", "user: thanks, bye"]},
    {"user": "C-2201", "date": "2026-11-03", "lines": ["user: parcel arrived damaged", "agent: sorry to hear that", "agent: photo received", "Outcome: replacement sent", "user: great"]},
    {"user": "C-2201", "date": "2026-11-20", "lines": ["user: how do I change my delivery address", "agent: here is the link", "Outcome: address updated by customer", "user: done"]},
]

def tokens(text):
    return max(1, len(text) // 4)

def pick(lines, prefix):
    return next((l[len(prefix):] for l in lines if l.startswith(prefix)), "")

def make_episode(t):
    return {"date": t["date"], "user": t["user"], "issue": pick(t["lines"], "user: "),
            "outcome": pick(t["lines"], "Outcome: "), "lesson": pick(t["lines"], "Lesson: ")}

STORE = {}
for t in TRANSCRIPTS:
    STORE.setdefault(t["user"], []).append(make_episode(t))
for eps in STORE.values():
    eps.sort(key=lambda e: e["date"], reverse=True)
loaded = STORE["C-2201"][:2]
print("episodes stored:", sum(len(v) for v in STORE.values()))
for e in loaded:
    print("loaded:", e["date"], "|", e["issue"], "|", e["outcome"])
full = sum(tokens(" ".join(t["lines"])) for t in TRANSCRIPTS)
short = sum(tokens(e["issue"] + e["outcome"] + e["lesson"]) for e in STORE["C-2201"])
print("transcript tokens:", full, "episode tokens:", short, "ratio: %.1fx" % (full / short))
Quick checkWhat's the most useful way to store a past support conversation as episodic memory?
How sure are you?
Pick an answer and how sure you are