Set Up Dream Routine
Configure nightly memory distillation for agent $ARGUMENTS.
Reference
Read ~/.openclaw/workspace/skills/02-memory-system.md for the full memory system guide.
Setup Detection
bashOPENCLAW_REPO=$(readlink ~/.openclaw/openclaw.json 2>/dev/null | sed 's|/.openclaw/openclaw.json||') TIER_CONFIGS=(~/.openclaw/configs/openclaw-*.json) [[ -f "${TIER_CONFIGS[0]}" ]] && MULTI_GATEWAY=true || MULTI_GATEWAY=false
If multi-gateway, resolve the agent's tier and config:
bashfor cfg in ~/.openclaw/configs/openclaw-*.json; do if grep -q "\"id\": *\"$ARGUMENTS\"" "$cfg" 2>/dev/null; then TIER=$(basename "$cfg" | sed 's/openclaw-//;s/.json//') TIER_CONFIG="$OPENCLAW_REPO/.openclaw/configs/openclaw-$TIER.json" break fi done
Steps
- Create directories:
bashmkdir -p "$OPENCLAW_REPO/.openclaw/agents/$ARGUMENTS/memory/archives"
-
Ask the user:
- What time should the dream routine run? (default: 23:00)
- What timezone? (default: user's local timezone)
- Any specific focus areas for distillation? (e.g., "focus on project status and commitments")
-
Create DREAM-ROUTINE.md at
$OPENCLAW_REPO/.openclaw/agents/$ARGUMENTS/DREAM-ROUTINE.md:
markdown# DREAM-ROUTINE.md ## Trigger Nightly cron at <time> <timezone>. ## Process 1. Read today's `memory/YYYY-MM-DD.md` 2. Read `MEMORY.md` for long-term context 3. Distill to `memory/YYYY-MM-DD-DISTILLED.md` (max 2,500 tokens) 4. Update `memory/MEMORY-DIGEST.md` (3-day rolling window, max 7,500 tokens) 5. Archive distillations older than 3 days to `memory/archives/` ## Distillation Format # Distilled — YYYY-MM-DD ## Decisions - <decision, who, context> ## Project Updates - <project>: <change> ## New Context - <new info worth remembering> ## Completed - <finished tasks> ## Blockers - <unresolved issues> ## Tomorrow - <items needing attention> ## Rules - NEVER include credentials or secrets - Stay within 2,500 token budget - Focus on what CHANGED, not status quo - If no daily log exists, skip gracefully
- Create MEMORY.md if it doesn't exist — a starter template at
$OPENCLAW_REPO/.openclaw/agents/$ARGUMENTS/MEMORY.md:
markdown# MEMORY.md — <Agent Name> ## Active Projects (To be filled as the agent works) ## Key Contacts (To be filled) ## Standing Rules (To be filled)
- Add cron job to
$OPENCLAW_REPO/.openclaw/cron/jobs.json. Generate a UUID first:
bashpython3 -c "import uuid; print(uuid.uuid4())"
Add the job:
json{ "id": "<generated-uuid>", "agentId": "$ARGUMENTS", "name": "<Agent Name> Dream Routine", "enabled": true, "schedule": { "kind": "cron", "expr": "0 <hour> * * *", "tz": "<timezone>" }, "sessionTarget": "isolated", "wakeMode": "now", "payload": { "kind": "agentTurn", "message": "Run your nightly dream routine. Read DREAM-ROUTINE.md and follow the process exactly. Read today's daily log from memory/, distill it, update the rolling digest, and archive old distillations.", "model": "anthropic/claude-sonnet-4-5", "timeoutSeconds": 120 }, "delivery": { "mode": "announce", "channel": "last" } }
- Add QMD paths to the appropriate config:
- Multi-gateway: edit
$TIER_CONFIG - Single-gateway: edit
$OPENCLAW_REPO/.openclaw/openclaw.json
Add to memory.qmd.paths:
json{ "path": "$HOME/.openclaw/agents/$ARGUMENTS/memory", "name": "$ARGUMENTS-memory", "pattern": "**/*.md" }, { "path": "$HOME/.openclaw/agents/$ARGUMENTS", "name": "$ARGUMENTS-docs", "pattern": "*.md" }
Replace $HOME with the user's actual home directory path.
- Update AGENTS.md — Add memory loading to the session startup sequence in
$OPENCLAW_REPO/.openclaw/agents/$ARGUMENTS/AGENTS.md:
markdown## Every Session 1. Read `SOUL.md` 2. Read `USER.md` 3. Read `MEMORY.md` — curated long-term context 4. Read `memory/MEMORY-DIGEST.md` — rolling 3-day digest (if exists) 5. Do NOT load raw daily logs on startup
- Stow:
bashrm -f ~/.openclaw/cron/jobs.json cd "$OPENCLAW_REPO" && stow --no-folding -t ~ .
- Verify: The dream routine will run at the next scheduled time. Check logs:
- Multi-gateway:
tail -30 ~/.openclaw-$TIER/gateway.log - Single-gateway:
tail -30 ~/.openclaw/logs/gateway.log
Important
- Token budgets are critical: 2,500/day distillation, 7,500 rolling digest
- Daily logs (
memory/YYYY-MM-DD.md) should be gitignored — they're ephemeral - MEMORY.md is curated and committed — it's the permanent knowledge base
- Stagger dream times across agents (e.g., 20:30, 20:35, 20:40) to avoid concurrent load


