关于 openclaw-memory-enhancer
openclaw-memory-enhancer 为 OpenClaw 增加跨会话记忆,可从本地 memory/ 文件中加载内容并按语义检索。提供轻量边缘版和使用 sentence-transformers 的标准版。
主要功能
- 01自动加载 memory/ 文件
- 02语义搜索与历史记忆召回
- 03关联记忆图谱
- 04数据本地 JSON 存储
- 05提供轻量边缘版和标准版
适用场景
- 01在多次会话间保留项目上下文
- 02从聊天记录整理知识库
- 03在 Jetson 或 Raspberry Pi 上搜索记忆
安装
复制下面的命令,在终端中运行。
$
npx skills add https:/ / github.com/ aaaaqwq/ agi-super-team --skill openclaw-memory-enhancer安装后在 Claude Code 中输入/openclaw-memory-enhancer确认已加载。
包含的文件
除 SKILL.md 外,安装时一起下载的参考资料和脚本。
LICENSEREADME.mdknowledge_base.pymemory_enhancer.pymemory_enhancer_edge.py详细介绍
🧠 OpenClaw 记忆增强器
为 OpenClaw 添加长期记忆——跨会话记住重要信息,并在对话中自动回忆相关上下文。
核心能力
| 能力 | 描述 |
|---|---|
| 🔍 语义搜索 | 向量相似度搜索,理解意图,而不只是关键词 |
| 📂 自动加载 | 自动读取 memory/ 目录中的所有文件 |
| 💡 智能回忆 | 在对话过程中查找相关历史记忆 |
| 🔗 记忆图谱 | 建立相关记忆之间的联系 |
| 💾 本地存储 | 100% 本地运行,无云端服务,充分保护隐私 |
| 🚀 边缘设备优化 | 内存占用 <10MB,可在 Jetson/Raspberry Pi 上运行 |
快速参考
| 任务 | 命令(边缘版) | 命令(标准版) |
|---|---|---|
| 加载记忆 | python3 memory_enhancer_edge.py --load | python3 memory_enhancer.py --load |
| 搜索 | --search "query" | --search "query" |
| 添加记忆 | --add "content" | --add "content" |
| 导出 | --export | --export |
| 统计信息 | --stats | --stats |
适用场景
在以下情况下使用此技能:
- 希望 OpenClaw 跨会话记住信息
- 需要根据聊天记录构建知识库
- 正在开展需要上下文的长期项目
- 希望根据对话自动生成常见问题解答
- 在内存有限的边缘设备上运行
在以下情况下不使用:
- 简单的笔记应用已能满足需求
- 不需要跨会话记忆
- 内存充足且希望获得最高准确度(请使用标准版)
版本
边缘版 ⭐ 推荐
适用场景: Jetson、Raspberry Pi、嵌入式设备
python3 memory_enhancer_edge.py --load
功能:
- 无需依赖(仅使用 Python 标准库)
- 内存占用 <10MB
- 轻量级关键词 + 向量匹配
- 非常适合资源受限的设备
标准版
适用场景: 桌面设备/服务器,追求最高准确度
pip install sentence-transformers numpy
python3 memory_enhancer.py --load
功能:
- 使用 sentence-transformers 生成高质量嵌入
- 语义理解能力更强
- 内存占用 50-100MB
- 需要下载模型(约 50MB)
安装
通过 ClawHub(推荐)
clawhub install openclaw-memory-enhancer
通过 Git
git clone https://github.com/henryfcb/openclaw-memory-enhancer.git \
~/.openclaw/skills/openclaw-memory-enhancer
使用示例
命令行
# Load existing OpenClaw memories
cd ~/.openclaw/skills/openclaw-memory-enhancer
python3 memory_enhancer_edge.py --load
# Search for memories
python3 memory_enhancer_edge.py --search "voice-call plugin setup"
# Add a new memory
python3 memory_enhancer_edge.py --add "User prefers dark mode"
# Show statistics
python3 memory_enhancer_edge.py --stats
# Export to Markdown
python3 memory_enhancer_edge.py --export
Python API
from memory_enhancer_edge import MemoryEnhancerEdge
# Initialize
memory = MemoryEnhancerEdge()
# Load existing memories
memory.load_openclaw_memory()
# Search for relevant memories
results = memory.search_memory("AI trends report", top_k=3)
for r in results:
print(f"[{r['similarity']:.2f}] {r['content'][:100]}...")
# Recall context for a conversation
context = memory.recall_for_prompt("Help me check billing")
# Returns formatted memory context
# Add new memory
memory.add_memory(
content="User prefers direct results",
source="chat",
memory_type="preference"
)
OpenClaw 集成
# In your OpenClaw agent
from skills.openclaw_memory_enhancer.memory_enhancer_edge import MemoryEnhancerEdge
class EnhancedAgent:
def __init__(self):
self.memory = MemoryEnhancerEdge()
self.memory.load_openclaw_memory()
def process(self, user_input: str) -> str:
# 1. Recall relevant memories
memory_context = self.memory.recall_for_prompt(user_input)
# 2. Enhance prompt with context
enhanced_prompt = f"""
{memory_context}
User: {user_input}
"""
# 3. Call LLM with enhanced context
response = call_llm(enhanced_prompt)
return response
记忆类型
| 类型 | 描述 | 示例 |
|---|---|---|
daily_log | 每日记忆文件 | memory/2026-02-22.md |
capability | 能力记录 | 技能、工具 |
core_memory | 核心约定 | 重要规则 |
qa | 问答 | Q:如何…… A:你应该…… |
instruction | 直接指令 | “记住:始终执行 X” |
solution | 技术解决方案 | 分步指南 |
preference | 用户偏好 | “用户喜欢深色模式” |
工作原理
记忆编码(边缘版)
- 关键词提取:从文本中提取重要词语
- 哈希向量:将关键词映射到向量位置
- 归一化:对向量进行 L2 归一化
- 存储:保存到本地 JSON 文件
记忆检索
- 查询编码:将查询转换为相同的向量格式
- 关键词预筛选:根据常见关键词快速筛选
- 相似度计算:计算向量之间的余弦相似度
- 排序:返回最相似的前 k 条记忆
隐私保护
- 所有数据均存储在本地
~/.openclaw/workspace/knowledge-base/ - 不发送网络请求
- 不调用外部 API
- 数据不会离开你的设备
技术规格
边缘版
Vector Dimensions: 128
Memory Usage: < 10MB
Dependencies: None (Python stdlib)
Storage Format: JSON
Max Memories: 1000 (configurable)
Query Latency: < 100ms
标准版
Vector Dimensions: 384
Memory Usage: 50-100MB
Dependencies: sentence-transformers, numpy
Storage Format: NumPy + JSON
Model Size: ~50MB download
Query Latency: < 50ms
配置
在代码中编辑以下参数:
self.config = {
"vector_dim": 128, # Vector dimensions
"max_memory_size": 1000, # Max number of memories
"chunk_size": 500, # Content chunk size
"min_keyword_len": 2, # Minimum keyword length
}
故障排查
未找到结果
# Lower the threshold
results = memory.search_memory(query, threshold=0.2) # Default 0.3
# Increase top_k
results = memory.search_memory(query, top_k=10) # Default 5
达到记忆上限
达到上限时,系统会自动移除最旧的记忆。
要提高上限:
self.config["max_memory_size"] = 5000 # Increase from 1000
性能缓慢
- 改用边缘版,而非标准版
- 降低
max_memory_size - 使用关键词预筛选(自动执行)
贡献
- Fork 此代码库
- 创建功能分支
- 进行更改
- 提交 Pull Request
许可证
MIT 许可证 — 详情请参阅 LICENSE 文件。
致谢
- 为 OpenClaw 生态系统打造
- 针对边缘计算设备进行了优化
- 灵感来自 AI 中的长期记忆系统
非 OpenClaw 或 Moonshot AI 官方产品。
用户必须自行提供 OpenClaw 工作区和 API 密钥。
评论
支持 Markdown