The ultimate memory optimization system for OpenClaw agents.
OpenClaw 智能体终极记忆优化系统。
Combines the best of three worlds:
Result: 60-70% context reduction + complete learning retention + zero maintenance
效果:降低60-70%上下文占用 + 完整保留学习记录 + 零维护成本
Proactive Memory Agent 是一个专为 OpenClaw 设计的记忆优化系统,解决长会话中的上下文爆炸问题。
核心特性:
适用场景:
预期效果:
text
workspace/
├── SESSION-STATE.md # 🔥 HOT: Current task (WAL target)
├── .learnings/ # 🌡️ WARM: Learning records
│ ├── ERRORS.md — 错误记录
│ ├── LEARNINGS.md — 学习/纠正记录
│ └── FEATURE_REQUESTS.md — 功能请求记录
├── MEMORY.md # ❄️ COLD: Long-term archive
├── memory/
│ ├── hot/HOT_MEMORY.md # 快速恢复检查点
│ ├── warm/ # 稳定偏好/配置
│ ├── cold/ # 长期归档
│ └── working-buffer.md # ⚠️ 危险区日志
└── AGENTS.md/SOUL.md/TOOLS.md — 只读参考
Law: Context is a BUFFER, not storage. Write first, respond second. 法则: 上下文是缓冲,不是存储。先写再回。
SCAN every message for: 扫描每条消息中的:
The Protocol:
Purpose: Capture EVERY exchange in the danger zone (>60% context). 目的: 在危险区(>60%上下文)记录每一条消息。
中文说明: 当上下文使用率超过 60% 时,系统自动启用工作缓冲区,记录每一条对话。即使发生压缩,也能从缓冲区恢复。
How:
memory/working-buffer.mdStrict partitioning / 严格分区:
Zone%ContentFile中文说明Objective10%Core task, active constraintsSESSION-STATE.md核心任务Short-term40%Recent 5-10 turns raw dialogueWorking Buffer短期对话Decision Log20%Summarized outcomes.learnings/*.md决策日志Background20%High-relevance snippetsMEMORY.md背景知识
Rule: When any zone exceeds quota, oldest content moves to lower tier. 规则: 任何分区超出配额时,最旧内容移至下一层级。
Automatic lifecycle / 自动生命周期:
text
🔥 HOT (Current session) 当前会话
↓ (Task complete) 任务完成
🌡️ WARM (Recurring use) 重复使用
↓ (30 days old / promoted) 30天旧/已提升
❄️ COLD (Archive) 归档
TierLocationUpdate FrequencyRetention中文HOTSESSION-STATE.mdEvery messageCurrent task only当前任务WARM.learnings/When learning occursUntil promoted学习记录COLDMEMORY.mdWeekly archivalPermanent长期存档
bash
~/.openclaw/workspace/skills/proactive-memory-agent/scripts/init.sh
bash
# 检测当前状态 / Check current status
~/.openclaw/workspace/skills/proactive-memory-agent/scripts/detect.sh
# 搜索记忆 / Search memories
~/.openclaw/workspace/skills/proactive-memory-agent/scripts/search.sh "关键词"
# 执行记忆分层归档 / Run memory tiering
~/.openclaw/workspace/skills/proactive-memory-agent/scripts/tiering.sh
# 创建预压缩检查点 / Create pre-compaction checkpoint
~/.openclaw/workspace/skills/proactive-memory-agent/scripts/checkpoint.sh
场景 / Situation记录位置 / Record To类别 / Category命令失败 / Command failsERRORS.mderror用户纠正 / User correctsLEARNINGS.mdcorrection缺失功能 / Missing featureFEATURE_REQUESTS.mdfeature_request知识过时 / Knowledge outdatedLEARNINGS.mdknowledge_gap更好方法 / Better approachLEARNINGS.mdbest_practice
markdown
## [LRN-YYYYMMDD-XXX] category
**Logged**: ISO-8601 timestamp
**Priority**: low | medium | high | critical
**Status**: pending | in_progress | resolved | promoted
### Summary / 摘要
一句话描述学到了什么
### Details / 详情
What happened, what was wrong, correct approach
发生了什么,哪里错了,正确做法
### Suggested Action / 建议操作
Specific fix or improvement
具体的修复或改进建议
---
text
Learning in .learnings/ 在学习记录中
↓
IF recurring (3+ times) OR broadly applicable 如果重复(3+次)或广泛适用
↓
Promote to / 提升到:
├─ Behavioral patterns → SOUL.md 行为模式
├─ Workflow improvements → AGENTS.md 工作流改进
└─ Tool gotchas → TOOLS.md 工具技巧
Add to HEARTBEAT.md:
添加到心跳文件:
markdown
## Memory Management / 记忆管理 (每30分钟)
- [ ] Run detect.sh — 检查context使用率
- [ ] If >80%: Create checkpoint with checkpoint.sh / 创建检查点
- [ ] If >70%: Run tiering.sh to archive old content / 归档旧内容
- [ ] Review .learnings/ for pending items / 检查待处理项
Metric / 指标Before / 之前After / 之后Improvement / 改进Context usage / 上下文占用100%30-40%60-70% reductionToken consumption / Token消耗Baseline / 基准-50-60%Major savingsMaintenance / 维护成本High / 高Minimal / 极低Auto-tieringInformation loss / 信息丢失Risk / 有风险Zero / 零Buffer protection
MIT License — Free to use, modify, distribute. MIT 许可证 — 自由使用、修改、分发。
Part of the Hal Stack 🦞 + Self-Improvement Integration Integrated by @silaszhu