Paper: 2607.05378 Authors: Yujiang Li, Zhenyu Hou, Yi Jing, Jie Tang, Yuxiao Dong Categories: cs.LG

The Gap

Reinforcement Learning (RL) from human feedback or outcomes has become a standard tool for honing LLM capabilities, particularly for agentic tasks like coding. Simultaneously, techniques for “context compaction” – summarizing long histories into shorter ones – exist to manage the finite context window of LLMs. However, the world has treated these as two separate problems: first train the agent, then maybe compact its memory after the fact when it gets stuck. This paper addresses the fundamental disconnect: *how can we teach an agent through compaction, rather than treating compaction as a post-hoc repair? Prior work either ignored compaction in RL (leading to context overflow and training failure) or applied it heuristically outside the learning loop (losing valuable learning signal). The paper’s contribution is closing this loop, making compaction an integrated, learnable part of the RL training process itself.

[Problem]
| Finite context window in LLMs limits
| agentic task completion in long horizons.
v
[Assumption] <--> [Limitation]
| RL optimizes actions,       | Existing compaction is
| not summarization.          | separate & heuristic.
v                             v
[Gap]
| No method to jointly learn
| task execution and context
| compression via RL.
v
[Method: CompactionRL]
| Joint RL objective: optimize
| task reward + summary quality.
| Token-loss normalization &
| cross-trajectory GAE.
v
[Evidence]
| Open models gain 3-7 pp on
| SWE-bench & Terminal-Bench.
| Enables training of much larger
| models (GLM-5.2).
v
[Conclusion]
| Context compaction can and should
| be a learnable skill within the
| RL loop, not an afterthought.

The Increment

One sentence: Before this paper, context compaction was a utility tool applied after RL training; after this paper, it is a core, trainable capability within the RL loop itself, enabling the creation of long-horizon agents that learn to manage their own memory.

Core Mechanism

CompactionRL’s innovation lies in its training objective and data flow. The system treats the LLM as a dual-purpose agent: it must both execute actions (e.g., write code, run terminal commands) and generate summaries of its past context when that context grows too large. These two functions are optimized with a single, unified reinforcement learning signal. The key technical contributions enabling this are:

  1. Token-level loss normalization: The reward signal from the task (e.g., “did the code fix the bug?”) is normalized across all tokens, including those in the summary. This prevents the summary generation from dominating the loss just because it uses many tokens.
  2. Cross-trajectory Generalized Advantage Estimation (GAE): The RL advantage estimation, which guides the model toward good actions, is computed not just over the current action trajectory but can leverage information from previous, compacted trajectories. This allows the model to learn from the “lessons” summarized from past experiences.

The data flow is cyclical: The agent acts, its context grows, a summary is triggered, the summary is generated by the same LLM being trained, the context is replaced, and the agent continues learning from the new, compacted state. The RL update considers the entire loop.

[LLM Agent]
| (Initial Context)
v
[Execute Action] --> [Observe Result]
^                         |
|                         v
|              [Context Growing?]
|                   |       |
|                  Yes      No --> [Continue Task]
|                   |
|                   v
|         [Generate Summary]
|         (Learned Skill)
|                   |
|                   v
[Update Context] <---| (Replace history with summary)
^                   |
|                   v
+------[RL Loop: Reward + Cross-Trajectory GAE]------+

Structural Metaphor: Imagine training a junior software engineer. Normally, you’d give them a long notebook of past attempts (the context) and hope they finish the task before the notebook fills up. CompactionRL is like training them with two skills simultaneously: how to code (task execution) and how to write concise, useful commit messages and documentation (summary generation). The key is that their “performance review” (the RL reward) evaluates both the final code and the quality of their documentation. Moreover, they are taught to look back at summaries from their old projects (cross-trajectory) to inform new work. They don’t just learn *to code; they learn to code while managing their own knowledge base.

Key Concepts

  • Joint Optimization: Traditionally, you train a model for Task A (coding) and separately might use a tool for Task B (summarization). Here, the model’s weights are updated to get better at both A and B *simultaneously, using a single feedback signal from the world. It’s like learning to play basketball by shooting hoops, but your coach only scores you on made baskets—except now, the coach also gives you points for a clean, accurate pass that sets up the shot. The pass (summary) becomes directly optimized for the ultimate goal (basket/task success).
  • Token-level Loss Normalization: In a standard RL setup, if your reward is +1 for a correct solution, the model gets that +1 distributed over all the tokens it output. If the summary is very long (say, 1000 tokens) and the final action is short (10 tokens), the summary generation would dominate the learning, as each of its 1000 tokens gets a tiny piece of the reward. This paper scales the reward contribution by token count, ensuring the model pays equal “attention” to learning from the short, crucial final decision and from the long, informational summary.

Framework Shift

Before (mainstream approach):        After (this paper):

[RL Training Loop]                   [RL Training Loop]
     |                                    |
     v                                    v
[Agent Acts]                         [Agent Acts] <------+
[Context Fills]                           |              |
     |                                    v              |
     v                              [Context Fills]?     |
[Fail / Truncate]                         |              |
     |                               Yes--|--No          |
     v                                    v              |
[Manual Heuristic Summary]          [Learned Summary Gen]
(Outside RL)                                |
     |                                    v
     v                              [Compact Context]
[Restart or Give Up]                        |
                                            v
                                   [Continue within same
                                    RL loop, learn from
                                    both execution and
                                    summary via reward]

From treating compaction as an external tool to making it an internal, optimized skill, the core shift is that the agent’s memory management is no longer a liability but a trainable asset.

Expert Assessment

Problem choice: Strong. The context window is a fundamental, practical bottleneck for deploying LLM agents on real, long-horizon tasks. Connecting it to the RL training loop is a logical and timely leap. It sits at the intersection of two hot areas (agentic RL and long-context efficiency) and addresses a real pain point, not a theoretical curiosity.

Method maturity: Clever with some complexity. The joint optimization insight is elegant. The cross-trajectory GAE is a smart way to reuse information, but it adds significant conceptual and implementation complexity. One wonders if a simpler approach—like only summarizing at the very end of a failed trajectory and feeding that summary into the next attempt’s initial prompt—would capture 80% of the gain. The authors don’t deeply explore such simpler baselines, which is a minor weakness.

Experimental integrity: Good, but with caveats. The gains (3-7 points) are solid and consistent across models and two challenging benchmarks. Training on top of open models (GLM-4.5/4.7) is a fair test. However, the absolute numbers (66.8% on SWE-bench Verified) are still far behind state-of-the-art proprietary models, suggesting this technique is more about enabling capability (making long tasks trainable at all) than achieving top-tier performance. The comparison is primarily with the untuned base model, which is the correct comparison for measuring the *increment, but the reader should not misconstrue the results as placing these models at the frontier.

Writing quality: Functional but could be sharper. The motivation and high-level idea are clearly presented. The “Core Mechanism” section, however, dives into technical details (token normalization, GAE) without always first grounding them in the intuitive “why.” The structural metaphor above is absent from the paper; adding a page of such intuition would greatly improve accessibility for the broader ML audience.

Verdict: Weak accept — A clear, valuable contribution that solves a real problem with a non-trivial method. It opens a well-defined research direction (learned context management in RL) even if the specific technique may be iterated upon.

Takeaways

  1. Treat Context as a Learnable Resource, Not Just a Fixed Budget: The most transferable idea is to frame information compression itself as a policy to be optimized within any learning system that operates over long sequences. This applies to RL agents, but also to any recurrent model or even dialogue systems.
  2. The “Summary-as-Skill” Paradigm: If you’re building a system that must retain information over long interactions, consider making the summarization component a first-class citizen in your training objective, not a post-processing step. Train it with the same end-goal signal as the primary task.
  3. Cross-Trajectory Generalization is Powerful: The paper shows that summaries from past episodes can inform and accelerate learning in new ones. Practically, this means persisting and reusing distilled knowledge from past experiences can make your training more sample-efficient, even if the tasks are slightly different.

论文: 2607.05378 作者: Yujiang Li, Zhenyu Hou, Yi Jing, Jie Tang, Yuxiao Dong 分类: cs.LG

缺口

基于强化学习(RL)来磨练大语言模型(LLM)的能力,尤其是在编码等智能体任务上,已成为标准方法。 与此同时,用于管理LLM有限上下文窗口的“上下文压缩”技术——即将长历史总结为短文本——也早已存在。 然而,学界一直将这两者视为两个独立的问题:先训练智能体,等到任务因上下文爆满而失败时,再用启发式方法进行压缩。 这篇论文要解决的,正是这个根本性的脱节:如何在压缩中学习,而不是将压缩视为事后补救? 此前的工作要么在RL中忽略压缩(导致上下文溢出和训练失败),要么在学习循环外进行启发式压缩(丢失了宝贵的优化信号)。 本文的核心贡献,就是闭合了这个循环,让压缩本身成为RL训练过程中一个可集成、可学习的组成部分。

[问题]
| LLM有限上下文窗口制约了
| 智能体在长时域任务中的完成。
v
[假设] <--> [局限]
| RL优化行动,          | 现有压缩方法是
| 而非总结。            | 分离且启发式的。
v                     v
[缺口]
| 缺乏通过RL联合学习
| 任务执行与上下文压缩
| 的方法。
v
[方法: CompactionRL]
| 联合RL目标:同时优化
| 任务奖励与摘要质量。
| 采用令牌级损失归一化
| 与跨轨迹GAE。
v
[证据]
| 开源模型在SWE-bench
| 和Terminal-Bench上提升
| 3-7个百分点。并实现了
| 更大模型(GLM-5.2)的训练。
v
[结论]
| 上下文压缩可以、也应该
| 成为RL循环内可学习的技能,
| 而非事后补救措施。

增量

一句话: 在此论文之前,上下文压缩是RL训练结束后使用的工具性手段;在此论文之后,它变成了RL循环内部的核心、可训练能力,从而催生出能够学习管理自身记忆的长时域智能体。

核心机制

CompactionRL的创新在于其训练目标和数据流。 该系统将LLM视为一个双重目标的智能体:它既必须执行动作(如编写代码、运行终端命令),又必须在上下文过长时生成摘要。 这两个功能通过统一的强化学习信号进行优化。 使其成为可能的关键技术贡献包括:

  1. 令牌级损失归一化:来自任务(如“代码是否修复了错误?”)的奖励信号会在所有令牌上进行归一化,包括摘要中的令牌。这防止了摘要生成仅仅因为使用了大量令牌而在损失中占据主导。
  2. 跨轨迹广义优势估计(GAE):用于指导模型走向好动作的优势估计,不仅基于当前的动作轨迹计算,还可以利用之前已压缩轨迹的信息。这使得模型能够从过往经验所“总结”出的教训中学习。

数据流是循环的:智能体执行动作,其上下文增长,触发摘要生成,摘要由同一个正在训练的LLM生成,上下文被替换,智能体从新的、压缩后的状态继续学习。RL更新考虑整个循环。

[LLM 智能体]
| (初始上下文)
v
[执行动作] --> [观察结果]
^                   |
|                   v
|           [上下文过长?]
|                |       |
|               是       否 --> [继续任务]
|                |
|                v
|        [生成摘要]
|        (习得的技能)
|                |
|                v
[更新上下文] <---| (用摘要替换历史)
^                |
|                v
+-----[RL循环:奖励 + 跨轨迹GAE]-----+

结构性比喻:想象在训练一名初级软件工程师。通常,你会给他一本记录过往尝试的长笔记本(上下文),并指望他在笔记本写满前完成任务。 CompactionRL就像是在同时训练他两项技能:如何写代码(任务执行)如何撰写简洁、有用的提交信息和文档(摘要生成)。 关键是,他的“绩效评估”(RL奖励)不仅评估最终的代码,还评估文档的质量。 此外,他还被教导回顾过去项目的摘要(跨轨迹),以指导新工作。 他不仅仅是学习写代码;他是在学习一边写代码,一边管理自己的知识库

关键概念

  • 联合优化: 传统方法是为任务A(编码)训练一个模型,任务B(摘要)可能单独使用一个工具。在这里,模型的权重被更新,以同时改进A和B,使用的是来自世界的单一反馈信号。这就像通过投篮来学习打篮球,但你的教练只根据进球得分——然而现在,教练还会为你一次干净、精准的、为进球创造机会的传球(摘要)加分。传球(摘要)直接为最终目标(进球/任务成功)而优化。
  • 令牌级损失归一化: 在标准RL设置中,如果你的正确解法奖励是+1,模型会将这+1分配给其输出的所有令牌上。如果摘要非常长(比如1000个令牌)而最终动作很短(10个令牌),摘要生成将主导学习,因为它的1000个令牌中的每一个都会分到一小部分奖励。本文根据令牌数缩放奖励贡献,确保模型从短暂、关键的最终决策中学习,与从冗长、信息丰富的摘要中学习,能获得同等的“关注”。

框架转变

之前(主流方法):                之后(本文方法):

[RL 训练循环]                   [RL 训练循环]
     |                              |
     v                              v
[智能体行动]                    [智能体行动] <------+
[上下文填满]                       |               |
     |                             v               |
     v                       [上下文过长]?         |
[失败/截断]                       |               |
     |                     是-----|--否           |
     v                             v               |
[手动启发式摘要]             [学习生成摘要]
(RL循环之外)                       |
     |                             v
     v                       [压缩上下文]
[重启或放弃]                        |
                                    v
                           [在同一RL循环内继续,
                            从执行与摘要中共同学习]

将压缩视为外部工具使其成为内部的、被优化的技能,核心转变是:智能体的记忆管理不再是负债,而是一项可训练的资产。

专家评审

选题眼光: 。上下文窗口是部署LLM智能体处理真实长时域任务时一个根本性的、实际的瓶颈。将其与RL训练循环联系起来,是一个合乎逻辑且及时的飞跃。它位于两个热门领域(智能体RL和长上下文效率)的交汇处,解决的是一个真实的痛点,而非理论好奇心。

方法成熟度: 巧劲与复杂并存。联合优化的洞见很优雅。跨轨迹GAE是一种聪明的、复用信息的方式,但它增加了显著的概念和实现复杂度。人们会想,是否有一种更简单的方法——比如仅在轨迹完全失败时才进行摘要,并将该摘要作为下一次尝试的初始提示——也能获得80%的收益。作者没有深入探讨这类更简单的基线,这是一个小缺点。

实验诚意: 良好,但需注意。3-7个百分点的提升是扎实的,并且在不同模型和两个具有挑战性的基准上具有一致性。在开源模型(GLM-4.5/4.7)基础上进行训练是公平的测试。然而,绝对分数(SWE-bench Verified上的66.8%)仍远低于最先进的专有模型,这表明该技术更多在于使能能力(让长任务可训练),而非达到顶级性能。主要比较对象是未调优的基础模型,这是衡量增量的正确比较,但读者不应误解结果,认为这些模型已处于前沿。

写作功力: 功能性强,但可以更精炼。动机和高级理念阐述清晰。然而,“核心机制”部分有时会直接深入技术细节(令牌归一化、GAE),而未先将其根植于直觉的“为什么”中。上述的结构性比喻在论文中缺失;增加一页这样的直觉解释,将极大地提高对更广泛ML读者群的可理解性。

判决: 弱接收 — 一个清晰、有价值的贡献,用非平凡的方法解决了一个真实的问题。它开启了一个明确的研究方向(RL中的可学习上下文管理),即使该具体技术可能在未来被迭代改进。

要点总结

  1. 将上下文视为可学习资源,而非固定预算: 最可迁移的思想是将信息压缩本身视为一个策略,在任何处理长序列的学习系统中进行优化。这不仅适用于RL智能体,也适用于任何循环模型,甚至对话系统。
  2. “摘要即技能”范式: 如果你正在构建一个必须在长时间交互中保留信息的系统,请考虑将摘要组件作为训练目标中的“头等公民”,而非后处理步骤。用与主任务相同的最终目标信号来训练它。
  3. 跨轨迹泛化威力强大: 本文表明,过往情节的摘要可以为新情节的学习提供信息并加速学习。在实践中,这意味着持久化并复用从过往经验中提炼的知识,可以提高你的训练样本效率,即使任务略有不同。