Skip to content
maenifold
GitHub

Cognitive Sleep Cycle (Orchestrator)

5 steps

Serialized orchestration for memory maintenance during agent sleep. Runs 5 specialist workflows in dependency order: repair → hub-detection → consolidation → epistemic → status. Each phase produces cleaner data for the next — quality cascades downhill.

Triggers

sleep cyclememory consolidationcognitive maintenancegraph maintenancecustodiansleep

Steps

  1. 1.

    🔧 Phase 1: Concept Repair

    Dispatch memory-repair specialist. This runs FIRST because all downstream phases need normalized concepts.

    Repair normalizes WikiLink variants (plurals, case, typos) so hub-detection gets accurate degree counts, consolidation promotes clean concepts, and epistemic searches return precise results.

    🎯 REQUIREMENTS:

    • Repair: SHALL use graph tools (analyze_concept_corruption, repair_concepts, sync), NOT read_memory
    • Always dryRun=true before applying repairs
    • Sync graph after repairs to rebuild with normalized concepts

    ⏱️ Duration: 15-30 minutes

    Tools:Task*
    Effort:low
    Guardrails
    • tool_access_safety: Repair MUST NOT use read_memory (NFR-7.11.3)
    • dry_run_first: Always preview repairs with dryRun=true before applying
  2. 2.

    🎯 Phase 2: Hub Detection

    Dispatch memory-hub-detection specialist. Runs AFTER repair so degree counts reflect normalized concepts.

    Hub detection identifies generic hubs (tool, agent, etc.) that connect to everything, updates .wikilink-filter, strips hub WikiLinks from files, and rebuilds the graph. Consolidation and epistemic then operate on a graph free of noise.

    🎯 REQUIREMENTS:

    • Hub detection: SHALL use graph tools (build_context, find_similar_concepts, repair_concepts, sync), NOT read_memory
    • Always dryRun=true before applying repair_concepts
    • Rebuild graph via sync after stripping hubs

    ⏱️ Duration: 15-30 minutes

    Tools:Task*
    Effort:low
    Guardrails
    • tool_access_safety: Hub detection MUST NOT use read_memory; MUST dryRun repair_concepts first (NFR-11.3.x)
  3. 3.

    💾 Phase 3: Consolidation

    Dispatch memory-consolidation specialist. Runs AFTER repair + hub-detection so it promotes clean, hub-free concepts into durable semantic memory.

    Consolidation replays high-significance episodic content (thinking sessions), distills it into semantic memory notes with clean WikiLinks, and synthesizes novel connections. This is the only phase that MAY use read_memory (access boosting is semantically correct for content being consolidated).

    🎯 REQUIREMENTS:

    • Consolidation: MAY use read_memory (access boosting is semantically correct)
    • New semantic notes SHOULD use WikiLinks validated by the clean graph
    • Consolidated notes are written to appropriate knowledge folders (not custodian/)

    ⏱️ Duration: 30-45 minutes

    Tools:Task*
    Effort:low
    Guardrails
    • tool_access_safety: Consolidation MAY use read_memory (NFR-7.11.1)
    • no_custodian_files: Consolidated notes go to knowledge folders, NOT memory://custodian/
  4. 4.

    ⚖️ Phase 4: Epistemic Review

    Dispatch memory-epistemic specialist. Runs AFTER consolidation so search_memories includes freshly consolidated semantic notes when validating assumptions.

    Epistemic review queries the assumption ledger, searches for evidence using the clean graph, and updates assumption statuses. Validated assumptions become immortal; invalidated assumptions decay aggressively.

    🎯 REQUIREMENTS:

    • Epistemic: SHALL use assumption_ledger and search_memories, NOT read_memory
    • Status changes require cited evidence
    • Validated = immortal (NFR-7.8.1), invalidated = aggressive decay (NFR-7.8.3)

    ⏱️ Duration: 15-30 minutes

    Tools:Task*
    Effort:low
    Guardrails
    • tool_access_safety: Epistemic MUST NOT use read_memory (NFR-7.11.4)
    • evidence_required: Status changes require cited evidence from search_memories
  5. 5.

    🍂 Phase 5: Status & Reporting

    Dispatch memory-status specialist, then compile the full sleep cycle report.

    Status runs last — it's pure observation (list_memories for timestamps) and doesn't modify anything. Running it last means the report reflects the final state after all modifications.

    After decay completes, compile the full sleep cycle report:

    1. Repair: Concepts normalized, variants merged, graph rebuilt
    2. Hub Detection: Hubs identified, filter updated, hub WikiLinks stripped
    3. Consolidation: Episodic content promoted, new semantic notes created
    4. Epistemic: Assumptions reviewed, statuses updated, evidence cited
    5. Status: Tier breakdown, flagged items, overall memory health

    Compile wake context (<2000 tokens):

    • Key insights and priorities for next session
    • Items flagged for human review
    • Cycle metrics (items processed per phase)

    ⏱️ Duration: 15-30 minutes

    Tools:Task*sequential_thinking
    Effort:medium
    Guardrails
    • tool_access_safety: Decay MUST NOT use read_memory (NFR-7.11.2)
    • context_size: Wake context should be concise (<2000 tokens)
    • no_persistence: Wake context is returned as output, NOT written to memory://
    • completeness_check: All 5 phases must have returned output before compiling