Episodic Memory: Experience Induction & Reuse

Experience Induction & Reuse” in the context of Episodic Memory means that an AI agent doesn’t just store raw conversation logs—it extracts structured lessons from past successful (and failed) interactions, generalizes them into reusable patterns, and applies those patterns to new, similar situations.

CN: “经验归纳与复用”在情景记忆(Episodic Memory)的语境下,指的是 AI Agent 不只是存储原始对话日志,而是从过去的成功(和失败)交互中提取结构化的经验教训归纳为可复用的模式,并在新的类似场景中应用这些模式

Think of it like a seasoned detective vs a rookie:

CN: 用人话比喻,就像资深侦探 vs 新警察

Rookie (无经验归纳)Seasoned Detective (有经验归纳)
ENReads every case file from scratch. Has to figure out the same patterns over and over.Has a “playbook” of past cases. Recognizes: “This looks like the Smith case from 2022—we found the killer by checking the alibi.”
CN每份卷宗都从头读起,同样的模式要反复摸索。有一本“过往案例手册”,一眼认出:“这像2022年的Smith案——当时我们通过核查不在场证明找到了凶手。”
ENTries the same failing interrogation tactic repeatedly.Learns from past mistakes: “Last time we pressured the suspect, they clammed up. This time we try a different approach.”
CN反复使用同样失败的审讯技巧。从过去错误中学习:“上次给嫌疑人施压,对方直接闭嘴了。这次换一种方法。”

Core Flow of Experience Induction & Reuse

The process consists of four key stages: ① Extraction (提取) ──► ② Storage (存储) ──► ③ Reflection (反思) ──► ④ Reuse (复用)

3.1 阶段1:Episode 提取 (Extraction)

aw conversation is transformed into a structured Episode record:

CN: 原始对话被转换为结构化的 Episode 记录

class Episode(BaseModel):
    observation: str   # Context and setup - what happened / 上下文和场景——发生了什么
    thoughts: str      # Internal reasoning process - "I..." / 内部推理过程——“我...”
    action: str        # What was done and how - "I..." / 做了什么、怎么做——“我...”
    result: str        # Outcome and retrospective - "I..." / 结果和复盘——“我...”

This schema preserves the complete decision-making process, enabling the agent to learn not just what worked, but why it worked and how to replicate the success.

CN: 这个结构保留了完整的决策过程,让 Agent 不仅能学到什么有效,还能学到为什么有效以及如何复制成功

3.2 阶段2:存储与检索 (Storage & Retrieval)

EN: Episodes are stored as vector embeddings in a vector database (e.g., Azure AI Search, Pinecone, Chroma). Retrieval is done by semantic similarity—not by recency.

CN: Episode 以向量嵌入的形式存储在向量数据库中(如 Azure AI Search、Pinecone、Chroma)。检索基于语义相似度,而不是时间先后。

EN: Key storage operations:

CN: 关键存储操作

OperationMethodPurpose
EN: Store EpisodeENMemoryStoreManager.ainvoke()EN: Persist new episodes
CN: 存储EpisodeCN:CN: 持久化新的Episode
EN: Search SimilarENBaseStore.asearch()EN: Find relevant past experiences
CN: 相似检索CN:CN: 查找相关的过往经验
EN: Update EpisodeENenable_updates=TrueEN: Refine existing episodes
CN: 更新EpisodeCN:CN: 优化已有的Episode

3.3 阶段3:反思与归纳 (Reflection & Induction) ★核心★

EN: This is the heart of “experience induction.” The Reflection Module:

CN: 这是“经验归纳”的核心。反思模块(Reflection Module)

  1. EN: Evaluates each episode for success or failure
    CN: 评估每个 Episode 是成功还是失败
  2. EN: Compares similar past episodes to identify generalizable patterns and principles
    CN: 比较相似的过往 Episode,识别可泛化的模式和原则
  3. EN: Distills reusable strategies rather than just replaying prior trajectories
    CN: 提炼可复用策略,而不仅仅是重放之前的轨迹

EN: For example:

CN: 例如:

成功Episode 1: 用 pandas chunking 处理 50GB CSV → 成功
成功Episode 2: 用 pandas chunking 处理 80GB Parquet → 成功
成功Episode 3: 用 pandas chunking 处理 120GB JSON → 成功

→ 反思归纳出模式: "处理大型数据集时,pandas + chunking 是可靠方案"
→ 可复用策略: "当数据量 > 10GB,使用 chunking 策略"

3.4 阶段4:经验复用 (Reuse)

EN: When a new task arrives:

CN: 当新任务到达时

  1. EN: Agent queries episodic memory: “Have I done something similar before?”
    CN: Agent 查询情景记忆:“我以前做过类似的事吗?”
  2. EN: Relevant past episodes are retrieved by semantic similarity
    CN: 通过语义相似度检索相关的过往 Episode
  3. EN: Agent adapts its plan based on outcomes of past episodes
    CN: Agent 根据过往 Episode 的结果调整自己的计划
  4. EN: New success/failure becomes a new episode → loop continues
    CN: 新的成功/失败成为新的 Episode → 循环继续

Key Takeaways

要点 (Aspect)ENCN
Episodic Memory定义Episodic memory stores complete experiences: what happened, what was thought, what was done, and what resulted情景记忆存储完整经历:发生了什么、想了什么、做了什么、结果如何
经验归纳Reflection module compares similar episodes to extract generalizable patterns反思模块比较相似Episode,提取可泛化的模式
经验复用New tasks retrieve similar past episodes and adapt plans based on outcomes新任务检索相似过往Episode,根据结果调整计划
Episode结构observation → thoughts → action → resultobservation → thoughts → action → result
语义 vs 情景Semantic = facts (“what”); Episodic = experiences (“how”)语义 = 事实(”是什么”);情景 = 经历(”怎么做”)
存储选型Vector database with semantic similarity + metadata filtering向量数据库 + 语义相似度 + 元数据过滤
核心价值Turns agent from stateless function into learning system that improves over time将Agent从无状态函数变成随时间持续改进的学习系统
LangMem工具Use create_memory_manager() with Episode schemas for extraction使用create_memory_manager()配合Episode结构进行提取
检索原则Retrieval works by relevance, not recency检索基于相关性,而非时间先后

Episodic Memory

Episodic Memory is a type of long-term memory that stores specific events, experiences, and interactions that an agent has encountered, indexed by time, context, and sequence. In cognitive science, episodic memory is the “what happened, where, and when” memory — it’s your personal diary of past experiences.

CN

情景记忆(Episodic Memory) 是一种长期记忆,用于存储智能体所经历过的具体事件、体验和交互,并按时间、上下文和序列进行索引。在认知科学中,情景记忆就是“发生了什么、在哪里、何时发生”的记忆——它是你个人经历的日记。

Imagine you’re a detective. Short-term memory is your notepad — you write down what the suspect just said. Semantic memory is your law book — facts and rules you’ve memorized. Episodic memory is your case file archive — every interrogation, every clue you found, every mistake you made, and what worked in past cases. When a new case comes in, you don’t just rely on the law book; you flip through your old case files to see how you solved similar cases before.

CN — 用人话比喻

想象你是一名侦探。短期记忆是你的记事本——你记下嫌疑人刚说的话。语义记忆是你的法律书——你记住的事实和规则。情景记忆是你的案件档案库——每一次审讯、每一条线索、每一个你犯过的错误、以及过去哪些方法有效。当新案件到来时,你不仅依赖法律书,还会翻阅旧案件档案,看看以前你是怎么解决类似案件的

2. What Does Historical Task Records Include?

EN

“Historical task records” (历史任务记录) is the practical implementation of episodic memory for task-oriented agents. It stores:

ComponentDescription
Task IDUnique identifier for each task
Task DescriptionWhat the user asked the agent to do
Actions TakenSequence of tool calls, reasoning steps, and decisions
OutcomeSuccess/failure, final result, error messages
TimestampWhen the task occurred
ContextUser ID, session ID, relevant metadata
EmbeddingVector representation for semantic retrieval

CN

“历史任务记录”是情景记忆在面向任务的智能体中的实践实现。它存储:

组件描述
任务ID每个任务的唯一标识符
任务描述用户要求智能体做什么
执行的动作工具调用序列、推理步骤和决策
结果成功/失败、最终结果、错误信息
时间戳任务发生的时间
上下文用户ID、会话ID、相关元数据
向量嵌入用于语义检索的向量表示

The Four Memory Operations (四原语) in Episodic Context

OperationENCN
StoreSave a completed task with its full trajectory保存已完成的任务及其完整轨迹
RecallRetrieve similar past tasks by semantic similarity通过语义相似度检索相似的过往任务
UpdateModify a stored record (e.g., mark as “deprecated”)修改已存储的记录(如标记为”已废弃”)
ForgetPrune old/low-value records by time or reward按时间或奖励值清理旧/低价值记录

3. Core Components of Episodic Memory System

Key Takeaways 

要点 (Key Point)ENCN
情景记忆的定义Episodic memory stores specific events, experiences, and interactions indexed by time and context情景记忆存储按时间和上下文索引的具体事件、经历和交互
历史任务记录的本质Historical task records are the practical implementation of episodic memory for task-oriented agents历史任务记录是情景记忆在面向任务的智能体中的实践实现
检索基于相关性而非新鲜度Recall works by relevance (semantic similarity), not recency回忆基于相关性(语义相似度)而非新鲜度
四原语操作Four memory operations: Store, Recall, Update, Forget四种记忆操作:存储、回忆、更新、遗忘
向量嵌入是检索的关键Embeddings enable semantic similarity search for relevant past experiences嵌入使得对相关过往经历的语义相似度搜索成为可能
失败也是重要的记忆Failed tasks often have HIGH importance because they teach the agent what NOT to do失败的任务通常具有高重要性,因为它们教会智能体”不要做什么”
跨会话连续性Episodic memory gives the agent continuity across sessions情景记忆给智能体提供跨会话的连续性
记忆清理策略Prune by time, keep newest N, or keep top by importance/reward按时间清理、保留最新的N条、或按重要性/奖励值保留最高分

Type of Memory System

Think of an AI Agent as a new employee at your data company. Without memory, this employee lives in a state of permanent “Groundhog Day.” Every time you speak to him, it’s his first day on the job. He doesn’t remember the SQL query you asked for 5 minutes ago, doesn’t remember your preference for partitioned tables, and certainly doesn’t remember the mistake he made last week.

What is “Memory” in an AI Agent?

In the context of AI and Large Language Models (LLMs), a Memory System is not a single component (like RAM in a computer). Instead, it is a multi-layered architectural framework designed to store, retrieve, and synthesize information across different timescales.

Memory is what turns a stateless API caller into a true, stateful agent. It enables continuity, personalization, and learning over time. Without it, every interaction is isolated; with it, the agent becomes a colleague that grows with you.

记忆是把一个“无状态 API 调用者”变成真正的“有状态 Agent”的关键。它实现了连续性、个性化和长期学习。没有记忆,每次交互都是孤立的;有了记忆,Agent 就变成了一位与你一同成长的同事。

 In cognitive architectures for LLMs, we classify memory into four distinct types, borrowing heavily from cognitive psychology (Atkinson-Shiffrin model) but adapted for software engineering.
CN: 在 LLM 的认知架构中,我们借鉴认知心理学(Atkinson-Shiffrin 模型)并将其适配到软件工程,将记忆划分为四种不同类型。

  1. Short-Term Memory (STM) – The immediate context window.
    短期记忆(STM) – 即时的上下文窗口。
  2. Long-Term Memory (LTM) – Permanent storage of facts and preferences.
    长期记忆(LTM) – 事实和偏好的永久存储。
  3. Episodic Memory – Memory of specific past events and interactions.
    情景记忆(Episodic Memory) – 对特定过去事件和交互的记忆。
  4. Semantic Memory – Memory of general world knowledge and structured concepts.
    语义记忆(Semantic Memory) – 对通用世界知识和结构化概念的记忆。

1. Short-Term Memory (STM) / Working Memory

This is the “scratchpad” of the agent. It holds whatever the LLM is currently processing. In practical terms, this is the Context Window combined with the current conversation turn.
CN: 这是 Agent 的“草稿纸”。它保存 LLM 当前正在处理的内容。在实际中,这就是 Context Window(上下文窗口) 加上当前的对话轮次。

Volatile, limited capacity (e.g., 128k tokens), and fast. It’s managed by the system prompt and the chat history.

易失性、容量有限(例如 128k tokens)、速度快。它由 System Prompt 和聊天历史管理。

Example: In a chat, the agent remembers your name because you just told it 2 messages ago. It remembers the user_id variable you passed in the current API call.
CN: 例子: 在聊天中,Agent 记得你的名字,因为你刚在 2 条消息前告诉过它。它记得你在当前 API 调用中传递的 user_id 变量。

2. Long-Term Memory (LTM)

This is the “hard drive” of the agent. It stores facts, user preferences, and configurations that persist across sessions (days, weeks, or months).
CN: 这是 Agent 的“硬盘”。它存储跨会话(数天、数周或数月)持久化的事实、用户偏好和配置。

 Characteristics: Persistent, high capacity, slower to access (requires a database query), and durable.
CN: 特点: 持久性、高容量、访问速度较慢(需要数据库查询)、耐用。

Example: The agent remembers that you always prefer parquet over csv, or that your company’s production database is postgres://prod-db:5432. This is stored in a PostgreSQL table keyed by your user_id.
CN: 例子: Agent 记得你总是更喜欢 parquet 而不是 csv,或者你公司的生产数据库是 postgres://prod-db:5432。这存储在按 user_id 索引的 PostgreSQL 表中。

3. Episodic Memory

This is the “diary” or “logbook” of the agent. It records specific, time-stamped past interactions, tasks completed, successes, and failures. It answers the question: “What happened previously?”
CN: 这是 Agent 的“日记”或“日志”。它记录具体的、带时间戳的过去交互、已完成的任务、成功和失败。它回答:“之前发生了什么?”

Characteristics: Chronological, specific, and context-rich. Used for error analysis, auditing, and experience reuse.
CN: 特点: 按时间顺序排列、具体、上下文丰富。用于错误分析、审计和经验复用。

 Example: “On July 15th at 3 PM, you asked me to generate a sales report, but I failed because the table sales_2023 was missing.” The agent recalls this specific failure to avoid repeating it or to suggest a fix.
CN: 例子: “在 7 月 15 日下午 3 点,你让我生成一份销售报告,但因为表 sales_2023 不存在,我失败了。” Agent 回忆起这个具体的失败,以避免重蹈覆辙或建议修复方案。

4. Semantic Memory

This is the “encyclopedia” of the agent. It stores general, factual, and conceptual knowledge about the world and your specific domain (like your company’s business logic), decoupled from specific experiences.
CN: 这是 Agent 的“百科全书”。它存储关于世界和你特定领域(如你公司的业务逻辑)的通用、事实性和概念性知识,与具体经历脱钩。

Characteristics: Factual, abstract, and structured. This is typically your RAG Knowledge Base.
CN: 特点: 事实性、抽象、结构化。这通常就是你的 RAG 知识库

Example: “The sales table is joined with customers on customer_id.” This is a fact about your data model. It is true regardless of who asked, or when.
CN: 例子: “sales 表通过 customer_id 与 customers 表关联。” 这是关于你数据模型的一个事实。无论谁问,或者什么时候问,它都是真的。

Summary Table of the Four Types

Memory TypeHuman AnalogyAI ImplementationPersistenceExample
Short-TermSticky Note / Scratchpadmessages array, Context WindowSession only (Volatile)Current chat conversation
Long-TermEmployee File / Hard DrivePostgreSQL / RedisPermanent (Years)“I prefer Python 3.11”
EpisodicPersonal Diary / LogsTime-series DB / Vector DBPermanent (Months/Years)“Last week, you asked for X and got error Y.”
SemanticEncyclopedia / WikiVector DB / Graph DBPermanent (Updated via RAG)“The Primary Key of orders is order_id.”

Key Takeaways Table

要点 (EN)要点 (CN)
Memory turns a stateless LLM into a stateful Agent.记忆将无状态 LLM 变为有状态 Agent。
STM is the current context window; manage it via sliding windows.短期记忆是当前上下文窗口;通过滑动窗口管理它。
LTM stores user preferences (key-value) in databases like PostgreSQL.长期记忆在 PostgreSQL 等数据库中存储用户偏好(键值对)。
Episodic is a chronological log of actions; use it for audit and learning.情景记忆是行动的时间顺序日志;用于审计和学习。
Semantic is general domain knowledge; typically powered by Vector DBs (RAG).语义记忆是通用领域知识;通常由向量数据库驱动(RAG)。
The build_system_context() method is where you integrate all four types for the LLM.build_system_context() 方法是整合所有四种记忆给 LLM 的地方。
In production, STM is ephemeral, LTM/Episodic/Semantic are persistent.在生产中,短期记忆是临时的,长期/情景/语义记忆是持久的。