#19685: feat: Dreaming Process — Autonomous Memory Consolidation
docs
gateway
size: M
## 🌙 Dreaming Process — Autonomous Memory Consolidation
Inspired by how biological brains consolidate memories during sleep, this PR adds a built-in **dreaming process** that runs during low-activity periods to autonomously review, consolidate, and organize an agent's accumulated memories.
### What It Does
A scheduled isolated cron job that:
1. Runs during configured quiet hours (default: 3 AM daily)
2. Checks for recent user activity — skips if user was active recently
3. Reviews the last N daily memory files (`memory/YYYY-MM-DD.md`)
4. Consolidates significant events, decisions, and lessons into long-term memory (`MEMORY.md`)
5. Optionally sends a brief summary notification
### Why This Matters
1. **Biological analogy that works** — Like hippocampus→neocortex memory transfer during sleep. Human brains don't store memories during the day and call it done — during sleep, the hippocampus replays experiences and transfers important ones to the neocortex. This is the AI equivalent.
2. **Token efficiency** — Uses a cheap model in an isolated session instead of expensive conversational tokens during heartbeats. No conversation history overhead.
3. **Consistent memory quality** — Guaranteed regular maintenance vs inconsistent manual consolidation.
4. **Self-improving context** — Systematic consolidation = better long-term memory = better responses over time.
5. **Separation of concerns** — Memory maintenance is infrastructure, not conversation.
6. **Personality development** — Reflect mode enables genuine self-analysis and pattern recognition.
### Three Modes
| Mode | What it does | Use case |
|------|-------------|----------|
| `consolidate` | Review daily files → update MEMORY.md | Default, lightweight |
| `reflect` | Consolidate + analyze behavioral patterns | Weekly deep-dive |
| `organize` | Consolidate + clean workspace files | Monthly maintenance |
### Configuration
```yaml
dreaming:
enabled: true
schedule: "0 3 * * *"
model: "auto"
lookbackDays: 7
mode: "consolidate"
quietMinutes: 60
delivery:
enabled: false
```
### Activity Guard
Respects user activity — skips if user was active within `quietMinutes`. Uses the **session store** `updatedAt` timestamps (persisted on disk) to determine last user activity. This survives gateway restarts — no in-memory singletons.
Previously used a volatile in-memory tracker (`user-activity.ts`) which was deleted in favor of reading `max(updatedAt)` across all sessions from the persisted store.
### Files Changed
- `src/infra/dreaming.ts` — Config types, prompt builder, cron job builder, activity guard
- `src/infra/dreaming.test.ts` — Comprehensive unit tests
- `docs/rfcs/dreaming-process.md` — Full design rationale and RFC
- `src/config/types.openclaw.ts` — `dreaming?: Partial<DreamingConfig>` added to `OpenClawConfig`
- `src/gateway/server.impl.ts` — Gateway registration: registers dreaming cron job on startup via `cron.add()`
- `src/gateway/server-cron.ts` — `shouldDream()` called before executing dreaming jobs, using persisted session timestamps
### Commits
1. **`c5ebe387`** — Core dreaming logic: config types, prompt builder, cron job factory, activity guard, unit tests, RFC
2. **`832c9d2c`** — Integration: config schema, gateway startup registration, activity tracking module
3. **`14498968`** — Replaced in-memory activity singleton with persisted session store `updatedAt`
### Real-World Validation
This has been running as a manual cron job in production for weeks. This PR promotes it to a first-class configurable feature.
### Future Work
- Dream journaling (`memory/dreams/`)
- Adaptive scheduling
- Forgetting curve
- Cross-agent memory sharing
Most Similar PRs
#6060: feat(onboarding): add Memory Optimization step to onboarding wizard
by GodsBoy · 2026-02-01
68.2%
#12806: feat(memory): add continuity rollup system for session persistence
by koala73 · 2026-02-09
66.8%
#22220: feat(bootstrap): cache session's bootstrap files so we don't invali...
by anisoptera · 2026-02-20
66.5%
#19341: Mind Memory Fork
by juliopx · 2026-02-17
66.2%
#7196: docs: Agent continuity - the 'stranger problem' and lighter approach
by sincere-arjun · 2026-02-02
66.2%
#11457: feat: Add hybrid memory mode with auto-created daily log templates
by Undertone0809 · 2026-02-07
65.4%
#18912: feat: periodic fact extraction from conversations
by ruypang · 2026-02-17
65.2%
#21855: feat: add memory-bank skill — persistent file-based context
by winstonkoh87 · 2026-02-20
64.9%
#7480: feat: Add CoreMemories hierarchical memory system
by Itslouisbaby · 2026-02-02
64.4%
#10644: feat: add runDuringHeartbeats option for memory flush (AI Assisted)
by tripphillips · 2026-02-06
63.9%