OpenClaw Dream
Automatic memory consolidation — turn scattered daily notes into clean, organized long-term memory.
Overview
Memory files accumulate noise over time: relative dates lose meaning, contradictory entries confuse the agent, duplicates waste context, and stale information causes hallucinations. Dream fixes this by running a structured consolidation pass.
When to Run
- - Manual: User says "dream", "整理记忆", "consolidate memory"
- Cron: Schedule via
openclaw cron add for daily execution (recommended: 3-4 AM) - Heartbeat: Add to HEARTBEAT.md as a periodic task (every 3-5 days)
- Condition check: Only run if
memory/.last_dream is older than 24h AND new daily notes exist since last dream
Execution
Always run as a sub-agent to avoid blocking the main session:
CODEBLOCK0
For manual triggers in the main session, spawn the sub-agent, reply to user "开始整理记忆,稍后汇报结果", then yield.
Four-Phase Consolidation
Phase 1: Scan
- 1. Read
MEMORY.md — note current line count, section headers, last-updated date - Read all
memory/YYYY-MM-DD.md files from the last 14 days - Read
memory/self-improving/*.jsonl if it exists (error/correction/best_practice/decision logs) - Read
.last_dream timestamp to know what's already been processed - Build a mental map: what topics exist, what's fresh, what's stale
Phase 2: Analyze
Scan all content for these problems:
Relative dates — Find phrases like "yesterday", "today", "last week", "recently", "刚才", "昨天", "上周". Cross-reference with the file's date to compute the absolute date.
Contradictions — Same topic with conflicting conclusions across different files. Examples:
- - "API uses Express" in one file, "migrated to Fastify" in another
- Different pricing numbers for the same product on different dates
Duplicates — Same fact recorded in multiple daily notes. Example:
- - Three different files all note the same build command or deployment step
Stale entries — Information about things that no longer exist:
- - References to deleted files or deprecated APIs
- Completed tasks still marked as "in progress"
- Resolved issues still listed as open
Unprocessed JSONL patterns — High-frequency errors or corrections in self-improving logs that should become rules in MEMORY.md
Important events not yet in MEMORY.md — Significant decisions, lessons, or changes in daily notes that deserve long-term retention
Phase 3: Consolidate
Execute fixes in this order:
- 1. Date absolutization: Replace relative dates with absolute dates
- "Yesterday we decided X" (in 2026-03-15.md) → "2026-03-14: decided X"
- Preserve the original meaning; only change the date reference
- 2. Contradiction resolution: Keep the most recent entry, remove or mark the old one
- Add
[superseded by YYYY-MM-DD] to the old entry if in a daily note
- In MEMORY.md, simply update to the latest fact
- 3. Duplicate merging: Consolidate into one canonical entry
- Keep the most complete/detailed version
- Note the date range if relevant ("first noted YYYY-MM-DD")
- 4. Stale cleanup: Remove or archive entries about things that no longer exist
- Mark completed projects as done with completion date
- Remove references to deleted files/configs
- 5. JSONL distillation: Extract patterns from self-improving logs
- Errors appearing ≥2 times → add rule to MEMORY.md "经验教训" section
- Important decisions → add to appropriate MEMORY.md section
- Update
memory/self-improving/.last_distill timestamp
- 6. Daily notes → MEMORY.md promotion: Identify significant items worth keeping long-term
- Major decisions, architectural changes, new integrations
- People/relationships updates
- Lessons learned
- Do NOT promote routine operational logs
Phase 4: Write
- 1. Update MEMORY.md:
- Apply all changes from Phase 3
- Keep total line count under 250 lines (warn if approaching)
- Update the
*最后更新* date at the bottom
- Preserve existing section structure (don't reorganize unless necessary)
- 2. Rebuild vector index:
CODEBLOCK1
- 3. Generate dream log at
memory/dream-log-YYYY-MM-DD.md:
CODEBLOCK2
- 4. Update timestamp:
CODEBLOCK3
Safety Rules
- - Never delete daily note files — only modify MEMORY.md and generate dream-log
- Never modify source code, configs, or non-memory files
- Preserve all 📌 pinned entries in MEMORY.md (lines starting with 📌 are never removed)
- When uncertain about a contradiction, keep both entries and flag in dream-log as "needs human review"
- Dream-log is append-only — never modify past dream logs
Configuration
Users can create DREAM.md in workspace root to customize behavior:
CODEBLOCK4
If DREAM.md doesn't exist, use defaults above.
Cron Setup Example
CODEBLOCK5
OpenClaw Dream
自动记忆整合——将零散的日常笔记转化为清晰、有序的长期记忆。
概述
记忆文件会随时间积累噪声:相对日期失去意义、矛盾条目混淆智能体、重复内容浪费上下文、过时信息导致幻觉。Dream 通过执行结构化的整合流程来解决这些问题。
何时运行
- - 手动:用户说dream、整理记忆、consolidate memory
- 定时任务:通过 openclaw cron add 设置每日执行(建议凌晨 3-4 点)
- 心跳任务:作为周期性任务添加到 HEARTBEAT.md(每 3-5 天)
- 条件检查:仅在 memory/.last_dream 超过 24 小时且上次运行后有新的日常笔记时执行
执行方式
始终作为子代理运行,避免阻塞主会话:
sessions_spawn:
task: 运行 openclaw-dream 整合。首先阅读 skills/openclaw-dream/SKILL.md 中的技能说明。
mode: run
model: sonnet # 使用较便宜的模型
在主会话中手动触发时,启动子代理,回复用户开始整理记忆,稍后汇报结果,然后让出控制权。
四阶段整合
阶段 1:扫描
- 1. 读取 MEMORY.md — 记录当前行数、章节标题、最后更新日期
- 读取过去 14 天内所有 memory/YYYY-MM-DD.md 文件
- 读取 memory/self-improving/*.jsonl(如果存在)(错误/修正/最佳实践/决策日志)
- 读取 .last_dream 时间戳,了解已处理的内容
- 构建思维导图:存在哪些主题、哪些是新的、哪些已过时
阶段 2:分析
扫描所有内容,查找以下问题:
相对日期 — 查找昨天、今天、上周、最近、刚才、昨天、上周等短语。根据文件日期交叉引用,计算绝对日期。
矛盾内容 — 不同文件中同一主题存在冲突结论。例如:
- - 一个文件中写API 使用 Express,另一个文件中写已迁移到 Fastify
- 不同日期同一产品的不同定价数字
重复内容 — 多条日常笔记中记录了相同的事实。例如:
过时条目 — 关于已不存在事物的信息:
- - 引用已删除文件或已弃用 API
- 已完成任务仍标记为进行中
- 已解决问题仍列为未关闭
未处理的 JSONL 模式 — 自我改进日志中高频出现的错误或修正,应成为 MEMORY.md 中的规则
尚未纳入 MEMORY.md 的重要事件 — 日常笔记中值得长期保留的重大决策、经验教训或变更
阶段 3:整合
按此顺序执行修复:
- 1. 日期绝对化:将相对日期替换为绝对日期
- 昨天我们决定 X(在 2026-03-15.md 中)→ 2026-03-14:决定 X
- 保留原始含义;仅更改日期引用
- 2. 矛盾解决:保留最新条目,删除或标记旧条目
- 如果旧条目在每日笔记中,添加 [已被 YYYY-MM-DD 取代]
- 在 MEMORY.md 中,直接更新为最新事实
- 3. 重复合并:整合为一个规范条目
- 保留最完整/详细的版本
- 如相关,注明日期范围(首次记录于 YYYY-MM-DD)
- 4. 过时清理:删除或归档关于已不存在事物的条目
- 标记已完成项目并注明完成日期
- 删除对已删除文件/配置的引用
- 5. JSONL 提炼:从自我改进日志中提取模式
- 出现 ≥2 次的错误 → 在 MEMORY.md 的经验教训部分添加规则
- 重要决策 → 添加到 MEMORY.md 的相应部分
- 更新 memory/self-improving/.last_distill 时间戳
- 6. 日常笔记 → MEMORY.md 提升:识别值得长期保留的重要项目
- 重大决策、架构变更、新集成
- 人员/关系更新
- 经验教训
- 不要提升常规操作日志
阶段 4:写入
- 1. 更新 MEMORY.md:
- 应用阶段 3 的所有更改
- 保持总行数在 250 行以下(接近时发出警告)
- 更新底部的
最后更新 日期
- 保留现有章节结构(除非必要,否则不重新组织)
- 2. 重建向量索引:
bash
openclaw memory index --force
- 3. 在 memory/dream-log-YYYY-MM-DD.md 生成梦境日志:
markdown
# 梦境日志 YYYY-MM-DD
## 所做更改
- [日期修复] 3 个相对日期转换为绝对日期
- [矛盾] 删除过时的 Express 引用(已被 Fastify 迁移取代)
- [重复] 合并 2 条重复的构建命令条目
- [过时] 将 ChatClaw 第二阶段标记为已完成
- [提升] 将 RhinoRank 订单跟踪添加到 MEMORY.md
- [提炼] 从错误日志中添加 1 条新规则
## MEMORY.md 统计
- 行数:119 → 128
- 章节:8(未变)
## 已跳过
- 5 条仅包含常规操作日志的日常笔记(无需操作)
- 4. 更新时间戳:
bash
date -u +%Y-%m-%dT%H:%M:%SZ > memory/.last_dream
安全规则
- - 绝不删除日常笔记文件 — 仅修改 MEMORY.md 并生成梦境日志
- 绝不修改源代码、配置文件或非记忆文件
- 保留 MEMORY.md 中所有 📌 固定条目(以 📌 开头的行永不删除)
- 对不确定的矛盾,保留两个条目并在梦境日志中标记为需要人工审核
- 梦境日志仅可追加 — 绝不修改过去的梦境日志
配置
用户可以在工作区根目录创建 DREAM.md 来自定义行为:
markdown
DREAM.md
设置
- - maxmemorylines: 250
- lookbackdays: 14
- minhoursbetweendreams: 24
受保护章节
自定义规则
- - 始终保留定价/计费相关条目
- 合并重复的 API 端点引用
如果 DREAM.md 不存在,则使用上述默认值。
定时任务设置示例
bash
openclaw cron add \
--id dream-nightly \
--schedule 0 3 * \
--task 运行 openclaw-dream 记忆整合。阅读 skills/openclaw-dream/SKILL.md 并遵循阶段 1-4。 \
--model sonnet \
--isolated