CORE GUIDE

MENTAL_MODELINTERMEDIATE7 min read

Context compaction

Context compaction preserves the smallest task-relevant state needed for future decisions instead of repeatedly carrying the full interaction history forward.

Mental model

Compaction is lossy state transformation with an explicit preservation contract. The goal is not 'make text shorter'; it is retain decisions, constraints, unresolved questions and evidence references while discarding detail that no longer changes future behavior.

Why it matters

Long conversations and agent runs eventually exceed practical context budgets. Blind truncation loses important constraints, while generic summarization can collapse identifiers, uncertainty or pending work. A reliable compaction step defines what must survive and tests whether the compacted state still supports the next decisions.

01

Compact against future decision requirements

Identify durable facts, active goals, constraints, completed actions, unresolved branches and evidence pointers. Transform history into a structured compact state, then validate required fields and references before replacing raw history in the active context. Keep original traces separately for audit and debugging instead of treating the compacted form as lossless history.

02

Example: compact a twenty-step support incident

After many tool calls, the active context no longer needs every intermediate log line. It does need the customer ID, controlling policy version, refund operation IDs, verified current status, failed hypotheses and pending approval. The runtime compacts those fields into a structured state while retaining the full trace outside the prompt.

Common failure modes

  • Summarizing for readability without defining which state must survive.
  • Deleting raw traces after compaction and losing audit evidence.
  • Compacting too early and repeatedly accumulating summary-of-summary distortion.

Engineering heuristics

  • Define a preservation schema before choosing a summarizer.
  • Keep durable evidence references and identifiers verbatim where possible.
  • Evaluate compaction by downstream task success, not compression ratio alone.

Takeaways

  1. 01Compaction is state preservation under a smaller budget.
  2. 02Loss must be intentional and testable.
  3. 03Raw trace and active compact context serve different purposes.

Reading evidence

UnseenPractice not completed

This records actions you actually took; it does not claim mastery, proficiency, or certification.

Used in

This Concept is reused across these canonical learning paths.

Related concepts from the Knowledge Graph

These relationships come from the canonical graph, not a separate Guide taxonomy.