跨会话记忆传承,AI不再遗忘
简介
三层持久化记忆系统让AI跨会话记住决策、事实与规则,解决LLM失忆问题,实现真正的长期学习与知识传承。
原始描述
Three-layer persistent memory system (Markdown + ChromaDB vectors + NetworkX knowledge graph) for long-term agent recall across sessions. One-command setup w...
通过你的 Agent 添加
安装目录:persistent-memory/(目录名取自 SKILL.md 的 frontmatter name,不是 URL 里的 slug)。
点「快速安装」复制一段指令贴给你的 Agent:它会先下载到 /tmp、把文件清单和校验值给你看,你确认之后才解压安装。不会一步装完、也不改系统其它位置。
或者手动安装
包是「根级 SKILL.md + 作者附带的文件」,解压到上面的 <slug>/ 目录即可;
目录名不用换,也不要把包直接解压到 skills 根目录。
技能申请的权限由作者决定:装之前先看清单里有没有脚本、它会读写什么。
中文使用说明 来自收录源
核心用法
persistent-memory 是一套企业级三层记忆架构,专为解决AI Agent的跨会话遗忘问题而设计。系统通过一键部署脚本(unified_setup.sh)自动构建:
- L1 Markdown层:人类可读的
MEMORY.md、每日日志memory/YYYY-MM-DD.md及reference/知识库,作为真相源 - L2 向量层:ChromaDB + all-MiniLM-L6-v2模型实现语义搜索,支持自然语言检索历史决策
- L3 图谱层:NetworkX构建概念关系网络,支持关系遍历推理
关键创新在于configure_openclaw.py脚本——它强制OpenClaw索引SOUL.md、AGENTS.md等关键指令文件,根治「Agent无视自身规则」的行业顽疾。
显著优点
- 零配置开箱即用:单条bash命令完成Python依赖、虚拟环境、数据库、IDE集成全链路部署
- 指令合规自动化:突破OpenClaw默认索引限制,确保行为准则被强制检索
- 三层冗余保障:任何单点故障不会导致记忆丢失,Markdown层始终可人工修复
- 语义+结构化双检索:既能模糊匹配概念,也能精准查询实体关系
- 生产级监控:
auto_retrieve.py --status提供版本哈希校验,防止记忆漂移
潜在局限
- 架构耦合性:强依赖OpenClaw生态,其他Agent框架需适配改造
- 本地存储限制:ChromaDB默认文件存储,高并发场景需迁移至服务器模式
- 索引延迟:手动触发
indexer.py,无实时监听(可配合inotify改进)
- 模型固定:sentence-transformers模型锁死,无法热切换多语言/领域专用模型
适合人群
- 长期运行项目的AI辅助开发团队(需跨周/月保持上下文)
- 企业知识库构建场景(合规审计要求决策可追溯)
- 多Agent协作系统(需共享机构记忆与行为准则)
- 对「AI幻觉导致违规操作」高度敏感的金融、医疗、法务领域
常规风险
风险类型
描述
缓解措施
记忆污染
错误信息被索引后持续传播
定期审核MEMORY.md,版本控制回溯
指令绕过
OpenClaw配置被意外覆盖
将configure_openclaw.py纳入CI检查
隐私泄露
reference/people.md含敏感联系信息
.gitignore配置+加密存储PII
索引损坏
SIGSEGV等ML库兼容性问题
使用脚本固定依赖版本,定期--status校验
依赖过时
ChromaDB/NetworkX版本迭代
锁定requirements.txt,计划性升级测试
auto_retrieve.py --status提供版本哈希校验,防止记忆漂移- 架构耦合性:强依赖OpenClaw生态,其他Agent框架需适配改造
- 本地存储限制:ChromaDB默认文件存储,高并发场景需迁移至服务器模式
- 索引延迟:手动触发
indexer.py,无实时监听(可配合inotify改进) - 模型固定:sentence-transformers模型锁死,无法热切换多语言/领域专用模型
适合人群
- 长期运行项目的AI辅助开发团队(需跨周/月保持上下文)
- 企业知识库构建场景(合规审计要求决策可追溯)
- 多Agent协作系统(需共享机构记忆与行为准则)
- 对「AI幻觉导致违规操作」高度敏感的金融、医疗、法务领域
常规风险
风险类型
描述
缓解措施
记忆污染
错误信息被索引后持续传播
定期审核MEMORY.md,版本控制回溯
指令绕过
OpenClaw配置被意外覆盖
将configure_openclaw.py纳入CI检查
隐私泄露
reference/people.md含敏感联系信息
.gitignore配置+加密存储PII
索引损坏
SIGSEGV等ML库兼容性问题
使用脚本固定依赖版本,定期--status校验
依赖过时
ChromaDB/NetworkX版本迭代
锁定requirements.txt,计划性升级测试
| 风险类型 | 描述 | 缓解措施 |
|---|---|---|
| 记忆污染 | 错误信息被索引后持续传播 | 定期审核MEMORY.md,版本控制回溯 |
| 指令绕过 | OpenClaw配置被意外覆盖 | 将configure_openclaw.py纳入CI检查 |
| 隐私泄露 | reference/people.md含敏感联系信息 |
.gitignore配置+加密存储PII |
| 索引损坏 | SIGSEGV等ML库兼容性问题 | 使用脚本固定依赖版本,定期--status校验 |
| 依赖过时 | ChromaDB/NetworkX版本迭代 | 锁定requirements.txt,计划性升级测试 |
技能正文
name: persistent-memory
version: 3.0.0
description: Three-layer persistent memory system (Markdown + ChromaDB vectors + NetworkX knowledge graph) for long-term agent recall across sessions. One-command setup with automatic OpenClaw integration. Use when the agent needs to remember decisions, facts, context, or institutional knowledge between sessions.
Persistent Memory
Adds persistent three-layer memory to any OpenClaw workspace. The agent gains semantic recall across sessions — decisions, facts, lessons, and institutional knowledge survive restarts.
Architecture
Layer
Technology
Purpose
L1: Markdown
MEMORY.md + daily logs + reference/
Human-readable curated knowledge
L2: Vector
ChromaDB + all-MiniLM-L6-v2
Semantic search across all memories
L3: Graph
NetworkX
Relationship traversal between concepts
| Layer | Technology | Purpose |
|---|---|---|
| L1: Markdown | MEMORY.md + daily logs + reference/ | Human-readable curated knowledge |
| L2: Vector | ChromaDB + all-MiniLM-L6-v2 | Semantic search across all memories |
| L3: Graph | NetworkX | Relationship traversal between concepts |
All three layers sync together. The indexer updates L2 and L3 from L1 automatically.
⚠️ Critical Integration: OpenClaw Memory Configuration
Problem: OpenClaw has its own built-in memory search system, but by default it only indexes MEMORY.md and memory/*.md files. Critical workspace files like SOUL.md (agent directives), AGENTS.md (behavior rules), and PROJECTS.md (active work) are ignored.
Impact: Agents can violate explicit directives because they're not found in memory searches. This causes operational failures where agents ignore their own rules.
Solution: The configure_openclaw.py script adds a memorySearch configuration block to OpenClaw that indexes all critical workspace files. This makes directive compliance automatic rather than optional.
Setup
One command from workspace root:
bash skills/persistent-memory/scripts/unified_setup.sh
This automatically:
- ✅ Creates 3-layer memory system (Markdown + Vector + Graph)
- ✅ Installs all Python dependencies (ChromaDB, NetworkX, sentence-transformers)
- ✅ Configures OpenClaw memorySearch integration (directive compliance)
- ✅ Indexes existing MEMORY.md if present
- ✅ Sets up daily maintenance automation
No manual configuration needed. The script handles everything including OpenClaw integration that prevents agents from ignoring workspace directives (SOUL.md, AGENTS.md, etc.).
Daily Usage
Writing Memories
- MEMORY.md — Curated long-term knowledge (decisions, architecture, lessons learned). Update after significant events.
- memory/YYYY-MM-DD.md — Daily logs. Raw notes of what happened each day.
- reference/*.md — Institutional facts (people, repos, infrastructure, business rules). The agent's encyclopedia.
Indexing (after editing any memory file)
vector_memory/venv/bin/python vector_memory/indexer.py
vector_memory/venv/bin/python vector_memory/indexer.py
The indexer parses MEMORY.md, reference/.md, and memory/.md into vector embeddings and rebuilds the knowledge graph. Run after every edit to keep layers in sync.
Searching
vector_memory/venv/bin/python vector_memory/search.py "your query"
vector_memory/venv/bin/python vector_memory/search.py "your query"
Returns top-3 semantically similar chunks with source file and section.
Sync Status Check
vector_memory/venv/bin/python vector_memory/auto_retrieve.py --status
vector_memory/venv/bin/python vector_memory/auto_retrieve.py --status
Reports sync health: MEMORY.md hash vs indexed state, chunk count, graph size. Use in heartbeats to detect drift.
Agent Behavior Rules
Add these to AGENTS.md or SOUL.md:
Pre-Response (mandatory)
Before answering questions about prior work, decisions, dates, people, or preferences — search memory first. Use memory_search or run auto_retrieve.py with the query. Never say "I don't remember" without checking.
CRITICAL: OpenClaw's built-in memory search should now automatically find directive files (SOUL.md, AGENTS.md) if configure_openclaw.py was run. If memory searches are not finding agent rules or workspace directives, the OpenClaw integration is missing or broken.
Pre-Action (mandatory)
Before executing any action that references an external identifier (URL, handle, email, repo name, address) — query reference/ files for the exact value. If not found, query vector memory. If still not found, ask the user. Never fabricate identifiers.
Post-Edit (mandatory)
After editing MEMORY.md or any file in reference/ or memory/ — re-index:
vector_memory/venv/bin/python vector_memory/indexer.py
Heartbeat Integration
Add to HEARTBEAT.md:
## Memory Sync Check
Run `vector_memory/venv/bin/python vector_memory/auto_retrieve.py --status` and if status is OUT_OF_SYNC, re-index with `vector_memory/venv/bin/python vector_memory/indexer.py`.
Reference Directory (Optional but Recommended)
Create reference/ in the workspace root as the agent's institutional knowledge base:
reference/
├── people.md — Contacts, roles, communication details
├── repos.md — GitHub repositories, URLs, status
├── infrastructure.md — Hosts, IPs, ports, services
├── business.md — Company info, strategies, rules
└── properties.md — Domain-specific entities (deals, products, etc.)
These files are vector-indexed alongside MEMORY.md. The agent queries them before any action involving external identifiers. Facts accumulate over time — the agent that never forgets.
File Structure After Setup
workspace/
├── MEMORY.md — Curated long-term memory (L1)
├── memory/
│ ├── 2026-02-17.md — Daily log
│ └── heartbeat-state.json — Sync tracking
├── reference/ — Institutional knowledge (optional)
│ ├── people.md
│ └── ...
└── vector_memory/
├── indexer.py — Index all markdown into vectors + graph
├── search.py — Semantic search CLI
├── graph.py — NetworkX knowledge graph
├── auto_retrieve.py — Status checker + auto-retrieval
├── chroma_db/ — Vector database (gitignored)
├── memory_graph.json — Knowledge graph (auto-generated)
└── venv/ — Python venv (gitignored)
Troubleshooting
- "No module named chromadb" — Run setup.sh again or activate the venv:
source vector_memory/venv/bin/activate
- OUT_OF_SYNC status — Run the indexer:
vector_memory/venv/bin/python vector_memory/indexer.py
- Empty search results — Check that MEMORY.md has content and the indexer has been run at least once
- SIGSEGV on indexing — Usually caused by incompatible ML libs. The setup script pins known-good versions.
- Agent ignoring SOUL.md/AGENTS.md directives — OpenClaw integration missing. Run
python skills/persistent-memory/scripts/configure_openclaw.py to fix.
- Memory searches not finding workspace files — Check OpenClaw configuration:
openclaw config get | grep memorySearch
- "Configuration verification failed" — Restart OpenClaw manually:
openclaw gateway restart
workspace/
├── MEMORY.md — Curated long-term memory (L1)
├── memory/
│ ├── 2026-02-17.md — Daily log
│ └── heartbeat-state.json — Sync tracking
├── reference/ — Institutional knowledge (optional)
│ ├── people.md
│ └── ...
└── vector_memory/
├── indexer.py — Index all markdown into vectors + graph
├── search.py — Semantic search CLI
├── graph.py — NetworkX knowledge graph
├── auto_retrieve.py — Status checker + auto-retrieval
├── chroma_db/ — Vector database (gitignored)
├── memory_graph.json — Knowledge graph (auto-generated)
└── venv/ — Python venv (gitignored)
- "No module named chromadb" — Run setup.sh again or activate the venv:
source vector_memory/venv/bin/activate - OUT_OF_SYNC status — Run the indexer:
vector_memory/venv/bin/python vector_memory/indexer.py - Empty search results — Check that MEMORY.md has content and the indexer has been run at least once
- SIGSEGV on indexing — Usually caused by incompatible ML libs. The setup script pins known-good versions.
- Agent ignoring SOUL.md/AGENTS.md directives — OpenClaw integration missing. Run
python skills/persistent-memory/scripts/configure_openclaw.pyto fix. - Memory searches not finding workspace files — Check OpenClaw configuration:
openclaw config get | grep memorySearch - "Configuration verification failed" — Restart OpenClaw manually:
openclaw gateway restart
正文来自原始发布页, 版权归作者所有,许可未标注。 权利人认为有不妥,可申请下架。