自压实语言模型智能体
Self-Compacting Language Model Agents
摘要
由思维链和工具调用构成的长期代理痕迹会积累大量无效内容,这些内容会束缚后续生成过程,最终超出上下文窗口的容量。现有的辅助机制通过以特定token数量为触发点来压缩信息来缓解这一问题。但这种机制并不考虑信息的演化路径,可能导致在推理或搜索过程中部分结果被忽略。我们提出了SelfCompact这一辅助机制,让模型本身能够决定何时以及以何种方式进行压缩。具体来说,它包含两个关键元素:(i) 一个用于总结累积上下文的压缩工具;(ii) 一个轻量级的判断标准,用于确定何时进行压缩——比如某个子任务已解决或信息演化路径趋于稳定时,或者何时停止压缩——比如在推理过程中或遇到障碍时。这两个要素都是必要的。单独使用压缩工具会导致不同模型的使用效果差异较大,往往会在无助于解决问题的时刻被使用,而单独使用判断标准则无法发挥作用。两者结合使用时,可以实现有效的自适应压缩,无需任何微调或外部监督。我们在六个基准测试项目上获得了实证结果,包括竞赛数学和代理式搜索领域。结果显示,SelfCompact在成本方面仅需要固定间隔压缩的极小比例,就能达到与固定间隔压缩相当甚至更好的效果。在竞赛数学领域,其性能提升了18.1分;在代理式搜索领域,其性能提升了5-9分,且每题成本降低了30-70%。我们的研究揭示了某种元认知上的差距:虽然无提示的模型无法可靠判断自己的上下文是否变得无效,但轻量级的判断标准可以弥补这一缺陷,将压缩决策转化为一种可以被辅助机制无需训练即可提供的功能。
English Abstract
Long agent traces composed of chains of thought and tool calls accumulate stale content that anchor subsequent generations, and eventually outgrow the context window. Existing scaffolds mitigate it with fixed-interval compaction triggered at a token threshold. Such triggers pay no heed to trajectory structure, risking discard of partial results mid-derivation or mid-search. We propose SelfCompact, a scaffold that allows the model itself to decide when and how to compact. Specifically, it pairs two inference-time elements: (i) a compaction tool the model invokes to summarize the accumulated context, and (ii) a lightweight rubric specifying when to fire (a sub-task has resolved, or the trajectory is converging) and when to suppress (mid-derivation, or when stuck). Both are needed. The tool alone is unevenly used across open-weight models, often invoked at unhelpful moments or not at all; the rubric alone cannot act. Together, they elicit effective adaptive compaction without any fine-tuning or external supervision. We present empirical results on six benchmarks (competitive math and agentic search) and seven models. Our results show that SelfCompact matches or exceeds fixed-interval summarization at a fraction of the token cost, improving over a no-summarization baseline by up to 18.1 points on math and 5-9 points on agentic search at 30-70% lower per-question cost. Our results expose a meta-cognitive gap: although unprompted models cannot reliably tell when their own context is rotting, a lightweight rubric closes this gap, reframing when to compact as a capability that scaffolds can supply without training.