When the window runs out,
the summary is the agent.
First surfaced in Tandemly Briefing — 2026-07-24.
Long-horizon agents eventually fill their context window. Most systems handle this with a static summarizer bolted on at inference time. Researchers at Tsinghua University trained the summarization step into the RL policy itself, so agents learn to compress what they actually need to finish the task, not what sounds informative in the abstract.
Context windows fill.
The task does not stop.
Every long-horizon agent eventually hits the same wall: the context limit. What a system does at that wall determines whether the task survives it.
A software engineering agent working through a complex codebase, or a terminal agent navigating a multi-step debugging session, accumulates a lot of history. Tool outputs, intermediate reasoning, observations from earlier steps, all of it piles up. At some point the context window is full.
The naive solution is truncation: drop the oldest content and keep going. That works until the truncated content turns out to matter. For tasks that span dozens of steps, the content that gets truncated is often the content that contains the key constraint, the relevant file path, or the error message the current step is supposed to address.
A more sophisticated approach is a static summarizer: a separate model trained on summarization data that condenses the context at intervals. This is better than truncation, but it optimizes for something adjacent to the goal. A summarizer trained on human summarization data learns to preserve what a human reading the history would find interesting. That is not the same as preserving what the agent needs to complete the task it is on.
The gap between a good summary and a task-preserving summary is what CompactionRL is built to close.
What if context compaction were not an inference-time heuristic applied to the agent, but a behavior trained into the agent alongside the task it is trying to complete? Would the summaries be better? Would the task completion rate improve?
Joint training:
task and summary together.
CompactionRL reframes context compaction as a component of the agent's learned policy, trained jointly with task execution rather than added as a separate post-hoc module.
The key insight is that whether a summary is good depends entirely on what the agent needs to do next. A summary that looks comprehensive to a human reviewer might omit the precise detail the agent requires at step 47. The only way to know what matters is to train the summarization step against the outcomes the agent is trying to achieve.
CompactionRL introduces two mechanisms to make this training work:
During RL training, two loss signals compete: one for task-execution actions and one for summary-generation tokens. Without explicit balancing, the task-execution signal typically dominates because there are far more task steps than compaction events. Token-level loss normalization reweights both signals so neither crowds out the other. The summary generator learns from outcomes, not just from the structure of good summaries.
Standard Generalized Advantage Estimation (GAE, the technique RL systems use to compute how much credit an action deserves for later outcomes) stops at context boundaries. This means actions taken before a compaction event cannot receive credit for what happens after the summary is generated. Cross-trajectory GAE extends advantage estimation across those boundaries. An action at step 12 that turned out to matter for the outcome at step 60, even though a summary happened at step 30, now gets credit for that outcome.
The evaluation holds the peak context window size constant. CompactionRL does not improve outcomes by giving the agent more room to work. It improves outcomes by using the existing room more effectively. This is a meaningful constraint: the benchmark is efficiency, not scale.
Seven points on
a fixed budget.
CompactionRL was evaluated on GLM-4.5-Air across two standard long-horizon benchmarks. Both showed meaningful gains over the baseline, and ablations confirm the summary training step's contribution is real.
Removing token-level loss normalization degrades summary quality. Removing cross-trajectory GAE reduces the agent's ability to preserve information that matters for distant future steps. Both mechanisms contribute independently. The combined system outperforms each component in isolation.
The ablation finding matters because it rules out the simpler hypothesis that any summarization during training is sufficient. The specific design choices drive the gains.
Results are on one base model (GLM-4.5-Air) and two benchmarks. Whether the gains transfer to other model families, other task domains, or shorter-horizon tasks is not established by this paper. Benchmarks with very short average episode lengths may not see the same benefit, since context pressure is the prerequisite for compaction to matter.
What this means
for agent builders.
CompactionRL is primarily a training-time result, which means the practitioners it matters to most are teams building and fine-tuning long-horizon agents, not teams deploying off-the-shelf models. But the evaluation framing carries lessons that apply more broadly.
Where to go
from here.
If you want to go deeper on context compaction, cross-boundary credit assignment, or long-horizon agent evaluation.