Dream — Memory Consolidation for OpenClaw
Memory consolidation for OpenClaw agents. Your agent accumulates daily notes in memory/YYYY-MM-DD.md files, but without periodic consolidation, long-term memory (MEMORY.md) becomes stale while daily files grow endlessly. Dream fixes this — like REM sleep for your AI.
When to Use
- - User says "dream", "做梦", "consolidate memory", or "整理记忆"
- Cron trigger (recommended: nightly at 3:00 AM)
- Heartbeat detects memory files piling up (>20 files or >3000 total lines)
Consolidation Flow
Phase 1 — Orient
- 1.
ls memory/ to inventory daily files - Read
MEMORY.md to understand current long-term memory structure - Count: total files, total lines, files from last 7 days
Phase 2 — Scan Recent Journals
Read daily files from the last 7 days (memory/YYYY-MM-DD.md). Extract:
- - New facts, preferences, or decisions not yet in MEMORY.md
- Information that contradicts MEMORY.md (needs correction)
- Recurring themes (indicates importance)
Token budget rules:
- - Skip files older than 7 days (too many tokens)
- If a file exceeds 500 lines, read only the first 200 lines
- Focus on headings and key facts, not verbose logs
Phase 3 — Merge into MEMORY.md
Apply these operations to MEMORY.md using surgical edits (not full rewrites):
- 1. Add: Append new facts to the appropriate section
- Correct: Update outdated information with newer data from journals
- Deduplicate: Merge entries that say the same thing
- Prune: Remove clearly obsolete info (e.g., "temporary workaround for X" when X is resolved)
- Absolutize dates: Convert "yesterday", "just now" → actual dates (e.g., "2026-03-27")
Phase 4 — Mark Old Journals (Optional)
For daily files older than 30 days:
- - If content is consolidated → prepend: INLINECODE5
- Never delete any file (user may want to look back)
Phase 5 — Report
Output a brief consolidation report:
CODEBLOCK0
Critical Rules
- - MEMORY.md is the primary output — all consolidated knowledge goes here
- Surgical edits only — use the
edit tool for precise changes, never overwrite the whole file - Conservative by default — when unsure whether to remove something, keep it
- No secrets in logs — don't expose API keys, passwords, or tokens in the dream report
- Log each run — append a
## Dream Log (HH:MM) entry to today's INLINECODE8
Cron Setup
CODEBLOCK1
How It Works (Under the Hood)
This skill mimics the human sleep cycle's memory consolidation process:
CODEBLOCK2
Without Dream, MEMORY.md stays frozen at whatever was manually written, while daily files accumulate unbounded. With Dream, your agent's long-term memory stays fresh, accurate, and compact.
梦境 — OpenClaw的记忆整合
为OpenClaw智能体提供记忆整合功能。您的智能体会将每日笔记累积存储在memory/YYYY-MM-DD.md文件中,但若不进行定期整合,长期记忆(MEMORY.md)会逐渐过时,而每日文件则无限增长。梦境功能解决了这一问题——如同您AI的快速眼动睡眠。
使用时机
- - 用户说做梦、整理记忆或consolidate memory
- 定时触发(建议:每日凌晨3:00)
- 心跳检测发现记忆文件堆积(超过20个文件或总行数超过3000行)
整合流程
第一阶段 — 定位
- 1. 执行ls memory/盘点每日文件
- 读取MEMORY.md了解当前长期记忆结构
- 统计:文件总数、总行数、最近7天的文件数
第二阶段 — 扫描近期日志
读取最近7天的每日文件(memory/YYYY-MM-DD.md)。提取:
- - 尚未记录在MEMORY.md中的新事实、偏好或决策
- 与MEMORY.md相矛盾的信息(需要修正)
- 重复出现的主题(表明重要性)
令牌预算规则:
- - 跳过7天前的文件(令牌过多)
- 若文件超过500行,仅读取前200行
- 重点关注标题和关键事实,而非冗长日志
第三阶段 — 合并至MEMORY.md
使用精准编辑(而非全文重写)对MEMORY.md执行以下操作:
- 1. 添加:将新事实追加到相应章节
- 修正:用日志中的新数据更新过时信息
- 去重:合并表述相同内容的条目
- 精简:移除明显过时的信息(例如,当问题X已解决时,移除针对X的临时解决方案)
- 日期绝对化:将昨天、刚才转换为实际日期(如2026-03-27)
第四阶段 — 标记旧日志(可选)
对于超过30天的每日文件:
- - 若内容已整合 → 在文件开头添加:
- 绝不删除任何文件(用户可能需要回溯查看)
第五阶段 — 报告
输出简要整合报告:
🌙 梦境完成
- - 扫描了N个每日文件(共X行)
- MEMORY.md:+N条新增 / ~N条修正 / -N条精简
- 后续建议:[如有]
关键规则
- - MEMORY.md是主要输出——所有整合的知识均存储于此
- 仅进行精准编辑——使用edit工具进行精确修改,切勿覆盖整个文件
- 默认保守——不确定是否应删除某内容时,保留它
- 日志中不含机密——不在梦境报告中暴露API密钥、密码或令牌
- 记录每次运行——将## 梦境日志(HH:MM)条目追加至当天的memory/YYYY-MM-DD.md
定时任务设置
/cron add --schedule 0 3 * --task 执行梦境技能:整合记忆 --label dream-nightly
工作原理(底层机制)
该技能模拟人类睡眠周期的记忆整合过程:
每日经历 夜间整合 长期记忆
┌─────────────────┐ ┌─────────────────┐ ┌─────────────────┐
│ memory/03-26.md │──┐ │ │ │ │
│ memory/03-27.md │──┤ │ 梦境技能 │────────▶│ MEMORY.md │
│ memory/03-28.md │──┤ │ (扫描+合并) │ │ (结构化、 │
│ memory/03-29.md │──┘ │ │ │ 去重后) │
│ ... │ └─────────────────┘ └─────────────────┘
└─────────────────┘
原始每日日志 整合过程 精选知识库
没有梦境功能,MEMORY.md将停留在手动编写的内容上,而每日文件则无限累积。有了梦境功能,您的智能体的长期记忆将保持新鲜、准确且精简。