让 AI 记住重要的事,忘记不重要的事
根据消息类型自动调节"记忆焦距",决定读取多少上下文:
焦距模式触发场景加载内容Token 节省**远景 (simple)**简单对话无100%**中景 (task)**任务执行相关记忆60-75%**近景 (memory)情感/偏好完整记忆正常微距 (new_info)**新信息完整记忆 + 写入正常
基于访问频率自动强化重要记忆:
三层存储架构,优化性能:
AI 自动生成记忆标签,支持语义检索:
艾宾浩斯遗忘曲线算法,智能清理:
标签 - 记忆双向索引,快速检索:
Append-Only JSONL 格式,保证数据完整性:
bash
# 从 ClawHub 安装
clawhub install memory-focal-system
# 或本地安装(已预装)
cd ~/.openclaw/workspace/skills/memory-focal-system
配置文件: ~/.openclaw/workspace/skills/memory-focal-system/config.json
json
{
"enabled": true,
"auto_classify": true,
"auto_write": true,
"load_user": true,
"load_memory": true,
"load_focal_active": true,
"token_limit": 8000
}
字段类型默认值说明enabledbooltrue是否启用记忆系统auto_classifybooltrue自动分类消息auto_writebooltrue自动写入新记忆load_userbooltrue加载用户配置文件load_memorybooltrue加载长期记忆文件load_focal_activebooltrue加载热存储记忆token_limitint8000Token 上限
安装后自动生效,无需手动调用。
每次对话时:
python
from memory_manager import MemoryManager
manager = MemoryManager()
# 处理消息
context = manager.process_message("用户偏好早上 8 点起床")
print(context)
# {
# "category": "memory",
# "load_user": "...",
# "load_memory": "...",
# "load_focal": [...],
# "should_write": true,
# "token_count": 907
# }
# 写入记忆
manager.write_memory("用户明天考试", "已记录", "event", ["考试", "日程"])
bash
cd ~/.openclaw/workspace/memory-focal
# 初始化
python3 scripts/cli.py init
# 添加记忆
python3 scripts/cli.py add "用户偏好早上 8 点起床" --type preference --tags 作息,偏好
# 搜索记忆
python3 scripts/cli.py search "作息"
# 查看统计
python3 scripts/cli.py stats
# 查看高优先级记忆
python3 scripts/cli.py top 5
# 分类测试
python3 scripts/cli.py classify "在吗"
# 生成标签
python3 scripts/cli.py tag "用户明天考试"
# 预览归档计划
python3 scripts/cli.py cleanup
场景优化前优化后节省简单对话8000 tokens0 tokens**100%任务执行8000 tokens2000-3000 tokens60-75%**情感/偏好8000 tokens8000 tokens0%新信息8000 tokens8000 tokens0%
综合节省:40-60%(取决于对话类型分布)
text
memory-focal-system/
├── SKILL.md # 技能说明
├── README.md # 使用文档
├── _meta.json # 元数据
├── config.json # 配置文件
├── memory_manager.py # 核心管理模块
└── classifier.py # 消息分类器
memory-focal/ # 记忆数据存储(独立目录)
├── config/config.json
├── data/raw/buffer.jsonl
├── data/index/
│ ├── tag_index.json
│ └── memory_index.json
├── storage/
│ ├── active/
│ ├── short_term/
│ ├── long_term/
│ └── archive/
└── scripts/
├── cli.py
├── classifier.py
├── frequency_trigger.py
├── storage_manager.py
├── auto_tag.py
└── forget_curve.py
json
{
"id": "mem_0001",
"text": "用户偏好早上 8 点起床",
"type": "preference",
"tags": ["作息", "偏好"],
"timestamp": "2026-03-29T08:00:00+08:00",
"created_at": "2026-03-29T08:00:00+08:00",
"access_count": 0,
"last_accessed": null,
"importance": 1.0,
"layer": "active",
"priority": 0.0
}
json
{
"version": "1.0.0",
"tags": {
"作息": ["mem_0001", "mem_0002"],
"偏好": ["mem_0001"]
}
}
需要配置 dashscope API key:
bash
python3 scripts/cli.py tag "用户明天考试" --api-key <your-api-key>
缓存机制:
python3 scripts/cli.py tag-statspython3 scripts/cli.py tag-clear基于访问次数、最后访问时间、重要性计算优先级:
python
from frequency_trigger import FrequencyTrigger
trigger = FrequencyTrigger()
priority = trigger.calculate_priority(memory)
艾宾浩斯遗忘曲线算法:
python
from forget_curve import ForgetCurve
curve = ForgetCurve()
strength = curve.calculate_strength(memory)
schedule = curve.get_archive_schedule(memories)
首次使用需要初始化 bash
python3 scripts/cli.py init
LLM 自动标签需要 API key
config.json 中设置 "auto_tag": falsePython 版本要求
备份建议
data/raw/buffer.jsonl解决: 编辑 classifier.py,调整关键词列表
python
# 添加新的关键词
self.simple_keywords.append("新关键词")
解决: 检查 CLI 路径和权限
bash
ls -la ~/.openclaw/workspace/memory-focal/scripts/cli.py
chmod +x ~/.openclaw/workspace/memory-focal/scripts/cli.py
解决: 降低 token_limit 或减少加载的记忆文件
json
{
"token_limit": 4000,
"load_focal_active": false
}
clawhub sync memory-focal-systemclawhub star memory-focal-system焦距记忆系统 - 让 AI 记住重要的事,忘记不重要的事