โ† Back to skills
extension
Category: OtherNo API key required

DeepSleep

Two-phase daily memory persistence for AI agents. v3.0: unified pack+dispatch cron, smart silence handling, memory importance tiers, cross-group correlation,...

personAuthor: jeffchang2024hubclawhub

DeepSleep v3.0

Two-phase daily memory persistence for AI agents.

Like humans need sleep for memory consolidation, AI agents need DeepSleep to persist context across sessions.

What's New in v3.0

| Change | Impact | |---|---| | ๐Ÿ”ด Unified pack+dispatch cron | Single 23:50 job replaces two separate crons. Saves ~2-3ไธ‡ token/day in cron startup overhead | | ๐Ÿ”ด Silent day fast path | Skips history pull on silent days. Saves ~5-8ไธ‡ token/day when nothing happened | | ๐Ÿ”ด Smartๆ™จๆŠฅ delivery | Only sends morning briefs when there's real content, P0 due items, or stale OQs. Eliminates noise | | ๐ŸŸก Memory importance tiers | ๐Ÿ”ดP0/๐ŸŸกP1/๐ŸŸขP2 per entry. Different retention windows (7/5/3 days). Phase 3 loads P0+P1 first | | ๐ŸŸก Cross-group correlation | Detects related topics across groups. "่ง†้ข‘่ฎญ็ปƒๅฎž้ชŒๅฎค โ†” ๅƒ้—ฎๅพฎ่ฐƒๅฎž้ชŒๅฎค: both discussing Qwen-VL" | | ๐ŸŸก OQ health tracking | Tracks age of each Open Question. โš ๏ธ at 7d, escalation at 14d, archive at 30d | | ๐ŸŸก Schedule priority + reminders | P0/P1/P2 priorities with differentiated reminder frequency. P0 overdue = daily nag | | ๐ŸŸข dispatch_policy flag | Pack sets active/silent in daily file header; dispatch reads it to decide behavior | | ๐ŸŸข Memory quality audit | Weekly self-audit: compare raw conversation vs summary to catch missed info |

When to Activate

Activate when user mentions daily summary, memory persistence, sleep cycle, cross-session memory, morning brief, or nightly pack.

Architecture

23:50  cron "deepsleep" (single unified job)
         โ”‚
         โ”œโ”€โ”€ PACK PHASE
         โ”‚   โ”œโ”€โ”€ Lock date (midnight race protection)
         โ”‚   โ”œโ”€โ”€ sessions_list โ†’ detect active/silent
         โ”‚   โ”‚
         โ”‚   โ”œโ”€โ”€ [ACTIVE DAY]
         โ”‚   โ”‚   โ”œโ”€โ”€ sessions_history (parallel batch)
         โ”‚   โ”‚   โ”œโ”€โ”€ Filter + summarize with importance tiers
         โ”‚   โ”‚   โ”œโ”€โ”€ Cross-group correlation detection
         โ”‚   โ”‚   โ”œโ”€โ”€ OQ health check (age tracking)
         โ”‚   โ”‚   โ”œโ”€โ”€ Schedule update (priority + dedup)
         โ”‚   โ”‚   โ””โ”€โ”€ Write daily file (dispatch_policy: active)
         โ”‚   โ”‚
         โ”‚   โ”œโ”€โ”€ [SILENT DAY โ€” fast path, <5000 tokens]
         โ”‚   โ”‚   โ”œโ”€โ”€ Read recent daily file
         โ”‚   โ”‚   โ”œโ”€โ”€ Carry-forward with decay
         โ”‚   โ”‚   โ””โ”€โ”€ Write daily file (dispatch_policy: silent)
         โ”‚   โ”‚
         โ”‚   โ””โ”€โ”€ Update MEMORY.md (P0 only, guard rails)
         โ”‚
         โ””โ”€โ”€ DISPATCH PHASE (same session, skip re-read)
             โ”œโ”€โ”€ Dedup check (dispatch-lock.md)
             โ”œโ”€โ”€ Smart send decision per group
             โ”œโ”€โ”€ Send morning briefs (active groups only)
             โ”œโ”€โ”€ Schedule due-date reminders
             โ”œโ”€โ”€ Write per-group snapshots (tiered retention)
             โ”œโ”€โ”€ Write dispatch log
             โ””โ”€โ”€ Write dispatch lock

On-demand  Phase 3: Session Memory Restore
             โ”œโ”€โ”€ Load memory/groups/<chat_id>.md
             โ”œโ”€โ”€ Priority: load ๐Ÿ”ดP0 + ๐ŸŸกP1 first
             โ”œโ”€โ”€ Check cross-group correlations
             โ””โ”€โ”€ Check schedule.md for P0 due items

Phases

Phase 1: Deep Sleep Pack (23:50)

  1. Lock date โ€” Prevent midnight race condition
  2. Auto-discover sessions โ€” sessions_list(kinds=['group', 'main'], activeMinutes=1440)
  3. Silent day detection โ€” If no real user messages, enter fast path (no history pull, <5000 tokens)
  4. Silent Day Carry-Forward with Decay โ€” 4-tier decay: Days 1-3 full, 4-7 slim, 8-14 minimal, 15+ archive to MEMORY.md
  5. [Active day] Pull conversation history โ€” Parallel batch sessions_history
  6. Filter and summarize with importance tiers โ€” ๐Ÿ”ดP0 strategic, ๐ŸŸกP1 important, ๐ŸŸขP2 routine
  7. Cross-group correlation โ€” Detect related topics across groups
  8. OQ health check โ€” Track age, warn at 7d, escalate at 14d, archive at 30d
  9. Schedule update โ€” With P0/P1/P2 priorities, key-based dedup
  10. Write daily file โ€” Idempotent, with dispatch_policy flag and importance tiers
  11. Self-check โ€” Validate chat_id annotations, importance tags, OQ dates
  12. Update MEMORY.md โ€” Only for P0 items, with guard rails

Phase 2: Morning Dispatch (same session, immediately after pack)

  1. Dedup check โ€” dispatch-lock.md prevents double-sending
  2. Failure recovery โ€” If pack somehow failed, do emergency mini-pack
  3. Read daily file โ€” Already in context from pack (skip re-read in unified mode)
  4. Check dispatch_policy โ€” active = send briefs; silent = update snapshots only
  5. Smart send decision โ€” Per-group: send only if new content, P0 due items, or stale OQs
  6. Send per-group briefs โ€” With importance-highlighted summaries, cross-group hints, OQ warnings
  7. Schedule reminders โ€” P0 due/overdue = ๐Ÿ”ฅ in brief; P1 due = mention; P2 = summary only
  8. Write per-group snapshots โ€” Tiered retention: ๐Ÿ”ด7d, ๐ŸŸก5d, ๐ŸŸข3d. OQs and todos never expire
  9. Write dispatch log โ€” Including send/skip counts and policy
  10. Write dispatch lock

Phase 3: Session Memory Restore (on demand)

When the agent receives a message in a group:

  1. Check memory/groups/<chat_id>.md โ€” load if exists
  2. Priority loading โ€” If token budget is tight, load ๐Ÿ”ด+๐ŸŸก entries first, skip ๐ŸŸข
  3. Check cross-group correlations โ€” If this group has related groups, note it
  4. Check memory/schedule.md โ€” Any P0 items due today? Proactively mention them
  5. If snapshot missing/stale (>48h) โ€” Fall back to memory/YYYY-MM-DD.md

Phase 4: Memory Quality Audit (weekly, optional)

Once a week (suggest: Sunday heartbeat or dedicated cron), self-audit pack quality:

  1. Pick 2-3 random groups from the past week
  2. Pull raw sessions_history for those groups
  3. Compare raw conversation vs the daily summary that was generated
  4. Check for:
    • Missed important info โ€” Decisions or lessons that didn't make it into the summary
    • Over-compression โ€” Context that was lost in summarization
    • Misclassification โ€” Items marked P2 that should have been P1/P0
    • OQ staleness โ€” Questions that resolved in conversation but weren't marked done
  5. Write audit findings to memory/audit-log.md
  6. If patterns emerge (e.g., consistently missing technical decisions), update filtering criteria in pack-instructions.md

Daily Summary Template

## DeepSleep Daily Summary
<!-- dispatch_policy: active|silent -->
<!-- pack_version: 3.0 -->
<!-- silent_days: N (only if silent) -->

> Auto-discovered N active groups (24h). schedule.md: [items due / none].

### [Group Name] <!-- chat:oc_abc123 -->
- ๐Ÿ”ด Strategic decision summary
- ๐ŸŸก Important progress
- ๐ŸŸข Routine note

### ๐Ÿ”— Cross-Group Correlations (if any)
- GroupA โ†” GroupB: related topic description

### Direct Messages
- N DMs processed (no details โ€” privacy)

### ๐Ÿ”ฎ Open Questions
- Question [since: MM-DD, pending N days]
- โš ๏ธ Question [since: MM-DD, pending 14 days โ€” escalate or shelve]

### ๐Ÿ“‹ Today (Next Day)
- Action items (reader perspective)
- ๐Ÿ”ฅ P0 due: [schedule item]

### Todo
- [ ] Immediate action items

Schedule File Format

File: memory/schedule.md

| Key | Date | Source | Item | Priority | Status |
|-----|------|--------|------|----------|--------|
| ds-v30 | 2026-04-04 | DeepSleepๅฎž้ชŒๅฎค | DeepSleep v3.0 ้ชŒ่ฏ | P0 | pending |

Priority levels:

  • P0 โ€” Must complete on due date. Reminded in morning brief + Phase 3. Overdue = daily nag
  • P1 โ€” Important, mentioned in morning brief on due date
  • P2 โ€” Low priority, noted in daily summary only

Per-Group Snapshot Format

File: memory/groups/<chat_id>.md

# [Group Name] ่ฟ‘ๆœŸ่ฎฐๅฟ†
> ๆ›ดๆ–ฐๆ—ถ้—ด๏ผšYYYY-MM-DD HH:MM
> ่ฟž็ปญ้™้ป˜ N ๅคฉ๏ผŒๆœ€ๅŽๆดป่ทƒ๏ผšYYYY-MM-DD (only if silent)

## ๆœ€่ฟ‘่ฟ›ๅฑ•
- ๐Ÿ”ด [YYYY-MM-DD] Strategic item (retained 7 days)
- ๐ŸŸก [YYYY-MM-DD] Important item (retained 5 days)
- ๐ŸŸข [YYYY-MM-DD] Routine item (retained 3 days)

## ๐Ÿ”ฎ Open Questions
- Question [since: MM-DD, pending N days]

## ๐Ÿ“‹ Todo
- [ ] Incomplete (never expires)
- [x] Completed (pruned after 3 days)

## ๐Ÿ”— Related Groups
- โ†” [Related Group]: topic description

Setup

1. Create unified cron job (v3.0: single job)

# v3.0: Single unified pack+dispatch job at 23:50
openclaw cron add \
  --name "deepsleep" \
  --cron "50 23 * * *" \
  --tz "Your/Timezone" \
  --session isolated \
  --message "Execute DeepSleep v3.0. Read the deepsleep skill pack-instructions.md and follow it strictly. After pack completes, continue with dispatch (pack-instructions.md Step 6)." \
  --timeout-seconds 900 \
  --no-deliver

โš ๏ธ Migration from v2.x: If you have two separate cron jobs (deepsleep-pack and deepsleep-dispatch), remove them and create the single unified job above:

openclaw cron remove <pack-job-id>
openclaw cron remove <dispatch-job-id>
openclaw cron add ...  # the unified job above

2. Optional: Weekly audit cron

openclaw cron add \
  --name "deepsleep-audit" \
  --cron "0 10 * * 0" \
  --tz "Your/Timezone" \
  --session isolated \
  --message "Execute DeepSleep Phase 4 memory quality audit. Read deepsleep SKILL.md Phase 4 section." \
  --timeout-seconds 600 \
  --no-deliver

3. Enable cross-session visibility

openclaw config set tools.sessions.visibility all
openclaw gateway restart

4. Initialize schedule

Create memory/schedule.md with the table header.

5. Add Phase 3 restore to AGENTS.md

See Phase 3 section above for the standing order template.

Requirements

  • OpenClaw with tools.sessions.visibility set to all
  • Single cron job using agentTurn mode (--session isolated) with --timeout-seconds 900
  • --no-deliver on cron job (dispatch sends messages directly via message tool)

Privacy Notes

  • Pack writes a daily summary that dispatch may broadcast to groups. Never include private MEMORY.md content.
  • Each group only receives its own summary โ€” no cross-group content leakage.
  • Cross-group correlations mention only the topic connection, never specific conversation content from another group.
  • MEMORY.md is updated separately and stays in the main session only.
  • Per-group snapshots only contain that group's own conversation summaries.
  • DM content: only "N DMs processed" in daily summary; details go to MEMORY.md only.

Known Gotchas

  1. Cron timezone: --tz Asia/Shanghai means cron expression is in LOCAL time. Don't convert to UTC.
  2. Must use isolated agentTurn: systemEvent ignores timeoutSeconds (hardcoded ~120s). Use --session isolated.
  3. Timeout must be generous: 900s (15 min). Real-world unified pack+dispatch with 8 sessions takes ~3-5 min.
  4. Parallel tool calls: Batch sessions_history and snapshot writes in parallel.
  5. Chat ID in headers: Every ### GroupName MUST have <!-- chat:oc_xxx -->. Missing = group loses memory.
  6. Header must be exact: ## DeepSleep Daily Summary โ€” no variations.
  7. dispatch_policy flag: Pack MUST set <!-- dispatch_policy: active|silent -->. Dispatch reads this.
  8. Time perspective: Briefs use reader perspective: "yesterday did X / today do Y".
  9. Midnight race: Lock PACK_DATE at start, never re-fetch.
  10. Dispatch dedup: dispatch-lock.md written AFTER sends complete.
  11. Schedule Key dedup: Check existing keys before writing.
  12. Silent Day Decay: 4-tier (1-3d full / 4-7d slim / 8-14d minimal / 15+d archive).
  13. MEMORY.md guard rails: Append/update only. Never delete/restructure.
  14. DM privacy: Daily summary is broadcast; MEMORY.md is diary. Don't mix.
  15. Importance tiers: ๐Ÿ”ดP0 retained 7d in snapshots, ๐ŸŸกP1 5d, ๐ŸŸขP2 3d.
  16. OQ age tracking: All OQs must have [since: MM-DD, pending N days] annotation.
  17. Cross-group correlations: Only mention topic keywords, never quote another group's conversations.

Failure Recovery

If pack fails or times out:

  • Unified mode: Dispatch won't run (same session). Next day's unified job will detect missing summary and do emergency mini-pack for the missed day.
  • Manual recovery: Run dispatch-instructions.md independently โ€” it has built-in pack-failure detection and emergency mini-pack.

Verification Checklist

# 1. Manually trigger unified job
openclaw cron run <job-id>

# 2. Check completion
openclaw cron runs --id <job-id> --limit 1
# Expected: durationMs > 120000 (proves timeout works)

# 3. Check pack output
cat memory/YYYY-MM-DD.md | grep "DeepSleep Daily Summary"
cat memory/YYYY-MM-DD.md | grep "dispatch_policy"
cat memory/YYYY-MM-DD.md | grep "pack_version: 3.0"

# 4. Check dispatch output
ls -la memory/groups/
# Expected: updated timestamps on group snapshot files

# 5. Check dispatch log
tail -20 memory/dispatch-log.md

# 6. Check Feishu groups (only active groups should receive briefs)

Inspirations

Built with insights from the community: agent-sleep (multi-level sleep), memory-reflect (filtering criteria), jarvis-memory-architecture (cron inbox), memory-curator (open questions).