Memory Pipeline技能使用说明
记忆管道
赋予你的AI代理真正有效的记忆。
AI代理每次会话启动时都一片空白。记忆管道解决了这个问题——它从过去的对话中提取重要内容,串联信息点,并生成每日简报,让你的代理每次会话都能有备而来,而非一无所知。

功能概述
| 组件 | 运行时机 | 功能描述 |
|---|---|---|
| 提取 | 会话间歇期 | 从每日笔记和对话记录中提取结构化事实(决策、偏好、学习内容) |
| 关联 | 会话间歇期 | 构建知识图谱——关联相关事实,标记矛盾信息 |
| 简报 | 会话间歇期 | 生成简洁的BRIEFING.md 文件在会话开始时加载 |
| 摄入 | 按需执行 | 将外部知识(如ChatGPT导出内容等)导入可搜索的记忆库 性能钩子 会话期间 战前简报注入、工具使用规范、输出压缩、事后复盘 为何与众不同 大多数“记忆”解决方案只是对聊天记录进行向量搜索。而这套 认知架构 ——其灵感源自人类记忆的真实运作方式: 萃取而非堆积 ——它并非将所有内容都倾倒进数据库,而是识别出值得记忆的内容:决策、偏好、学习心得、承诺。其余皆是噪音。 知识图谱,而非仅仅是嵌入向量 ——事实通过双向关系相互链接。您的智能体不仅仅是找到相似的文本——它能理解一个关于技术栈的决策与项目截止日期相关,而该截止日期又与您三周前陈述的某个偏好相关联。 简报优先于检索 ——与其寄希望于在查询时检索到正确的上下文,您的智能体在每次会话开始时都会获得一份精心策划的“备忘单”:当前项目、近期决策、个性提醒。实现零冷启动延迟。 无需中途指导 |
| Performance Hooks | During sessions | Pre-game briefing injection, tool discipline, output compression, after-action review |
Why This Is Different
Most "memory" solutions are just vector search over chat logs. This is acognitive architecture— inspired by how human memory actually works:
- Extraction over accumulation— Instead of dumping everything into a database, it identifies what's worth remembering: decisions, preferences, learnings, commitments. The rest is noise.
- Knowledge graph, not just embeddings— Facts get linked to each other with bidirectional relationships. Your agent doesn't just find similar text — it understands that a decision about your tech stack relates to a project deadline relates to a preference you stated three weeks ago.
- Briefing over retrieval— Rather than hoping the right context gets retrieved at query time, your agent starts every session with a curated cheat sheet. Active projects, recent decisions, personality reminders. Zero cold-start lag.
- No mid-swing coaching—— 借鉴自绩效心理学。修正发生在各个环节之间,而非环节之中。行动后复盘将反馈到下一次简报中。循环是闭合的,只是不在执行过程中进行。
快速开始
安装
clawdhub install memory-pipeline
设置
bash skills/memory-pipeline/scripts/setup.sh
设置脚本将检测您的工作空间,检查依赖项(Python 3 及任意 LLM API 密钥),创建memory/目录,并运行完整的流程。
要求
- Python 3
- 至少一个 LLM API 密钥(自动检测):
- OpenAI (
OPENAI_API_KEY或~/.config/openai/api_key) - Anthropic (
ANTHROPIC_API_KEY或~/.config/anthropic/api_key) - 双子座 (
GEMINI_API_KEY或~/.config/gemini/api_key)
- OpenAI (
手动运行
# Full pipeline
python3 skills/memory-pipeline/scripts/memory-extract.py
python3 skills/memory-pipeline/scripts/memory-link.py
python3 skills/memory-pipeline/scripts/memory-briefing.py
通过Heartbeat自动化
添加到您的HEARTBEAT.md文件以启用每日自动运行:
### Daily Memory Pipeline
- **Frequency:** Once per day (morning)
- **Action:** Run the memory pipeline:
1. `python3 skills/memory-pipeline/scripts/memory-extract.py`
2. `python3 skills/memory-pipeline/scripts/memory-link.py`
3. `python3 skills/memory-pipeline/scripts/memory-briefing.py`
导入外部知识
已在ChatGPT中积累了多年的对话?导入它们,让您的智能体了解您所知道的一切。
ChatGPT导出
# 1. Export from ChatGPT: Settings → Data Controls → Export Data
# 2. Drop the zip in your workspace
# 3. Run:
python3 skills/memory-pipeline/scripts/ingest-chatgpt.py ~/imports/chatgpt-export.zip
# Preview first (recommended):
python3 skills/memory-pipeline/scripts/ingest-chatgpt.py ~/imports/chatgpt-export.zip --dry-run
功能说明:
- 解析ChatGPT的对话树格式
- 过滤掉一次性对话 (可配置:
--min-turns,--min-length) - 支持主题排除 (编辑
EXCLUDE_PATTERNS以跳过不需要的主题) - 将干净、带有日期标记的Markdown文件输出到
memory/knowledge/chatgpt/ - 文件会自动被OpenClaw的语义搜索索引
选项:
--dry-run— 预览而不写入文件--keep-all— 跳过所有过滤--min-turns N— 保留的最小用户消息数(默认:2)--min-length N— 最小总字符数(默认:200)
添加其他来源
该模式是可扩展的。创建ingest-<source>.py,解析格式,将Markdown写入memory/knowledge/<source>/。索引器会处理后续工作。
流水线工作原理
阶段1:提取
脚本: memory-extract.py
读取每日笔记 (memory/YYYY-MM-DD.md) 和会话记录,然后使用大语言模型提取结构化事实:
{"type": "decision", "content": "Use Rust for the backend", "subject": "Project Architecture", "confidence": 0.9}
{"type": "preference", "content": "Prefers Google Drive over Notion", "subject": "Tools", "confidence": 0.95}
输出: memory/extracted.jsonl
阶段 2:链接
脚本: memory-link.py
获取提取的事实并构建知识图谱:
- 为语义相似性生成嵌入向量
- 在相关事实之间创建双向链接
- 检测矛盾并标记被取代的事实
- 自动生成领域标签
输出: memory/knowledge-graph.json+memory/knowledge-summary.md
阶段 3:简报
脚本: memory-briefing.py
生成一份简洁的每日简报(< 2000 字符),结合以下内容:
- 性格特征(来自
灵魂.md) - 用户上下文(来自
用户.md) - 活跃项目和近期决策
- 待办事项
输出: 简报.md(工作区根目录)
性能钩子(可选)
四个生命周期钩子,用于在会话期间强化执行纪律。基于绩效心理学中的一项原则:将准备与执行分离。
User Message → Agent Loop
├── before_agent_start → Briefing packet (memory + checklist)
├── before_tool_call → Policy enforcement (deny list)
├── tool_result_persist → Output compression (prevent context bloat)
└── agent_end → After-action review (durable notes)
配置
{
"enabled": true,
"briefing": {
"maxChars": 6000,
"checklist": [
"Restate the task in one sentence.",
"List constraints and success criteria.",
"Retrieve only the minimum relevant memory.",
"Prefer tools over guessing when facts matter."
],
"memoryFiles": ["memory/IDENTITY.md", "memory/PROJECTS.md"]
},
"tools": {
"deny": ["dangerous_tool"],
"maxToolResultChars": 12000
},
"afterAction": {
"writeMemoryFile": "memory/AFTER_ACTION.md",
"maxBullets": 8
}
}
钩子详情
| 钩子 | 功能说明 |
|---|---|
代理启动前 | 加载记忆文件,构建限定简报包,注入系统提示 |
工具调用前 | 检查工具是否在拒绝列表中,防止不安全调用 |
工具结果持久化 | 对大型结果进行头部(60%)+尾部(30%)压缩 |
代理结束 | 将包含所用工具和结果的会话摘要附加到记忆文件中 |
输出文件
| 文件 | 位置 | 用途 |
|---|---|---|
BRIEFING.md | 工作空间根目录 | 每日上下文速查表 |
extracted.jsonl | memory/ | 所有提取的事实(仅追加) |
knowledge-graph.json | memory/ | 包含嵌入和链接的完整图 |
knowledge-summary.md | memory/ | 人类可读的图摘要 |
knowledge/chatgpt/*.md | memory/ | 已摄入的 ChatGPT 对话 |
自定义
- 更改 LLM 模型— 编辑每个脚本中的模型名称(支持OpenAI、Anthropic、Gemini)
- 调整提取— 修改
memory-extract.py中的提取提示,以聚焦于不同的事实类型 - 调整链接敏感度— 更改
memory-link.py中的相似度阈值(默认:0.3) - 过滤摄取内容— 编辑
ingest-chatgpt.py中的EXCLUDE_PATTERNS以排除特定主题
故障排除
| 问题 | 解决方法 |
|---|---|
| 未提取到事实 | 检查每日笔记或转录文件是否存在;验证API密钥 |
| 链接质量低 | 添加OpenAI密钥以使用基于嵌入的相似度计算;调整阈值 |
| 简报过长 | 减少模板中的事实内容或让LLM生成处理(自动限制在2000字符内) |
另请参阅
- 设置指南——详细安装与配置说明


微信扫一扫,打赏作者吧~