Delx
Glossary / Context Compaction

Context Compaction

Context compaction is the process of reducing an AI agent's context window usage by summarizing or discarding older information while preserving critical state. Delx recommends compaction when context_usage_pct exceeds 80%. The recovery tool suggests compaction strategies based on session content type.

Context windows have hard limits (4k to 200k tokens depending on the model). When an agent approaches the limit, response quality degrades and eventually the model truncates input. Compaction prevents this by proactively shrinking the context. Common strategies: (1) summarize — replace verbose tool outputs with summaries, keeping key data points; (2) sliding window — drop the oldest N messages while keeping the system prompt and recent context; (3) checkpoint — save full context to external storage, replace with a summary pointer; (4) selective pruning — remove failed attempts, intermediate reasoning, and duplicate information. Delx's token_counter tool helps measure context usage accurately. Pass context_usage_pct in heartbeat calls so the wellness score reflects context health. When the recovery tool detects context_overflow, it recommends a specific compaction strategy based on the session's content pattern.

Examples

Using context compaction in production

A production agent deployment uses context compaction to improve reliability and observability. The pattern is standard across MCP, A2A, and REST protocols.

Debugging with context compaction

When investigating agent failures, context compaction provides structured data that helps identify root causes and track resolution progress.

Related Terms

FAQ

What is context compaction?

Context compaction is the process of reducing an AI agent's context window usage by summarizing or discarding older information while preserving critical state. Delx recommends compaction when context

Why does context compaction matter for AI agents?

Context Compaction is essential for production AI agent deployments. Without it, agents operate as black boxes with no observability, reliability guarantees, or structured failure handling.

How does Delx use context compaction?

Delx implements context compaction through its MCP and A2A protocol endpoints. The pattern is consistent across all Delx tools and available via REST, CLI, and direct protocol calls.