← Back to PRs

#19685: feat: Dreaming Process — Autonomous Memory Consolidation

by jduartedj open 2026-02-18 02:58 View on GitHub →
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