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.
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:
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.
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
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
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}")observation: Customer expressed anger because parcel for order A-1003 was a week late. thoughts: I recognized the customer's frustration, decided to give a clear update on the shipment and add a free delivery voucher to restore goodwill. action: Apologized for the delay, provided the latest shipping status (left warehouse yesterday, expected arrival Friday), and offered a free delivery voucher as compensation. result: Customer accepted the explanation and voucher, responded positively with "Oh, thanks. That's fine then."
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
| Episodic | Semantic | |
|---|---|---|
| Holds | How one interaction went | Facts that stay true |
| Example | An apology plus a voucher calmed a late-parcel complaint | Asha prefers email |
| Written | Once per conversation, after it ends | Whenever a fact appears or changes |
| Used as | An example in the prompt for a similar case | Context 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.
Related
- Previous: Profiles
- Next: The LangGraph store
- Reference: How to extract episodic memories
- Change the last message to "That's not good enough" and extract again.
- Add a field
avoid: strtoEpisodeand 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.
Slow is fine. Stopping is the only problem.