section

Compaction Process

On-Demand Compaction

Unlike Beads' nightly cron, Recall compaction is ON-DEMAND.

When to Compact

  1. Before ops handoff - ensure clean context for new ops
  2. Before spawning agents - give them focused context
  3. After long sessions - prevent memory bloat
  4. On explicit request - recall.compact(force=True)

Compaction Flow

  1. Query Session for AI state older than threshold (default 7 days)
  2. Group related items (same project, same session)
  3. Call Haiku API: 'Summarize this in 3-5 sentences'
  4. Store compacted summary in Recall archive
  5. Mark originals as compacted (don't delete)

API Call (Haiku)

response = anthropic.messages.create(
    model='claude-3-5-haiku-20241022',
    max_tokens=500,
    messages=[{
        'role': 'user',
        'content': f'Summarize this AI working context in 3-5 sentences:\n{content}'
    }]
)

Cost Estimate

  • Haiku: ~$0.25/M input tokens, ~$1.25/M output tokens
  • Typical session: ~2000 tokens input, ~200 tokens output
  • Cost per compaction: < $0.001
ID: 09011b44
Path: Nexus Recall System > Compaction Process
Updated: 2026-01-05T10:39:28