In long tasks, context is the bottleneck
When an auto research loop runs for many hours across sessions, the context window hits its limit first. Leaving old conversation as-is overflows the window; cutting it blindly breaks task coherence. Context compaction summarizes older portions and replaces them with a compressed state while preserving task continuity.
The key insight is that compaction is a decision problem, not a mere threshold problem. When you compact determines quality.
Reactive, proactive, and decision-based
Reactive strategies respond after a problem occurs, such as a sliding window that drops the oldest messages on overflow or on-demand summarization. Proactive strategies prepare summaries in the background so that when a threshold is reached, a pre-computed summary is used immediately without pausing. Recently, decision-based compaction, where the model itself decides when and how to compact, matched or beat threshold approaches at a fraction of the token cost.
Full guide: from planning to operations
In planning, define compaction goals as numbers. For example, set task-continuity retention after compaction, zero interruptions from context overflow, and a compaction token-cost ceiling. Decision-based compaction pairs the compaction tool with firing rules: compact when a sub-task is resolved or the trajectory is converging, and hold mid-derivation or when stuck. Judging timing this way reduces the mistake of cutting away important context.
A common failure pattern is losing decisive information in the summary. If a summary keeps only conclusions and discards rationale or open items, later steps repeat the same mistakes. To prevent this, use hierarchical summarization to keep the original, mid-level summary, and top summary together, and exclude open tasks and decision rationale from compaction. For recovery, if work after compaction contradicts or repeats a prior decision, trace back from the top summary to the original to restore it. Store short-term memory as raw events synchronously and build long-term memory asynchronously in the background so it does not block the conversation.
On the operations checklist, keep a compaction history. Record what was compacted when and why, and which items were preserved, in standard fields. As observability fields, use compaction frequency, post-compaction continuity failure rate, summary-to-original token ratio, and re-expansion (original restore) count. Keep masking rules so summaries and originals contain no personal data.
The continuous improvement loop analyzes cases where quality dropped after compaction weekly. Add frequently lost information types to preservation rules and reflect inappropriate compaction timing into firing rules. A compaction strategy should be a decision rule that keeps adjusting to absorb real failures, not a fixed threshold.
Key takeaways
In short, the bottleneck for long-running agents is context, and compaction is a decision, not a threshold. Go beyond reactive and proactive to judge firing timing by decision, preserve rationale and open tasks with hierarchical summarization, and separate STM and LTM. Observe post-compaction continuity failure and keep refining preservation rules to maintain coherence in long tasks.