Install
openclaw skills install clawlancememory基于 LanceDB 向量数据库的长期记忆与语义检索系统,支持自动抽取、分类和跨会话存储,快速响应集成 OpenClaw。
openclaw skills install clawlancememory基于 LanceDB 向量数据库的智能记忆系统,为 OpenClaw Agent 提供长期记忆和语义检索能力。
# 克隆仓库
git clone https://github.com/asbinbin/claw_lance.git
cd claw_lance
# 创建虚拟环境
python3 -m venv venv
source venv/bin/activate
# 安装依赖
pip install -r requirements.txt
# 获取智谱 AI API Key: https://open.bigmodel.cn/
export ZHIPU_API_KEY="your-api-key-here"
# 方法 1: 使用启用脚本
bash enable.sh
# 方法 2: OpenClaw 命令
openclaw hooks enable memory-system
# 查看用户画像
python3 skill.py profile
# 添加记忆
python3 skill.py add --content "我喜欢简洁" --type preference
# 检索记忆
python3 skill.py search --query "项目"
| 类型 | 说明 | 触发词 | 例子 |
|---|---|---|---|
| preference | 偏好、习惯 | 我喜欢/我偏好/我习惯 | "我喜欢简洁的汇报风格" |
| fact | 事实、背景 | 我是/我负责/我擅长 | "我负责 POC 项目" |
| task | 任务、待办 | 我需要/别忘了/明天要 | "每周四提交 OKR 周报" |
| general | 其他 | - | 对话历史、临时信息 |
# 查看用户画像
python3 skill.py profile
# 检索记忆
python3 skill.py search --query "项目" --k 5
# 添加记忆
python3 skill.py add --content "我喜欢 Markdown" --type preference
# 自动抽取(从消息中识别记忆)
python3 skill.py auto --message "我负责 POC 项目,喜欢简洁的代码"
# 查看统计信息
python3 skill.py stats
# 清理过期记忆
python3 skill.py cleanup
from skills.memory.openclaw_integration import OpenClawMemoryIntegration
# 初始化
mem = OpenClawMemoryIntegration(user_id="ou_xxx")
# 生成 system prompt(包含记忆)
prompt = mem.get_session_system_prompt("你是小美式")
# 检索记忆
results = mem.search_memory("项目", k=5)
for r in results:
print(f"{r['type']}: {r['content']}")
# 添加记忆
mem.add_memory("我喜欢简洁", type="preference", importance=0.8)
# 获取用户画像
profile = mem.get_user_profile()
print(f"偏好:{profile['preferences']}")
print(f"事实:{profile['facts']}")
print(f"任务:{profile['tasks']}")
┌─────────────────────────────────────────┐
│ OpenClaw Agent │
│ │
│ ┌────────────────────────────────────┐ │
│ │ Memory Hook (handler.js) │ │
│ │ - 拦截 agent:bootstrap 事件 │ │
│ │ - 调用 Python 脚本 │ │
│ │ - 注入 USER_MEMORY.md │ │
│ └────────────────────────────────────┘ │
└─────────────────────────────────────────┘
↓
┌─────────────────────────────────────────┐
│ Python 记忆模块 │
│ │
│ ┌────────────────────────────────────┐ │
│ │ openclaw_integration.py │ │
│ │ - OpenClaw 集成接口 │ │
│ │ - 生成 system prompt │ │
│ └────────────────────────────────────┘ │
│ ↓ │
│ ┌────────────────────────────────────┐ │
│ │ lancedb_memory.py │ │
│ │ - LanceDB 记忆管理 │ │
│ │ - 向量检索 │ │
│ └────────────────────────────────────┘ │
│ ↓ │
│ ┌────────────────────────────────────┐ │
│ │ auto_memory.py │ │
│ │ - 自动记忆抽取 │ │
│ │ - 模式匹配 │ │
│ └────────────────────────────────────┘ │
└─────────────────────────────────────────┘
↓
┌─────────────────────────────────────────┐
│ LanceDB 向量数据库 │
│ memory_lancedb/ │
│ │
│ - 向量存储(智谱 AI Embedding) │
│ - 语义检索 │
│ - 多用户隔离 │
└─────────────────────────────────────────┘
智谱 AI Embedding:
LanceDB:
claw_lance/
├── README.md # 项目说明
├── requirements.txt # Python 依赖
├── enable.sh # 启用脚本
├── skill.py # 命令行入口
├── hooks/
│ └── memory-system/
│ ├── HOOK.md # Hook 元数据
│ └── handler.js # Hook 处理器
├── skills/
│ └── memory/
│ ├── lancedb_memory.py # LanceDB 核心
│ ├── openclaw_integration.py # OpenClaw 集成
│ ├── auto_memory.py # 自动记忆抽取
│ └── session_start.py # Session 启动脚本
├── docs/ # 文档目录
│ ├── INSTALL.md
│ ├── USAGE.md
│ ├── API.md
│ ├── HOOK.md
│ └── FAQ.md
└── tests/ # 测试目录
└── test_memory.py
# 安装测试依赖
pip install pytest
# 运行测试
pytest tests/
欢迎提交 Issue 和 Pull Request!
git checkout -b feature/AmazingFeature)git commit -m 'Add some AmazingFeature')git push origin feature/AmazingFeature)本项目采用 MIT 许可证 - 查看 LICENSE 文件了解详情。
Made with ❤️ by 小美式 ☕