让 AI 记住重要的事,忘记不重要的事
根据消息类型自动调节"记忆焦距",决定读取多少上下文:
| 焦距模式 | 触发场景 | 加载内容 | Token 节省 |
|---|---|---|---|
| ---------- | ---------- | ---------- | ----------- |
| 远景 (simple) | 简单对话 | 无 | 100% |
| 中景 (task) | 任务执行 | 相关记忆 | 60-75% |
| 近景 (memory) | 情感/偏好 | 完整记忆 | 正常 |
| 微距 (new_info) | 新信息 | 完整记忆 + 写入 | 正常 |
基于访问频率自动强化重要记忆:
三层存储架构,优化性能:
AI 自动生成记忆标签,支持语义检索:
艾宾浩斯遗忘曲线算法,智能清理:
标签 - 记忆双向索引,快速检索:
Append-Only JSONL 格式,保证数据完整性:
# 从 ClawHub 安装
clawhub install memory-focal-system
# 或本地安装(已预装)
cd ~/.openclaw/workspace/skills/memory-focal-system
配置文件:~/.openclaw/workspace/skills/memory-focal-system/config.json
{
"enabled": true,
"auto_classify": true,
"auto_write": true,
"load_user": true,
"load_memory": true,
"load_focal_active": true,
"token_limit": 8000
}
| 字段 | 类型 | 默认值 | 说明 |
|---|---|---|---|
| ------ | ------ | -------- | ------ |
enabled | bool | true | 是否启用记忆系统 |
auto_classify | bool | true | 自动分类消息 |
auto_write | bool | true | 自动写入新记忆 |
load_user | bool | true | 加载用户配置文件 |
load_memory | bool | true | 加载长期记忆文件 |
load_focal_active | bool | true | 加载热存储记忆 |
token_limit | int | 8000 | Token 上限 |
安装后自动生效,无需手动调用。
每次对话时:
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", ["考试", "日程"])
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 tokens | 0 tokens | 100% |
| 任务执行 | 8000 tokens | 2000-3000 tokens | 60-75% |
| 情感/偏好 | 8000 tokens | 8000 tokens | 0% |
| 新信息 | 8000 tokens | 8000 tokens | 0% |
综合节省:40-60%(取决于对话类型分布)
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
{
"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
}
{
"version": "1.0.0",
"tags": {
"作息": ["mem_0001", "mem_0002"],
"偏好": ["mem_0001"]
}
}
需要配置 dashscope API key:
python3 scripts/cli.py tag "用户明天考试" --api-key <your-api-key>
缓存机制:
python3 scripts/cli.py tag-statspython3 scripts/cli.py tag-clear基于访问次数、最后访问时间、重要性计算优先级:
from frequency_trigger import FrequencyTrigger
trigger = FrequencyTrigger()
priority = trigger.calculate_priority(memory)
艾宾浩斯遗忘曲线算法:
from forget_curve import ForgetCurve
curve = ForgetCurve()
strength = curve.calculate_strength(memory)
schedule = curve.get_archive_schedule(memories)
```bash
python3 scripts/cli.py init
```
config.json 中设置 "auto_tag": falsedata/raw/buffer.jsonl解决: 编辑 classifier.py,调整关键词列表
# 添加新的关键词
self.simple_keywords.append("新关键词")
解决: 检查 CLI 路径和权限
ls -la ~/.openclaw/workspace/memory-focal/scripts/cli.py
chmod +x ~/.openclaw/workspace/memory-focal/scripts/cli.py
解决: 降低 token_limit 或减少加载的记忆文件
{
"token_limit": 4000,
"load_focal_active": false
}
clawhub sync memory-focal-systemclawhub star memory-focal-system_焦距记忆系统 - 让 AI 记住重要的事,忘记不重要的事_
共 1 个版本