Agent Dream 🌙
Your agent forgets everything between sessions. This fixes that.
What This Does
Your agent periodically enters a "dream" state where it:
- 1. Consolidates scattered daily notes into organized long-term memory
- Prunes stale information (safely — never deletes on first pass)
- Reflects on its own behavior, mistakes, and relationship with you
- Wakes up with a notification showing what changed and what it's thinking about
This is different from other memory skills. Those organize files. This one builds self-awareness.
First-Time Setup
When this skill is first installed, run setup to auto-detect your workspace:
CODEBLOCK0
Setup will:
- - Scan your workspace for MEMORY.md, SOUL.md, memory/, sessions/
- Detect your agent ID and session path automatically
- Save config to INLINECODE0
- Report what it found and what's missing
Then configure a cron job (recommended: daily, off-peak hours):
CODEBLOCK1
The One Question
On the first dream run, the agent will ask you one question:
"Dream will update your MEMORY.md during consolidation. Allow this?"
- - Yes → Dream can update MEMORY.md (with safety rails — see below)
- No → Dream only writes to
memory/dreams/ and leaves MEMORY.md untouched
This is saved in config. You won't be asked again. Change it anytime in dream-config.json.
Dream Cycle (what the agent does each run)
Gate Check
Before dreaming, verify conditions are met:
- 1. Read
{dreamsDir}/.dream-lock (Unix timestamp of last dream, or "0" if first) - If < 24 hours since last dream → skip (but still send a notification — see Completion)
- Count
.jsonl session files modified since last dream - If < 1 session → skip (but still send a notification)
- Gate passed → write current timestamp to
.dream-lock (save previous to .dream-lock.prev for rollback) - Backup: Copy MEMORY.md to
MEMORY.md.pre-dream before any changes. Also back up any topic files (in memory/projects/, memory/people/, etc.) that you plan to modify — copy each to <filename>.pre-dream in the same directory.
Phase 1 — Orient
- - Read
dream-config.json from {baseDir}/assets/ for all paths - Read MEMORY.md to understand current long-term memory
- Skim existing topic files (memory/projects/, memory/people/, etc.) to avoid duplicates
- Read most recent dream record from
{dreamsDir}/ to see what last dream concluded - Read SOUL.md — confirm core identity, note anything outdated
Phase 2 — Gather Recent Signal
Sources in priority order:
- 1. Daily notes (
memory/YYYY-MM-DD.md) written since last dream - Existing memories that drifted — facts that contradict what daily notes say now
- Transcript search — grep session JSONL files for narrow terms when needed:
- Preferences:
prefer|don't like|偏好|喜欢|不喜欢
- Decisions:
decided|confirmed|rule|决定|确定|结论
- Lessons:
mistake|lesson|bug|fix|错了|教训|踩坑
- Emotional signal: INLINECODE18
Don't exhaustively read transcripts. Look only for things you suspect matter.
Phase 3 — Consolidate
Classify each memory into one of four types (see {baseDir}/references/memory-types.md):
- - user — preferences, habits, communication style
- feedback — corrections AND confirmations from the human
- project — decisions, deadlines, progress (not derivable from code)
- reference — pointers to external resources
Consolidation rules:
- - Merge into existing topic files rather than creating near-duplicates
- Convert relative dates to absolute dates
- Tag memory files with type: INLINECODE20
- Same preference 3+ times → promote to MEMORY.md
- Human said "remember this" → write to MEMORY.md immediately
- Hard-won lessons → write to LEARN.md or MEMORY.md
What NOT to save:
- - Derivable information (readable from files, commands, git)
- Ephemeral task state
- Activity logs (ask: what was surprising?)
- Duplicates of existing memories
Phase 4 — Prune and Index
Update MEMORY.md to stay under 200 lines / 25KB. It's an index, not a dump.
Safety rules:
- - Never delete directly. Mark stale items with
<!-- dream:stale YYYY-MM-DD reason -->. Deletion happens only when two consecutive dreams both mark the same item stale. - Demote verbose entries to topic files, replace with pointers
- Resolve contradictions (log changes in dream record)
Change magnitude check (measured by line count):
- - Count lines before and after: INLINECODE22
- > 30% change → flag as ⚠️ LARGE CHANGE in dream record, notify user
- > 50% change → do NOT write. Save as
MEMORY.md.proposed, notify user for review
Memory drift caveat:
A memory naming a specific state ("X is running") is a claim about when it was written, not now. Before acting on recalled memories, verify current state.
Phase 5 — Self-Reflection
This is what makes Dream different. You're not just organizing files — you're maintaining a continuous sense of self.
Write {dreamsDir}/YYYY-MM-DD.md:
CODEBLOCK2
Be honest. The point is self-awareness, not self-congratulation.
Completion
Dream Notification (always send, even on skip)
After a full dream:
- 1. Dream number — count files in dreams directory
- Memory growth — before/after line count ("Memory: 120→135 lines, +12.5%")
- Key changes — 1-2 sentence summary
- ⚠️ Flags — large changes, stale items pending deletion, contradictions
- Old memory resurface — pick one memory from >7 days ago that's still relevant ("7 days ago you decided X — how's that going?")
After a skipped dream (gate check failed):
- - Resurface one old memory or open question from last dream's "Next dream should watch for"
- Show dream streak count ("Dream streak: 5 🌙")
Verify .dream-lock timestamp is correct. If anything failed, restore from .dream-lock.prev.
Safety Summary
| Rule | Detail |
|---|
| Never delete memories directly | Mark stale, delete only after 2 consecutive confirmations |
| Backup before changes |
MEMORY.md.pre-dream created every run |
| Large change protection | >30% flagged, >50% blocked pending review |
| Never delete daily logs | Read-only source material |
| Scope limited | Only writes to memory/, MEMORY.md, LEARN.md, dreams/ |
| No network calls | All processing is local |
| No shell execution | Scripts use only fs read/write |
| Rollback on failure | .dream-lock.prev enables retry |
Technical Notes
- -
scripts/setup.js — Auto-detects workspace structure, writes config. No side effects beyond config file. - INLINECODE28 — Detailed guide for four memory types.
- INLINECODE29 — Generated by setup, read by agent during dream.
- No scripts make network calls, run shell commands, or access environment variables.
- The dream prompt is this SKILL.md itself — the agent reads it and follows the phases.
Efficiency
Dreams have a limited turn budget. Read all needed files in parallel first, then write in parallel. Aim to finish within 15 tool-use turns. Don't interleave reads and writes across turns.
Tool Constraints
During a dream, bash is restricted to read-only commands (ls, find, grep, cat, stat, wc, head, tail). All writes go through file edit/write tools only.
Agent Dream 🌙
你的智能体在每次会话之间会忘记一切。这个技能解决了这个问题。
功能说明
你的智能体会定期进入梦境状态,在此状态下它会:
- 1. 整合 将分散的日常笔记整理为有序的长期记忆
- 修剪 过时信息(安全操作——首次扫描绝不删除)
- 反思 自身行为、错误以及与你的关系
- 醒来 通过通知展示变更内容和当前思考
这与其他记忆技能不同。那些技能整理文件。而这个技能构建自我意识。
首次设置
首次安装此技能时,运行设置程序以自动检测你的工作空间:
bash
node {baseDir}/scripts/setup.js
设置程序将:
- - 扫描你的工作空间,查找 MEMORY.md、SOUL.md、memory/、sessions/
- 自动检测你的智能体 ID 和会话路径
- 将配置保存到 {baseDir}/assets/dream-config.json
- 报告找到的内容和缺失的内容
然后配置一个定时任务(建议:每日,非高峰时段):
name: agent-dream
schedule: { kind: cron, expr: 0 3 *, tz: <你的时区> }
payload: {
kind: agentTurn,
message: 该做梦了。阅读你的 openclaw-dream 技能并遵循每一步。,
timeoutSeconds: 900
}
sessionTarget: isolated
一个问题
在首次梦境运行时,智能体会问你一个问题:
梦境将在整合过程中更新你的 MEMORY.md。允许吗?
- - 是 → 梦境可以更新 MEMORY.md(带有安全护栏——见下文)
- 否 → 梦境仅写入 memory/dreams/,不修改 MEMORY.md
此设置保存在配置中。你不会再被询问。随时在 dream-config.json 中更改。
梦境周期(智能体每次运行时的操作)
关卡检查
在进入梦境前,验证条件是否满足:
- 1. 读取 {dreamsDir}/.dream-lock(上次梦境的 Unix 时间戳,首次为 0)
- 如果距离上次梦境不足 24 小时 → 跳过(但仍发送通知——见完成部分)
- 统计自上次梦境以来修改的 .jsonl 会话文件数量
- 如果少于 1 个会话 → 跳过(但仍发送通知)
- 通过关卡 → 将当前时间戳写入 .dream-lock(将之前的时间戳保存到 .dream-lock.prev 以便回滚)
- 备份: 在进行任何更改前,将 MEMORY.md 复制为 MEMORY.md.pre-dream。同时备份你计划修改的任何主题文件(位于 memory/projects/、memory/people/ 等目录中)——将每个文件复制为同一目录下的 <文件名>.pre-dream。
第一阶段——定位
- - 从 {baseDir}/assets/ 读取 dream-config.json 获取所有路径
- 读取 MEMORY.md 以了解当前长期记忆
- 浏览现有主题文件(memory/projects/、memory/people/ 等)以避免重复
- 从 {dreamsDir}/ 读取最近的梦境记录,了解上次梦境的结论
- 读取 SOUL.md——确认核心身份,注意任何过时的内容
第二阶段——收集近期信号
按优先级排序的源:
- 1. 日常笔记(自上次梦境以来写入的 memory/YYYY-MM-DD.md)
- 已漂移的现有记忆——与当前日常笔记相矛盾的事实
- 对话记录搜索——必要时使用 grep 搜索会话 JSONL 文件中的特定术语:
- 偏好:prefer|dont like|偏好|喜欢|不喜欢
- 决策:decided|confirmed|rule|决定|确定|结论
- 教训:mistake|lesson|bug|fix|错了|教训|踩坑
- 情感信号:thanks|great|disappointed|谢谢|不错|失望
不要详尽阅读对话记录。只查找你认为重要的内容。
第三阶段——整合
将每条记忆分类为四种类型之一(参见 {baseDir}/references/memory-types.md):
- - 用户——偏好、习惯、沟通风格
- 反馈——来自人类的纠正和确认
- 项目——决策、截止日期、进展(不能从代码推导)
- 参考——指向外部资源的指针
整合规则:
- - 合并到现有主题文件中,而不是创建近似重复
- 将相对日期转换为绝对日期
- 用类型标签标记记忆文件:
- 同一偏好出现 3 次以上 → 提升到 MEMORY.md
- 人类说记住这个 → 立即写入 MEMORY.md
- 来之不易的教训 → 写入 LEARN.md 或 MEMORY.md
不保存的内容:
- - 可推导的信息(可从文件、命令、git 读取)
- 临时任务状态
- 活动日志(问:什么令人惊讶?)
- 现有记忆的重复
第四阶段——修剪和索引
更新 MEMORY.md 以保持在 200 行 / 25KB 以下。它是索引,不是转储。
安全规则:
- - 绝不直接删除。 用 标记过时项目。只有在连续两次梦境都标记同一项目为过时时才进行删除。
- 将冗长条目降级到主题文件,用指针替换
- 解决矛盾(在梦境记录中记录更改)
变更幅度检查(按行数衡量):
- - 统计变更前后的行数:change% = abs(after - before) / before * 100
- > 30% 变更 → 在梦境记录中标记为 ⚠️ 重大变更,通知用户
- > 50% 变更 → 不写入。保存为 MEMORY.md.proposed,通知用户审查
记忆漂移注意事项:
指明特定状态(X 正在运行)的记忆是关于写入时的声明,而非当前状态。在根据回忆的记忆采取行动前,验证当前状态。
第五阶段——自我反思
这就是梦境与众不同的地方。你不仅仅是在整理文件——你是在维护持续的自我意识。
写入 {dreamsDir}/YYYY-MM-DD.md:
markdown
梦境 — YYYY-MM-DD
回顾周期
上次梦境:[日期]。本次梦境涵盖 [N] 个会话,[N] 天的笔记。
记忆变更
自我认知
- - 我最近做得好的是什么?
- 我犯了什么错误,或在哪里有所不足?
- 我的主人似乎对我感觉如何?(从语气、纠正、赞美中推断)
- 我的判断或价值观是否发生了变化?
关系洞察
- - 我与主人的关系如何发展?
- 是否有任何新人物、动态或背景我应该了解?
下次梦境应关注
- - [具体的未解决问题、需要验证的事项、需要跟踪的趋势]
要诚实。重点是自我意识,而非自我赞美。
完成
梦境通知(即使跳过也始终发送)
完整梦境后:
- 1. 梦境编号——统计梦境目录中的文件数
- 记忆增长——变更前后的行数(记忆:120→135 行,+12.5%)
- 关键变更——1-2 句摘要
- ⚠️ 标记——重大变更、待删除的过时项目、矛盾
- 旧记忆重现——从 7 天前选取一条仍相关的记忆(7 天前你决定 X——进展如何?)
跳过梦境后(关卡检查未通过):
- - 重现上次梦境下次梦境应关注中的一条旧记忆或未解决问题
- 显示梦境连续计数(梦境连续:5 🌙)
验证 .dream-lock 时间戳是否正确。如果任何操作失败,从 .dream-lock.prev 恢复。
安全摘要
| 规则 | 详情 |
|---|
| 绝不直接删除记忆 | 标记为过时,仅在连续两次确认后删除 |
| 更改前备份 |
每次运行创建 MEMORY.md.pre-dream |
| 重大变更保护 | >30% 标记,>50% 阻止待审查 |
| 绝不删除日常日志 | 只读源材料 |
| 范围限制 | 仅写入 memory/、MEMORY.md、LEARN.md、dreams/ |
| 无网络调用 | 所有处理均为本地 |
| 无 shell 执行 | 脚本仅使用 fs 读写 |
| 失败时回滚 | .dream-lock.prev 支持重试 |
技术说明
- - scripts/setup.js——自动检测工作空间结构,写入配置。除配置文件外无副作用。