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
CODEBLOCK0
Phases
Phase 1: Deep Sleep Pack (23:50)
- 1. Lock date — Prevent midnight race condition
- Auto-discover sessions — INLINECODE2
- Silent day detection — If no real user messages, enter fast path (no history pull, <5000 tokens)
- Silent Day Carry-Forward with Decay — 4-tier decay: Days 1-3 full, 4-7 slim, 8-14 minimal, 15+ archive to MEMORY.md
- [Active day] Pull conversation history — Parallel batch INLINECODE3
- Filter and summarize with importance tiers — 🔴P0 strategic, 🟡P1 important, 🟢P2 routine
- Cross-group correlation — Detect related topics across groups
- OQ health check — Track age, warn at 7d, escalate at 14d, archive at 30d
- Schedule update — With P0/P1/P2 priorities, key-based dedup
- Write daily file — Idempotent, with
dispatch_policy flag and importance tiers - Self-check — Validate chat_id annotations, importance tags, OQ dates
- 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 - Failure recovery — If pack somehow failed, do emergency mini-pack
- Read daily file — Already in context from pack (skip re-read in unified mode)
- Check dispatch_policy —
active = send briefs; silent = update snapshots only - Smart send decision — Per-group: send only if new content, P0 due items, or stale OQs
- Send per-group briefs — With importance-highlighted summaries, cross-group hints, OQ warnings
- Schedule reminders — P0 due/overdue = 🔥 in brief; P1 due = mention; P2 = summary only
- Write per-group snapshots — Tiered retention: 🔴7d, 🟡5d, 🟢3d. OQs and todos never expire
- Write dispatch log — Including send/skip counts and policy
- 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 - Priority loading — If token budget is tight, load 🔴+🟡 entries first, skip 🟢
- Check cross-group correlations — If this group has related groups, note it
- Check
memory/schedule.md — Any P0 items due today? Proactively mention them - If snapshot missing/stale (>48h) — Fall back to INLINECODE10
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
- Pull raw
sessions_history for those groups - Compare raw conversation vs the daily summary that was generated
- 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 INLINECODE12
- If patterns emerge (e.g., consistently missing technical decisions), update filtering criteria in pack-instructions.md
Daily Summary Template
CODEBLOCK1
Schedule File Format
File: INLINECODE13
CODEBLOCK2
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: INLINECODE14
CODEBLOCK3
Setup
1. Create unified cron job (v3.0: single job)
CODEBLOCK4
⚠️ 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:
CODEBLOCK5
2. Optional: Weekly audit cron
CODEBLOCK6
3. Enable cross-session visibility
CODEBLOCK7
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 INLINECODE17 - Single cron job using
agentTurn mode (--session isolated) with INLINECODE20 - INLINECODE21 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. - Must use isolated agentTurn:
systemEvent ignores timeoutSeconds (hardcoded ~120s). Use --session isolated. - Timeout must be generous: 900s (15 min). Real-world unified pack+dispatch with 8 sessions takes ~3-5 min.
- Parallel tool calls: Batch
sessions_history and snapshot writes in parallel. - Chat ID in headers: Every
### GroupName MUST have <!-- chat:oc_xxx -->. Missing = group loses memory. - Header must be exact:
## DeepSleep Daily Summary — no variations. - dispatchpolicy flag: Pack MUST set
<!-- dispatch_policy: active|silent -->. Dispatch reads this. - Time perspective: Briefs use reader perspective: "yesterday did X / today do Y".
- Midnight race: Lock PACKDATE at start, never re-fetch.
- Dispatch dedup:
dispatch-lock.md written AFTER sends complete. - Schedule Key dedup: Check existing keys before writing.
- Silent Day Decay: 4-tier (1-3d full / 4-7d slim / 8-14d minimal / 15+d archive).
- MEMORY.md guard rails: Append/update only. Never delete/restructure.
- DM privacy: Daily summary is broadcast; MEMORY.md is diary. Don't mix.
- Importance tiers: 🔴P0 retained 7d in snapshots, 🟡P1 5d, 🟢P2 3d.
- OQ age tracking: All OQs must have
[since: MM-DD, pending N days] annotation. - 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
CODEBLOCK8
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).
DeepSleep v3.0
AI智能体的双阶段日常记忆持久化方案。
如同人类需要睡眠来巩固记忆,AI智能体需要DeepSleep来跨会话保持上下文。
v3.0 新特性
| 变更 | 影响 |
|---|
| 🔴 统一打包+分发定时任务 | 单个23:50任务替代两个独立定时任务。每次定时任务启动节省约2-3万token开销 |
| 🔴 静默日快速路径 |
静默日跳过历史拉取。无事发生时每天节省约5-8万token |
| 🔴
智能晨报投递 | 仅在存在真实内容、P0到期项或过期开放问题时发送晨间简报。消除噪音 |
| 🟡
记忆重要性分级 | 每条记录标记🔴P0/🟡P1/🟢P2。不同保留窗口(7/5/3天)。阶段3优先加载P0+P1 |
| 🟡
跨群组关联 | 检测不同群组间的相关话题。视频训练实验室 ↔ 千问微调实验室:都在讨论Qwen-VL |
| 🟡
开放问题健康追踪 | 追踪每个开放问题的存续时间。7天⚠️警告,14天升级处理,30天归档 |
| 🟡
日程优先级+提醒 | P0/P1/P2优先级差异化提醒频率。P0逾期=每日催促 |
| 🟢
dispatch_policy标志 | 打包阶段在每日文件头部设置active/silent;分发阶段读取以决定行为 |
| 🟢
记忆质量审计 | 每周自我审计:对比原始对话与摘要,发现遗漏信息 |
何时激活
当用户提及每日总结、记忆持久化、睡眠周期、跨会话记忆、晨间简报或夜间打包时激活。
架构
23:50 定时任务 deepsleep(单一统一任务)
│
├── 打包阶段
│ ├── 锁定日期(午夜竞态保护)
│ ├── sessions_list → 检测活跃/静默
│ │
│ ├── [活跃日]
│ │ ├── sessions_history(并行批量)
│ │ ├── 按重要性分级过滤和总结
│ │ ├── 跨群组关联检测
│ │ ├── 开放问题健康检查(存续追踪)
│ │ ├── 日程更新(优先级+去重)
│ │ └── 写入每日文件(dispatch_policy: active)
│ │
│ ├── [静默日 — 快速路径,<5000 token]
│ │ ├── 读取最近每日文件
│ │ ├── 带衰减的延续
│ │ └── 写入每日文件(dispatch_policy: silent)
│ │
│ └── 更新MEMORY.md(仅P0,带防护)
│
└── 分发阶段(同一会话,跳过重新读取)
├── 去重检查(dispatch-lock.md)
├── 按群组的智能发送决策
├── 发送晨间简报(仅活跃群组)
├── 日程到期提醒
├── 写入各群组快照(分级保留)
├── 写入分发日志
└── 写入分发锁
按需 阶段3:会话记忆恢复
├── 加载 memory/groups/.md
├── 优先级:先加载🔴P0 + 🟡P1
├── 检查跨群组关联
└── 检查 schedule.md 中的P0到期项
阶段
阶段1:深度睡眠打包(23:50)
- 1. 锁定日期 — 防止午夜竞态条件
- 自动发现会话 — sessionslist(kinds=[group, main], activeMinutes=1440)
- 静默日检测 — 若无真实用户消息,进入快速路径(不拉取历史,<5000 token)
- 静默日带衰减延续 — 4级衰减:第1-3天完整,第4-7天精简,第8-14天最小化,第15天以上归档至MEMORY.md
- [活跃日]拉取对话历史 — 并行批量 sessionshistory
- 按重要性分级过滤和总结 — 🔴P0战略性,🟡P1重要,🟢P2常规
- 跨群组关联 — 检测不同群组间的相关话题
- 开放问题健康检查 — 追踪存续时间,7天警告,14天升级,30天归档
- 日程更新 — 带P0/P1/P2优先级,基于键的去重
- 写入每日文件 — 幂等,带dispatchpolicy标志和重要性分级
- 自我检查 — 验证chatid注释、重要性标签、开放问题日期
- 更新MEMORY.md — 仅P0项,带防护
阶段2:晨间分发(同一会话,打包后立即执行)
- 1. 去重检查 — dispatch-lock.md防止重复发送
- 故障恢复 — 若打包失败,执行紧急迷你打包
- 读取每日文件 — 打包阶段已加载到上下文(统一模式下跳过重新读取)
- 检查dispatch_policy — active=发送简报;silent=仅更新快照
- 智能发送决策 — 按群组:仅在有新内容、P0到期项或过期开放问题时发送
- 发送各群组简报 — 带重要性高亮摘要、跨群组提示、开放问题警告
- 日程提醒 — P0到期/逾期=简报中🔥标记;P1到期=提及;P2=仅摘要
- 写入各群组快照 — 分级保留:🔴7天,🟡5天,🟢3天。开放问题和待办事项永不过期
- 写入分发日志 — 包含发送/跳过次数及策略
- 写入分发锁
阶段3:会话记忆恢复(按需)
当智能体在群组中收到消息时:
- 1. 检查 memory/groups/.md — 若存在则加载
- 优先级加载 — 若token预算紧张,先加载🔴+🟡条目,跳过🟢
- 检查跨群组关联 — 若该群组有关联群组,进行标注
- 检查 memory/schedule.md — 今日是否有P0到期项?主动提及
- 若快照缺失/过期(>48小时) — 回退到 memory/YYYY-MM-DD.md
阶段4:记忆质量审计(每周,可选)
每周一次(建议:周日心跳或专用定时任务),自我审计打包质量:
- 1. 从过去一周随机选取2-3个群组
- 拉取这些群组的原始 sessions_history
- 对比原始对话与生成的每日摘要
- 检查:
-
遗漏的重要信息 — 未纳入摘要的决策或经验教训
-
过度压缩 — 摘要过程中丢失的上下文
-
错误分类 — 标记为P2但应为P1/P0的项
-
开放问题过期 — 对话中已解决但未标记完成的开放问题
- 5. 将审计结果写入 memory/audit-log.md
- 若发现模式(如持续遗漏技术决策),更新pack-instructions.md中的过滤标准
每日摘要模板
markdown
DeepSleep 每日摘要
自动发现N个活跃群组(24小时内)。schedule.md:[到期项/无]。
[群组名称]
🔗 跨群组关联(如有)
私信
🔮 开放问题
- - 开放问题 [起始:MM-DD,已存续N天]
- ⚠️ 开放问题 [起始:MM-DD,已存续14天 — 升级或搁置]
📋 今日(次日)
待办
日程文件格式
文件:memory/schedule.md
markdown
| 键 | 日期 | 来源 | 事项 | 优先级