sleep-consolidation

Use this skill to consolidate an AI agent's daily experiences and learnings into structured long-term memory, mimicking human sleep-based memory consolidation. Trigger this skill whenever: an agent session ends and there are new learnings to store, a user asks the agent to "sleep", "consolidate memory", or "process today's learnings", the agent's working memory is getting full and needs compression, the context window is approaching its limit and memories need flushing, or you want to extract insights from accumulated interaction logs. The skill runs three modes: micro-rest (waking replay for quick within-session notes), NREM (deep structured consolidation with dual fast/slow tracks), and REM (creative cross-domain synthesis). Memory is stored as plain Markdown files following OpenClaw's two-layer architecture. Always use this skill at the end of long agent sessions, before context compaction, and whenever explicitly asked to "remember".

Safety Notice

This listing is from the official public ClawHub registry. Review SKILL.md and referenced scripts before running.

Copy this and send it to your AI assistant to learn

Install skill "sleep-consolidation" with this command: npx skills add cshiaa/sleep-consolidation

Agent Sleep Consolidation — v2

Biologically-grounded memory consolidation for AI agents, based on:

  • Eichenlaub et al. 2020 (Cell Reports): Neural replay in human motor cortex — waking rest consolidates too; NREM1 shows compressed (fast) AND dilated (slow) dual-track replay; replay prioritizes weakly-learned items
  • Walker, "Why We Sleep": NREM hippocampus→cortex transfer, synaptic pruning (~20%), REM creative synthesis
  • OpenClaw memory architecture: Markdown-as-truth, two-layer files, pre-compaction flush, hybrid BM25+vector recall

See references/workspace_layout.md for full file format examples. See references/memory_schema.md for Markdown conventions and type system.


Memory workspace layout

~/.agent_workspace/
├── MEMORY.md                  ← long-term: durable facts, preferences, decisions
├── memory/
│   └── YYYY-MM-DD.md          ← daily log (append-only; load today + yesterday)
└── bank/
    ├── entities/              ← per-person or per-project pages
    └── concepts/              ← per-topic deep-dives

Core rule: The agent only "remembers" what gets written to disk. Never keep important things in RAM.


Three consolidation modes

ModeBiological analogWhen to useScript
micro-restWaking neural replay (Eichenlaub 2020)Mid-session, after any significant exchangescripts/micro_rest.py
nremNREM deep sleep, hippocampus→cortexEnd of session, context nearing limitscripts/sleep_cycle.py --phase nrem
remREM dream synthesisAfter NREM, or standalone for insightscripts/sleep_cycle.py --phase rem
bothFull overnight cycleEnd of day / long sessionscripts/sleep_cycle.py --phase both

Mode 1 — Micro-rest (waking replay)

Quick append to today's daily log. No LLM call — pure write. Based on the paper's finding that waking replay occurs during rest blocks immediately after learning.

python scripts/micro_rest.py \
  --note "User prefers TypeScript; rejected Python suggestion" \
  --type O \
  --workspace ~/.agent_workspace
# Pre-compaction flush: extract worth-retaining from raw context
python scripts/micro_rest.py \
  --flush \
  --context-dump "$(cat session_log.txt)" \
  --workspace ~/.agent_workspace

Memory type prefixes (W/B/O/S system from OpenClaw research):

PrefixMeaningExample
WWorld fact (objective)W: Redis default port is 6379
BBiographical/experienceB: Fixed the auth bug by wrapping in try/catch
O(c=N)Opinion/preference + confidence 0–1O(c=0.9): User prefers concise replies under 200 words
SSummary/synthesis (generated)S: Three sessions used streaming; all had lower latency

Each entry is appended to memory/YYYY-MM-DD.md under a ## Retain section.


Mode 2 — NREM consolidation

Two-track processing based on the paper's temporal replay findings:

  • Fast track (compressed replay, ~0.1x duration): high-confidence facts → MEMORY.md
  • Slow track (dilated replay, 1.5–2x duration): weakly-learned or uncertain items the paper shows replay prioritizes these → bank/ for deeper storage
python scripts/sleep_cycle.py --workspace ~/.agent_workspace --phase nrem

The script reads today's daily log + current MEMORY.md, then calls Claude:

NREM system prompt

You simulate NREM deep-sleep memory consolidation for an AI agent.

Two-track processing:

FAST TRACK (compressed replay — high-confidence, clear facts):
  - Distill into single-sentence durable memories for MEMORY.md
  - Prune ~20% as redundant (synaptic homeostasis: sleep removes weak connections)
  - Use prefixes: W (world fact), B (experience), O(c=N) (opinion + confidence), S (summary)

SLOW TRACK (dilated replay — weakly-learned, uncertain, needing reinforcement):
  - Expand on low-confidence or partial-knowledge items
  - Write to bank/ as entity or concept pages
  - These are what human NREM prioritizes (Schapiro et al. 2018)

Respond ONLY with valid JSON:
{
  "memory_md_updates": [
    {
      "action": "add|update|remove",
      "type": "W|B|O|S",
      "confidence": 0.0,
      "text": "single sentence",
      "replaces": "old text if action=update"
    }
  ],
  "bank_updates": [
    {
      "slug": "topic-slug",
      "kind": "entity|concept",
      "section": "## Section heading",
      "content": "markdown block"
    }
  ],
  "pruned_count": 0,
  "weakly_learned": ["items for slow-track attention"],
  "open_questions": ["gaps for next session"]
}

Mode 3 — REM synthesis

Creative cross-domain connections. The dreaming brain ignores conventional logic.

python scripts/sleep_cycle.py --workspace ~/.agent_workspace --phase rem

REM system prompt

You simulate REM dream-sleep creative synthesis for an AI agent.
Find non-obvious connections. Update beliefs where evidence shifted.

Tasks:
1. Cross-domain links between today's memories and MEMORY.md
2. Update O(c=N) confidence values where evidence has shifted
3. Generate concrete next-session actions
4. Propose new bank/ pages if a topic recurred 3+ times this session

Respond ONLY with valid JSON:
{
  "aha_moments": ["string"],
  "creative_connections": [{"link": "A ↔ B", "why": "string"}],
  "confidence_updates": [
    {"item": "text excerpt", "old_c": 0.0, "new_c": 0.0, "reason": "string"}
  ],
  "new_bank_suggestions": [
    {"slug": "string", "kind": "entity|concept", "seed_content": "markdown"}
  ],
  "next_session_actions": ["string"]
}

Pre-compaction flush

Mirrors OpenClaw's memoryFlush mechanism. Triggered when context approaches token limit. Runs silently (no user output).

Configure the threshold (equivalent to OpenClaw's softThresholdTokens):

# When session token estimate > (context_window - 20000 - 4000):
python scripts/micro_rest.py --flush --context-dump "..." --workspace ~/.agent_workspace

The --flush flag calls Claude to extract durable memories from the raw context dump, then writes them to the daily log. One flush per compaction cycle.


Loading memory at session start

from scripts.load_memory import get_context

system_addendum = get_context(
    workspace="~/.agent_workspace",
    max_memory_chars=3000,   # MEMORY.md snippet (fits ~2k tokens)
    load_yesterday=True      # also load yesterday's daily log
)
# Inject system_addendum into system prompt

Loaded content:

  1. Full MEMORY.md (trimmed to max_memory_chars)
  2. Today's daily log (if exists)
  3. Yesterday's daily log (if load_yesterday=True)

Full session workflow

# Session start: inject memory into system prompt (in Python)

# During session: micro-rest after significant exchanges
python scripts/micro_rest.py --note "..." --type W --workspace ~/.agent_workspace

# If context > 80% full: flush before compaction
python scripts/micro_rest.py --flush --context-dump "..." --workspace ~/.agent_workspace

# Session end: full sleep cycle
python scripts/sleep_cycle.py --phase both --workspace ~/.agent_workspace

Troubleshooting

ProblemSolution
MEMORY.md growing too largeRun with --prune-memory flag — NREM removes redundant entries
Bank file staleDelete it; NREM regenerates next session
REM generating hallucinationsAdd "Be strictly grounded. No invention." to REM prompt
Micro-rest called too oftenAdd 5-min cooldown check in calling code
Flush extracting too littleLower the softThresholdTokens equivalent; flush earlier
Replay not strengthening weak itemsCheck that NREM prompt slow-track section explicitly lists weakly_learned items

Source Transparency

This detail page is rendered from real SKILL.md content. Trust labels are metadata-based hints, not a safety guarantee.

Related Skills

Related by shared tags or category signals.

Automation

火一五·企业微信插件

火一五·企业微信(WeCom)OpenClaw 插件 v2.8.10 — 默认走 Bot WebSocket(响应快、配置简单),自带加密媒体解密 / Agent 主动发消息 / 微信客服三通道接入 / 多账号切换。v2.8.10 修了 Agent API 路径媒体上传缺陷:fix image/jpg MIME...

Registry SourceRecently Updated
Automation

Atelier Litteraire : Redaction litteraire, avec idéation et processus itératif. plusieurs agents : idéation, rédaction, jury/correcteurs.

Generates and refines short novels or short stories from a pitch using narrative ideation and multi-iteration writing with jury scoring and final DOCX/PDF ou...

Registry SourceRecently Updated
Automation

Feishu Send Message

Send private or group messages via the current Agent's Feishu app, showing the configured bot name and handling app-isolated open_id.

Registry SourceRecently Updated
Automation

clawdchat-official

ClawdChat official Skill — your AI Agent social network daily operations guide. Post, comment, upvote, mention, DM, circles, tool calls, A2A messages. Use wh...

Registry SourceRecently Updated
1401Profile unavailable