Sleep Consolidation

Mnemosyne's background process that promotes aged Working Memory entries to Episodic Memory, inspired by human sleep's role in memory consolidation.

What Sleep Does

During each consolidation cycle, Mnemosyne:

  1. Scans Working Memory for entries older than TTL/2 (12 hours by default)
  2. Groups candidates by source
  3. Summarizes each group via local LLM (TinyLlama) or AAAK text substitution
  4. Promotes summaries to Episodic Memory (with summary_of tracking originals)
  5. Evicts original Working Memory entries

Trigger Conditions

Consolidation triggers on:

  • Age threshold: When Working Memory entries exceed TTL/2 (default: 12 hours with 24h TTL)
  • Explicit call: mem.sleep() or mem.consolidate() for manual consolidation
  • auto_sleep: Background thread that periodically runs consolidation without explicit calls (configure via config.yaml or MNEMOSYNE_AUTO_SLEEP env var)
  • Shutdown: Graceful process exit

Consolidation Pipeline


flowchart LR
  A[Working Memory] -->|age > TTL/2| B[Candidate Selection]
  B -->|group by source| C[Group Entries]
  C -->|summarize| D[LLM or AAAK]
  D -->|promote| E[Episodic Memory]
  C -->|evict originals| F[Delete from Working]

Step-by-Step

  1. Candidate selection: Find all Working Memory entries where created_at < now - TTL/2
  2. Group by source: Cluster candidates by their source field
  3. Summarize: For each group, generate a summary using:
    • Local LLM (TinyLlama) if available
    • AAAK encode() text substitution as fallback
  4. Promote: Insert summary into episodic_memory with summary_of referencing the original IDs
  5. Evict: Delete the original entries from working_memory
  6. Log: Record the consolidation in consolidation_log

Retention Values

ParameterDefaultDescription
MNEMOSYNE_WM_MAX10000Maximum Working Memory entries
TTL24hTime-to-live for Working Memory entries

Monitoring Consolidation

Consolidation events are logged to the consolidation_log table:

ColumnTypeDescription
idINTEGERAuto-increment primary key
session_idTEXTSession that was consolidated
items_consolidatedINTEGERNumber of entries promoted
summary_previewTEXTPreview of the generated summary
created_atTIMESTAMPWhen consolidation ran
Performance Impact

Sleep consolidation runs in a background thread and does not block agent operations. On typical hardware, a full cycle processes ~1000 entries in under 5 seconds.