Skip to main content

Memory Consolidation

Overview

The Memory Consolidator is a scheduled Cloudflare Worker that aggregates approved triage items into consolidated memories. It bridges the gap between individual triage candidates and durable organizational knowledge. File: services/knowledge/src/memory-consolidator.ts

Schedules

Hourly Consolidation

  1. Fetch approved triage items from last hour
  2. Group by category/topic
  3. Generate topic summary using Think service (Workers AI fallback)
  4. Write consolidated_memories with type topic
Minimum threshold: 2+ sessions per topic.

Daily Consolidation

  1. Fetch approved triage items from last 24 hours
  2. User-level: Group by user, generate user summaries
  3. Account-level: Group by account, generate account summaries
  4. Send health signals for at-risk accounts
  5. Cleanup memories beyond retention period
Minimum threshold: 2+ sessions per user/account.

Weekly Consolidation

  1. Fetch consolidated memories from past week (topic + user + account types)
  2. Extract cross-cutting patterns using Think service
  3. Identify best practices
  4. Write pattern-type consolidated memory
  5. Update knowledge base with extracted patterns
Minimum threshold: 5+ consolidated memories.

Data Flow

Lock Mechanism

The Consolidator uses a Durable Object lock to prevent duplicate processing:
  • acquire-lock with TTL (3600 seconds)
  • Release after processing completes
  • If lock not acquired, skip this cycle

Fallback Behavior

If the Think service is unavailable, the Consolidator uses a fallback summary:

Retention

Old consolidated memories are cleaned up based on MEMORY_RETENTION_DAYS configuration. Default cleanup runs during daily consolidation.