LangMemLangMem 0.0.30 · LangGraph 1.2 · Python 3.10+
0%
1
Curious builder0 XP earned · 300 to level 2
0 daysFinish a lesson to begin
Badge collection0 of 6 unlocked
19 small wins to finish your pathNext lesson →

Episodic memory

Episodic memory is memory of past experiences: a record of one interaction, what the agent noticed, what it did and how it turned out, kept so the agent can repeat what worked.

Last updated: 30 Sep, 2026 · LangMem 0.0.30

Semantic memory keeps facts about Asha. Episodic memory keeps something else: how a situation was handled. When the next angry customer writes about a late parcel, the assistant can look up the episode where an apology, a delivery date and a voucher calmed a customer down.

Episodic memory · from the AI Security Course · 307:49 to 312:51
The video's notebook writes each episode by hand, as a dated diary entry per session produced by its own structured summarization. LangMem has no separate episodic API: this page gives create_memory_manager an episode schema, and follows LangMem's episodic memory guide in recording what worked (observation, thoughts, action, result) rather than a dated session log.

Timestamped records of whole interactions

The clip describes an episode as a timestamped, structured record of a whole session: what was discussed, what decisions were made and what advice was given, retrieved when a later session needs it. Episodes are written when a session ends, not after every message, by summarizing the session, and that runs in the background so the user never waits. A fact store keeps single fields; an episode keeps the whole session.

Syntax:

python
manager = create_memory_manager(model, schemas=[Episode], instructions="Extract one episode from this support chat.")
episodes = manager.invoke({"messages": chat})

The episode schema

LangMem's guide uses four fields: the situation, the agent's reasoning, the action and the result. The field descriptions are part of the prompt, so they tell the model what to write in each.

python
from pydantic import BaseModel, Field


class Episode(BaseModel):
    """One support chat, written from the agent's point of view, so it can learn what worked."""

    observation: str = Field(description="The situation and what the customer needed")
    thoughts: str = Field(description="What the agent considered, written as 'I ...'")
    action: str = Field(description="What the agent did")
    result: str = Field(description="How it turned out and why")

A chat that went well

python
chat = [
    {"role": "user", "content": "My parcel for order A-1003 is a week late and I'm angry."},
    {"role": "assistant", "content": "I'm sorry. It left the warehouse yesterday and arrives Friday. I've added a free delivery voucher."},
    {"role": "user", "content": "Oh, thanks. That's fine then."},
]

Extracting an episode

ExampleAPI key
from langchain.chat_models import init_chat_model
from langmem import create_memory_manager

from pydantic import BaseModel, Field


class Episode(BaseModel):
    """One support chat, written from the agent's point of view, so it can learn what worked."""

    observation: str = Field(description="The situation and what the customer needed")
    thoughts: str = Field(description="What the agent considered, written as 'I ...'")
    action: str = Field(description="What the agent did")
    result: str = Field(description="How it turned out and why")

chat = [
    {"role": "user", "content": "My parcel for order A-1003 is a week late and I'm angry."},
    {"role": "assistant", "content": "I'm sorry. It left the warehouse yesterday and arrives Friday. I've added a free delivery voucher."},
    {"role": "user", "content": "Oh, thanks. That's fine then."},
]

model = init_chat_model("groq:openai/gpt-oss-120b", temperature=0)
manager = create_memory_manager(model, schemas=[Episode], instructions="Extract one episode from this support chat.")
episode = manager.invoke({"messages": chat})[0].content
for field, text in episode.model_dump().items():
    print(f"{field}: {text}")

What the episode recorded

  • observation names the situation: an angry customer and a parcel a week late.
  • thoughts is written as "I ...", as the field description asked, and gives the reasoning: a clear update plus a voucher to restore goodwill.
  • action lists what was done, with the details from the chat: left the warehouse yesterday, arriving Friday, the voucher.
  • result quotes the customer's reply as the evidence that it worked. The next late-parcel complaint can be answered with this episode as an example.

Episodic vs semantic memory

EpisodicSemantic
HoldsHow one interaction wentFacts that stay true
ExampleAn apology plus a voucher calmed a late-parcel complaintAsha prefers email
WrittenOnce per conversation, after it endsWhenever a fact appears or changes
Used asAn example in the prompt for a similar caseContext about the user

When to keep episodes

  • Support: which resolution worked for which kind of complaint.
  • Tutoring: which explanation made a concept click for a student.
  • Any agent that should get better at a recurring task by reusing its own good examples.
Watch out. An episode is only as good as the conversation it came from. Extract episodes from interactions that went well, or add a field for what to avoid; otherwise the agent learns from its mistakes in the wrong direction.
Try it yourself
  • Change the last message to "That's not good enough" and extract again.
  • Add a field avoid: str to Episode and read what the model writes in it.
  • Put the episode's fields into a system prompt and ask the model to answer a new late-parcel complaint.
PreviousProfiles

Slow is fine. Stopping is the only problem.