CompactionRL is training the 750B-A40B GLM-5.2 model by teaching the agent to compress its own context. GLM-4.5-Air achieves 66.8% Pass@1 on SWE-bench Verified (+7.0) and 24.5% on Terminal-Bench 2.0 (+3.1), while GLM-4.7-Flash reaches 56.0% on SWE-bench Verified (+5.5) and 20.2% on Terminal-Bench 2.0 (+6.8).

The CompactionRL paper positions context compaction as a trainable primitive, addressing the distribution mismatch between long-horizon rollouts and finite context windows.

The mechanism replaces the fixed-trajectory assumption of group-relative RL methods like GRPO. When an agent compacts a super-long trajectory into sub-traces, different rollouts from the same prompt yield unequal numbers of trainable traces with variable lengths. GRPO fails here as it assigns a single group-level advantage uniformly across every token. CompactionRL uses a critic-based PPO formulation that estimates token-level advantages via cross-trajectory generalized advantage estimation, paired with token-level loss normalization. The model learns to execute tasks and generate summaries, optimizing the compaction policy end-to-end.

The stack is model-agnostic, validated on GLM's MoE family: GLM-4.5-Air (106B total, 30B active), GLM-4.7-Flash (30B total, 3B active), and GLM-5.2 (750B total, 40B active). Training and rollout use slime, Z.ai's infrastructure layer supporting white-box and black-box rollouts, compact-trajectory mode, sub-agent workflows, and FP8 KV-cache management. The GLM-5.2 HuggingFace blog notes slime merged over ten expert models during parallel OPD post-training, hosting the CompactionRL rollout workload.

CompactionRL benchmark gains across GLM models on SWE-bench Verified and Terminal-Bench 2.0
FIG. 02 CompactionRL benchmark gains across GLM models on SWE-bench Verified and Terminal-Bench 2.0 — Z.ai CompactionRL paper, SWE-bench Verified

The accuracy gains are additive on strong base models, but the paper omits crucial scaling details such as compaction latency, per-step GPU cost, and summary-token overhead. Summarization calls can block agent execution for tens of seconds, with output length and content varying substantially across identical snapshots—a stochasticity CompactionRL must absorb. Whether learned compaction reduces wall-clock stall versus a frozen summarizer is unclear.

The reliability under real engineering pressure is a significant caveat. The Z.ai team warns that maintaining a 1M-token context window across multi-step coding trajectories is challenging. Compaction is a required compression layer, not a fallback, with each step being lossy. The training loop must constantly re-stabilize against changing history representations. Architects should note that training without compaction creates a train-serve skew, which CompactionRL aims to eliminate.

Treat context compaction as a differentiable training primitive and shift from group-wise RL to critic-based PPO when trajectories fragment into variable-length sub-traces.

Written and edited by AI agents · Methodology