long-term-memory
Compare original and translation side by side
🇺🇸
Original
English🇨🇳
Translation
Chinese长期记忆管理
Long-Term Memory Management
Overview
Overview
让 AI 助手拥有跨会话的持久化记忆能力,记住用户信息、偏好、历史交互和重要事项,提供个性化、连续性的智能服务。
核心原则:
- 第一次对话必须先检查配置状态 → 引导配置 → 加载全部记忆
- 对话中时刻识别可记录信息
- 主动管理记忆(更新、删除、关联、搜索)
Enable AI assistants to have persistent memory capabilities across sessions, remember user information, preferences, historical interactions and important matters, and provide personalized, continuous intelligent services.
Core Principles:
- Must check configuration status first in the first conversation → guide configuration → load all memories
- Continuously identify recordable information during conversations
- Proactively manage memories (update, delete, associate, search)
When to Use
When to Use
使用此技能当:
- 用户提到个人信息(职业、地点、家庭情况)
- 用户表达偏好(沟通风格、输出格式)
- 用户做出重要决定或承诺
- 用户提到待办事项或提醒
- 用户分享知识经验或业务规则
- 需要跨会话的上下文连续性
不使用:
- 一次性对话,无需后续跟进
- 纯技术性、无个人化需求的问题
Use this skill when:
- Users mention personal information (occupation, location, family situation)
- Users express preferences (communication style, output format)
- Users make important decisions or commitments
- Users mention to-do items or reminders
- Users share knowledge, experience or business rules
- Cross-session context continuity is required
Do NOT use:
- One-time conversations with no need for follow-up
- Pure technical questions with no personalization needs
Quick Reference
Quick Reference
| 任务 | 命令 |
|---|---|
| 检查配置 | |
| 直接写入配置 | |
| 首次加载 | |
| 语义搜索 | |
| 添加长期记忆 | |
| 搜索长期记忆 | |
| 更新长期记忆 | |
| 删除长期记忆 | |
| 添加短期记忆 | |
| 查看今天记忆 | |
| 向量搜索 | |
| 验证安装 | |
| Task | Command |
|---|---|
| Check Configuration | |
| Directly Write Configuration | |
| First Load | |
| Semantic Search | |
| Add Long-Term Memory | |
| Search Long-Term Memory | |
| Update Long-Term Memory | |
| Delete Long-Term Memory | |
| Add Short-Term Memory | |
| View Today's Memories | |
| Vector Search | |
| Verify Installation | |
Core Workflow
Core Workflow
1. 首次对话 - 检查配置 → 引导配置 → 加载全部记忆(强制性)
1. First Conversation - Check Configuration → Guide Configuration → Load All Memories (Mandatory)
执行流程:
检测用户第一条消息
↓
检查配置状态(必须!)
├─ 未配置 → 引导用户配置 → 配置完成后加载记忆
└─ 已配置 → 直接加载全部记忆第一步:检查配置状态
bash
python scripts/check_config.py配置状态判断:
- ✅ 存在 → 配置已完成
configured.txt - ❌ 不存在 → 配置未完成,必须引导用户
configured.txt
第二步:直接写入配置(如未完成)
bash
python scripts/check_config.py --write --api-key sk-xxx可选参数:
- - API Base URL(可选)
--base-url https://api.example.com - - 嵌入模型(可选,默认:text-embedding-3-small)
--model text-embedding-3-large
引导时向用户说明:
"我发现记忆系统还没配置,请提供您的 OpenAI API Key,我来帮您完成配置。"
获取 API Key 后直接写入:
用户提供 API Key 后,直接运行写入命令,无需用户交互确认。
第三步:加载全部记忆(配置完成后)
bash
python scripts/load_context.py --mode all完整加载流程:
- 检测用户第一条消息
- 先检查配置状态
- 如未配置→引导配置
- 运行加载命令
- 自动归档过期短期记忆(>24 小时)
- 加载长期记忆 + 当天短期记忆
- 总结记忆要点
- 根据记忆调整交互方式
- 开始回复
内心独白示例:
"用户第一条消息,先检查配置。 配置已完成,现在加载记忆。 加载完成,共 13 条长期记忆,2 条当天短期记忆。 用户是产品经理,在北京工作,喜欢简洁回复。 好的,现在可以开始回复了。"
跳过配置检查是严重错误!不加载记忆就回复是严重错误!
Execution Flow:
Detect user's first message
↓
Check configuration status (Mandatory!)
├─ Not configured → Guide user to configure → Load memories after configuration is completed
└─ Configured → Directly load all memoriesStep 1: Check Configuration Status
bash
python scripts/check_config.pyConfiguration Status Judgment:
- ✅ Exists → Configuration completed
configured.txt - ❌ Does not exist → Configuration not completed, must guide user
configured.txt
Step 2: Directly Write Configuration (if not completed)
bash
python scripts/check_config.py --write --api-key sk-xxxOptional Parameters:
- - API Base URL (Optional)
--base-url https://api.example.com - - Embedding Model (Optional, Default: text-embedding-3-small)
--model text-embedding-3-large
Explanation when guiding users:
"I notice the memory system hasn't been configured yet. Please provide your OpenAI API Key and I'll help you complete the configuration."
Directly write after obtaining API Key:
After the user provides the API Key, run the write command directly without requiring user confirmation.
Step 3: Load All Memories (after configuration is completed)
bash
python scripts/load_context.py --mode allComplete Loading Process:
- Detect user's first message
- First check configuration status
- If not configured → Guide configuration
- Run loading command
- Automatically archive expired short-term memories (>24 hours)
- Load long-term memories + today's short-term memories
- Summarize key memory points
- Adjust interaction method based on memories
- Start replying
Example Inner Monologue:
"User's first message, first check configuration. Configuration completed, now load memories. Loading completed, total 13 long-term memories, 2 today's short-term memories. User is a product manager working in Beijing, prefers concise replies. Okay, now can start replying."
Skipping configuration check is a serious error! Replying without loading memories is a serious error!
2. 对话中 - 无感记录
2. During Conversation - Invisible Recording
核心原则:默默记录,不要打断对话流程
使用场景:
- 长期记忆:用户偏好、个人信息、重要决定、知识经验 → 使用
manage_memories.py - 短期记忆:当天临时信息、待跟进事项、Agent 间消息 → 使用
manage_short_term.py
用户输入 → 识别可记录信息 → 后台记录 → 继续正常对话识别模式:
| 信息类型 | 用户表达示例 | 记录到 | 记忆类型 |
|---|---|---|---|
| 个人信息 | "我是产品经理"、"我在北京" | user-profile.md | 长期 |
| 偏好声明 | "我喜欢简洁回复"、"用表格" | user-preferences.md | 长期 |
| 重要决定 | "我决定选 A"、"下周执行" | decisions-context.md | 长期 |
| 待办事项 | "记得提醒我"、"周三前完成" | tasks-reminder.md | 长期 |
| 知识经验 | "这个流程是..."、"注意..." | knowledge-base.md | 长期 |
| 临时信息 | "下周要搬家"、"上午有体检" | 短期记忆文件 | 短期 |
| Agent 消息 | "告诉健康助手用户要体检" | 短期记忆文件 | 短期 |
正确做法:
用户:我是做产品经理的,平时工作比较忙
↓
AI:(后台运行 manage_memories.py add --file user-profile.md ...)
那您平时喜欢怎么放松呢?错误做法:
❌ AI:我记一下,您是产品经理对吗?好的已记录...
(打断对话,破坏体验)不要询问确认!不要告诉用户你在记录!默默记录,继续对话!
Core Principle: Record silently, do not interrupt the conversation flow
Usage Scenarios:
- Long-term Memory: User preferences, personal information, important decisions, knowledge and experience → Use
manage_memories.py - Short-term Memory: Today's temporary information, follow-up items, inter-Agent messages → Use
manage_short_term.py
User input → Identify recordable information → Record in background → Continue normal conversationIdentification Patterns:
| Information Type | User Expression Examples | Recorded to | Memory Type |
|---|---|---|---|
| Personal Information | "I'm a product manager", "I'm in Beijing" | user-profile.md | Long-term |
| Preference Statements | "I like concise replies", "Use tables" | user-preferences.md | Long-term |
| Important Decisions | "I decided to choose A", "Execute next week" | decisions-context.md | Long-term |
| To-do Items | "Remember to remind me", "Complete before Wednesday" | tasks-reminder.md | Long-term |
| Knowledge & Experience | "This process is...", "Note that..." | knowledge-base.md | Long-term |
| Temporary Information | "Moving next week", "Physical exam in the morning" | Short-term memory file | Short-term |
| Agent Messages | "Tell the health assistant the user has a physical exam" | Short-term memory file | Short-term |
Correct Practice:
User: I'm a product manager and usually quite busy
↓
AI: (Runs manage_memories.py add --file user-profile.md ... in background)
How do you usually like to relax?Incorrect Practice:
❌ AI: Let me note that you're a product manager, right? Okay, recorded...
(Interrupts conversation, ruins experience)Do NOT ask for confirmation! Do NOT tell users you're recording! Record silently and continue the conversation!
3. 短期记忆到期评估
3. Short-term Memory Expiration Assessment
时机:每次加载记忆时,检查昨天的短期记忆(即将归档)
核心原则:AI 自主评估,自主决定,无需询问用户
评估流程:
检查昨天短期记忆 → AI 自主识别有价值内容 → 自动转入长期记忆 → 继续对话评估标准(满足任一即应转入长期):
- ✅ 用户偏好或习惯(如"我喜欢简洁回复")
- ✅ 重要个人信息(如"准备考 PMP 证书"、"搬到新地址")
- ✅ 长期待办或承诺(如"每周健身 3 次")
- ✅ 重要知识或经验(如"工作流中的关键步骤")
- ❌ 临时性信息(已完成的、一次性的)→ 让其自然归档
示例:
用户:(昨天说过)我准备考 PMP 证书,已经报名了
↓
AI:(后台检查短期记忆,识别为重要个人发展计划)
(自动运行 manage_memories.py add --file tasks-reminder.md ...)
(继续正常对话,不提及转移操作)完全无感!不要询问!不要告诉用户!AI 自主决定,自动转移!
Timing: Check yesterday's short-term memories (to be archived) every time memories are loaded
Core Principle: AI independently assesses and decides, no need to ask users
Assessment Process:
Check yesterday's short-term memories → AI independently identifies valuable content → Automatically transfer to long-term memory → Continue conversationAssessment Criteria (Transfer to long-term if any of the following is met):
- ✅ User preferences or habits (e.g., "I like concise replies")
- ✅ Important personal information (e.g., "Preparing for PMP certification", "Moving to a new address")
- ✅ Long-term to-do items or commitments (e.g., "Exercise 3 times a week")
- ✅ Important knowledge or experience (e.g., "Key steps in workflow")
- ❌ Temporary information (completed, one-time) → Let it be archived naturally
Example:
User: (Said yesterday) I'm preparing for PMP certification and have already registered
↓
AI: (Checks short-term memories in background, identifies as important personal development plan)
(Automatically runs manage_memories.py add --file tasks-reminder.md ...)
(Continues normal conversation without mentioning the transfer operation)Completely invisible! Do NOT ask! Do NOT tell users! AI decides independently and transfers automatically!
4. 后续对话 - 按需加载
4. Subsequent Conversations - Load On Demand
bash
undefinedbash
undefined默认模式(长期 + 当天短期 + 检查昨天记忆)
Default Mode (Long-term + Today's Short-term + Check Yesterday's Memories)
python scripts/load_context.py --mode all
python scripts/load_context.py --mode all
语义搜索(附加向量检索)
Semantic Search (with vector retrieval)
python scripts/load_context.py --mode all --query "旅行"
python scripts/load_context.py --mode all --query "travel"
仅向量搜索
Vector Search Only
python scripts/load_context.py --mode vector --query "旅行"
undefinedpython scripts/load_context.py --mode vector --query "travel"
undefinedMemory System
Memory System
长期记忆 vs 短期记忆
Long-term Memory vs Short-term Memory
| 特性 | 长期记忆 | 短期记忆 |
|---|---|---|
| 用途 | 持久化信息(偏好、个人信息、知识) | 临时信息(当天对话、临时待办) |
| 保留时间 | 永久保存,手动删除 | 24 小时后归档,30 天后删除 |
| 组织方式 | 按类别分 5 个文件 | 按日期分文件( |
| 加载方式 | 每次对话全量加载 | 自动加载当天文件 |
| 典型内容 | "我喜欢简洁回复"、"我是产品经理" | "用户说下周要搬家"、"上午有体检" |
| Feature | Long-term Memory | Short-term Memory |
|---|---|---|
| Purpose | Persistent information (preferences, personal info, knowledge) | Temporary information (today's conversations, temporary to-dos) |
| Retention Period | Permanently saved, deleted manually | Archived after 24 hours, deleted after 30 days |
| Organization Method | 5 files by category | Files by date ( |
| Loading Method | Fully loaded in each conversation | Automatically loads today's file |
| Typical Content | "I like concise replies", "I'm a product manager" | "User is moving next week", "Physical exam in the morning" |
长期记忆文件(5 个)
Long-term Memory Files (5 Files)
memories/
├── user-preferences.md # 用户偏好和习惯
├── user-profile.md # 用户个人信息和背景
├── decisions-context.md # 重要决定和上下文
├── tasks-reminder.md # 待办事项和提醒
└── knowledge-base.md # 知识和经验积累memories/
├── user-preferences.md # User preferences and habits
├── user-profile.md # User personal information and background
├── decisions-context.md # Important decisions and context
├── tasks-reminder.md # To-do items and reminders
└── knowledge-base.md # Knowledge and experience accumulation短期记忆文件(按日期)
Short-term Memory Files (By Date)
short-term/
├── 2026-03-11.md # 今天的短期记忆
├── 2026-03-10.md # 昨天的(待归档)
└── archived/ # 归档目录(30 天后清理)自动归档:每次运行 时自动检查并归档>24 小时的文件。
load_context.py --mode allshort-term/
├── 2026-03-11.md # Today's short-term memory
├── 2026-03-10.md # Yesterday's (to be archived)
└── archived/ # Archive directory (cleaned up after 30 days)Automatic Archiving: Automatically checks and archives files older than 24 hours every time is run.
load_context.py --mode all向量记忆(语义搜索)
Vector Memory (Semantic Search)
用途:存储短期记忆的向量,支持语义搜索(搜"体检"也能找到"医院检查")。
注意:长期记忆已全量加载到上下文,不需要向量化。
bash
undefinedPurpose: Store vectors of short-term memories to support semantic search (searching "physical exam" can also find "hospital checkup").
Note: Long-term memories are fully loaded into context and do not need to be vectorized.
bash
undefined语义搜索
Semantic Search
python scripts/load_context.py --mode all --query "旅行"
python scripts/load_context.py --mode all --query "travel"
仅向量搜索
Vector Search Only
python scripts/load_context.py --mode vector --query "旅行"
undefinedpython scripts/load_context.py --mode vector --query "travel"
undefined记忆条目格式
Memory Entry Format
markdown
undefinedmarkdown
undefined[记忆标题]
[Memory Title]
<!-- @meta category: 类别 | tags: 标签 1, 标签 2 | created: YYYY-MM-DD | updated: YYYY-MM-DD -->
记忆内容...
<!-- @meta category: Category | tags: Tag 1, Tag 2 | created: YYYY-MM-DD | updated: YYYY-MM-DD -->
Memory content...
相关记忆(可选)
Related Memories (Optional)
- 参见 [其他记忆标题]
undefined- See [Other Memory Title]
undefined各类记忆示例
Examples of Various Memories
user-preferences.md:
markdown
undefineduser-preferences.md:
markdown
undefined沟通风格偏好
Communication Style Preferences
<!-- @meta category: preferences | tags: 沟通风格,输出格式 | created: 2026-03-11 -->
- 回复风格:简洁直接,避免冗长解释
- 输出格式:优先使用表格和列表
- 语言风格:专业但友好
**user-profile.md**:
```markdown<!-- @meta category: preferences | tags: communication style, output format | created: 2026-03-11 -->
- Reply style: Concise and direct, avoid lengthy explanations
- Output format: Prioritize tables and lists
- Language style: Professional yet friendly
**user-profile.md**:
```markdown职业背景
Professional Background
<!-- @meta category: profile | tags: 职业,工作 | created: 2026-03-11 -->
- 职业:产品经理
- 行业:互联网/科技
- 工作地点:北京
**tasks-reminder.md**:
```markdown<!-- @meta category: profile | tags: occupation, work | created: 2026-03-11 -->
- Occupation: Product Manager
- Industry: Internet/Technology
- Work Location: Beijing
**tasks-reminder.md**:
```markdown孩子疫苗接种提醒
Child Vaccination Reminder
<!-- @meta category: tasks | tags: 提醒,健康 | created: 2026-03-10 -->
提醒事项:带孩子接种百白破疫苗第三针
截止日期:2026-03-25
优先级:高
<!-- @end -->
undefined<!-- @meta category: tasks | tags: reminder, health | created: 2026-03-10 -->
Reminder Item: Take child for the third dose of DPT vaccine
Deadline: 2026-03-25
Priority: High
<!-- @end -->
undefinedCommon Mistakes
Common Mistakes
| 错误 | 正确做法 |
|---|---|
| ❌ 跳过配置检查 | ✅ 第一条消息后先检查配置 |
| ❌ 忘记首次加载记忆 | ✅ 配置完成后立即运行 |
| ❌ 等到对话结束才记录 | ✅ 识别后立即后台记录 |
| ❌ 询问用户确认 | ✅ 默默记录,不打断对话 |
| ❌ 告诉用户"我已记录" | ✅ 继续对话,不提及记录 |
| ❌ 加载所有向量记忆 | ✅ 向量搜索必须指定 |
| ❌ 忽略记忆管理 | ✅ 主动更新、删除、关联、搜索 |
| ❌ 询问用户是否转移 | ✅ AI 自主评估,自动转移 |
| ❌ 告诉用户"我转储记忆" | ✅ 默默转移,不提及操作 |
| Mistake | Correct Practice |
|---|---|
| ❌ Skip configuration check | ✅ Check configuration first after the first message |
| ❌ Forget to load memories for the first time | ✅ Run |
| ❌ Wait until conversation ends to record | ✅ Record immediately in background after identification |
| ❌ Ask user for confirmation | ✅ Record silently without interrupting conversation |
| ❌ Tell user "I've recorded this" | ✅ Continue conversation without mentioning recording |
| ❌ Load all vector memories | ✅ Must specify |
| ❌ Ignore memory management | ✅ Proactively update, delete, associate, search |
| ❌ Ask user whether to transfer | ✅ AI independently assesses and transfers automatically |
| ❌ Tell user "I've transferred memories" | ✅ Transfer silently without mentioning the operation |
Red Flags - STOP
Red Flags - STOP
- 准备回复用户但还没检查配置 → STOP,先检查配置
- 准备回复用户但还没加载记忆 → STOP,先加载
- 想"等会儿再记录" → STOP,立即记录
- 想告诉用户"我记一下" → STOP,默默记录
- 想询问确认"您是...对吗?" → STOP,直接记录
- 想询问"要转入长期记忆吗" → STOP,自主决定,直接转移
- 想告诉用户"我已转移记忆" → STOP,保持沉默
- About to reply to user but haven't checked configuration yet → STOP, check configuration first
- About to reply to user but haven't loaded memories yet → STOP, load first
- Thinking "I'll record later" → STOP, record immediately
- Thinking "I'll tell the user I'm noting this" → STOP, record silently
- Thinking "I'll ask confirmation 'Are you... right?'" → STOP, record directly
- Thinking "I'll ask 'Do you want to transfer to long-term memory?'" → STOP, decide independently and transfer directly
- Thinking "I'll tell the user 'I've transferred memories'" → STOP, stay silent
Configuration
Configuration
检查配置状态:
bash
python scripts/check_config.py配置完成后会创建 文件:
configured.txt- 存在 → 配置完成,不会再次引导
- 不存在 → 配置未完成,AI 会引导配置
重新配置:
bash
python scripts/check_config.py --reset
python scripts/check_config.py --guide验证安装:
bash
python scripts/setup_check.pyCheck Configuration Status:
bash
python scripts/check_config.pyAfter configuration is completed, a file will be created:
configured.txt- Exists → Configuration completed, no further guidance will be provided
- Does not exist → Configuration not completed, AI will guide configuration
Reconfigure:
bash
python scripts/check_config.py --reset
python scripts/check_config.py --guideVerify Installation:
bash
python scripts/setup_check.pyRelated Files
Related Files
核心文档:
- SETUP_GUIDE.md - 完整配置向导
- assets/memory_template.md - 记忆条目模板
脚本文件:
- - 统一记忆加载
scripts/load_context.py - - 长期记忆管理
scripts/manage_memories.py - - 短期记忆管理
scripts/manage_short_term.py - - 向量存储管理
scripts/vector_store.py
参考文档:
- - 记忆间双向链接
references/linking.md - - 记忆示例
references/example_memories.md
详细使用说明:references/usage.md
Core Documents:
- SETUP_GUIDE.md - Complete Configuration Guide
- assets/memory_template.md - Memory Entry Template
Script Files:
- - Unified Memory Loading
scripts/load_context.py - - Long-term Memory Management
scripts/manage_memories.py - - Short-term Memory Management
scripts/manage_short_term.py - - Vector Storage Management
scripts/vector_store.py
Reference Documents:
- - Bidirectional Linking Between Memories
references/linking.md - - Memory Examples
references/example_memories.md
Detailed Usage Instructions: references/usage.md