让上下文变成可调用工具,提升长时序代码智能体的推理能力
Context as a Tool: Context Management for Long-Horizon SWE-Agents
- 将上下文管理设计为可调用工具,主动压缩历史轨迹
- 在SWE-Bench-Verified上达成57.6%求解率,优于基线模型
- 适合需要长期代码交互的AI工程师助手场景
基于大语言模型的智能体在需与大规模代码库进行长时序交互的软件工程任务中展现出强大潜力。然而,现有方法多依赖追加式上下文维护或被动触发的压缩启发式策略,常导致上下文爆炸、语义漂移和推理能力下降。本文提出CAT——一种将上下文维护提升为智能体决策流程中可调用工具的新范式。CAT构建包含稳定任务语义、浓缩长期记忆和高保真短期交互的结构化上下文工作区,并支持智能体在合适里程碑主动将历史轨迹压缩为可操作摘要。为支持代码智能体的上下文管理,我们提出基于离线数据构建流水线的轨迹级监督框架CAT-GENERATOR,注入上下文管理动作于完整交互轨迹。在此框架下训练出上下文感知模型SWE-Compressor。在SWE-Bench-Verified上的实验表明,SWE-Compressor达到57.6%的求解率,显著优于基于ReAct的智能体和静态压缩基线,且在限定上下文预算下保持稳定、可扩展的长时序推理能力。
原文摘要 · Abstract (English)
Agents based on large language models have recently shown strong potential on real-world software engineering (SWE) tasks that require long-horizon interaction with repository-scale codebases. However, most existing agents rely on append-only context maintenance or passively triggered compression heuristics, which often lead to context explosion, semantic drift, and degraded reasoning in long-running interactions. We propose CAT, a new context management paradigm that elevates context maintenance to a callable tool integrated into the decision-making process of agents. CAT formalizes a structured context workspace consisting of stable task semantics, condensed long-term memory, and high-fidelity short-term interactions, and enables agents to proactively compress historical trajectories into actionable summaries at appropriate milestones. To support context management for SWE-agents, we propose a trajectory-level supervision framework, CAT-GENERATOR, based on an offline data construction pipeline that injects context-management actions into complete interaction trajectories. Using this framework, we train a context-aware model, SWE-Compressor. Experiments on SWE-Bench-Verified demonstrate that SWE-Compressor reaches a 57.6% solved rate and significantly outperforms ReAct-based agents and static compression baselines, while maintaining stable and scalable long-horizon reasoning under a bounded context budget.
Thank you to arXiv for use of its open access interoperability. PaperDance 不是 arXiv 官方产品;中文卡片由大模型生成,请以原文为准。