Inspired by Claude Code's Dream memory consolidation system. Adapted for OpenClaw's file-based memory architecture.
Every memory entry belongs to one of four types. Tag each entry when writing.
TypeWhat to StoreWhereExampleuserUser's role, preferences, knowledge, communication styleUSER.md / MEMORY.md"Jim prefers casual Chinese, works at Amazon, timezone UTC+8"feedbackCorrections AND confirmations — what works and what doesn'tAGENTS.md / MEMORY.md"append over write for Feishu docs. Why: write overwrites history. How: always use feishu_doc append"projectOngoing work, goals, deadlines, decisionsdaily notes / MEMORY.md"France trip Jun 19-27, 4 people, budget TBD — optimized for museum closure days"referencePointers to where information livesTOOLS.md / MEMORY.md"Brave API ~1000/mo free, usage tracked in memory/brave-search-usage.json"
Every feedback/project memory entry should follow:
text
**Rule/Fact:** [the thing itself]
**Why:** [reason — past incident, user preference, or constraint]
**How to apply:** [when/where this kicks in]
Even if the user asks to save something from the exclusion list, ask what was surprising or non-obvious — that's the part worth keeping.
Hard limit: 200 lines / 25KB. When exceeded, run a Dream cycle.
Check with: wc -l MEMORY.md && wc -c MEMORY.md
A periodic consolidation pass over memory files. Run during heartbeats or when MEMORY.md exceeds limits.
Track state in memory/heartbeat-state.json:
json
{
"lastDreamAt": "2026-03-31T15:40:00Z",
"lastDreamResult": "pruned from 269 to 85 lines"
}
memory/YYYY-MM-DD.md files since last DreamlastDreamAt in heartbeat-state.jsonTo add this system to a new OpenClaw agent:
Add the memory classification table and Dream procedure to AGENTS.md
Add size limit header to MEMORY.md: text
> 📏 限制:≤ 200 行 / 25KB | 上次整理:YYYY-MM-DD
Add lastDreamAt field to memory/heartbeat-state.json
Add Dream trigger check to HEARTBEAT.md: text
5. Run an initial Dream cycle to establish baseline
## Memory Drift Warning
Before acting on a recalled memory:
- If memory names a **file path** → check the file exists
- If memory names a **function or config** → grep for it
- If memory is a **state snapshot** (activity log, architecture) → prefer git log or reading current code
- If memory conflicts with current reality → **trust what you see now, update the memory**