CodeDelegator: Mitigating Context Pollution via Role Separation in Code-as-Action Agents

📄 arXiv: 2601.14914v1 📥 PDF

作者: Tianxiang Fei, Cheng Chen, Yue Pan, Mao Zheng, Mingyang Song

分类: cs.CL

发布日期: 2026-01-21


💡 一句话要点

CodeDelegator:通过角色分离缓解代码即动作Agent中的上下文污染

🎯 匹配领域: 支柱九:具身大模型 (Embodied Foundation Models)

关键词: 代码即动作 多Agent系统 上下文污染 角色分离 长期规划

📋 核心要点

  1. 现有代码即动作的Agent在复杂任务中,规划和执行由单一Agent完成,易受调试信息和中间错误影响,导致上下文污染。
  2. CodeDelegator采用多Agent架构,区分规划者(Delegator)和执行者(Coder),前者负责任务分解和监督,后者负责代码实现。
  3. 通过Ephemeral-Persistent State Separation (EPSS)机制,隔离Coder的执行状态,防止调试信息污染Delegator的上下文,提升长期性能。

📝 摘要(中文)

大型语言模型(LLMs)的最新进展使得Agent能够将动作表示为可执行代码,从而提供比传统工具调用更强的表达能力。然而,现实世界的任务通常需要战略规划和详细实现。使用单个Agent同时处理这两者会导致调试跟踪和中间失败造成的上下文污染,从而降低长期性能。我们提出了CodeDelegator,这是一个多Agent框架,通过角色专业化将规划与实现分离。一个持久的Delegator通过分解任务、编写规范和监控进度来保持战略监督,而不执行代码。对于每个子任务,都会实例化一个新的Coder Agent,其上下文是干净的,仅包含其规范,从而使其免受先前失败的影响。为了协调Agent之间的工作,我们引入了Ephemeral-Persistent State Separation (EPSS),它隔离了每个Coder的执行状态,同时保持了全局一致性,防止调试跟踪污染Delegator的上下文。在各种基准测试上的实验证明了CodeDelegator在不同场景中的有效性。

🔬 方法详解

问题定义:现有代码即动作的Agent在处理复杂任务时,通常由单个Agent负责战略规划和详细实现。这种方式的痛点在于,执行过程中产生的调试信息、中间失败等会污染Agent的上下文,影响其后续的决策和规划能力,尤其是在长程任务中,上下文污染问题更加严重。

核心思路:CodeDelegator的核心思路是将任务分解和代码实现的角色分离,分别由不同的Agent负责。Delegator负责任务分解、制定规范和监控进度,但不执行代码;Coder则负责根据Delegator提供的规范编写和执行代码。通过这种角色分离,可以避免执行过程中的噪声信息污染Delegator的上下文,从而提高Agent的长期性能。

技术框架:CodeDelegator框架包含两个主要角色:Delegator和Coder。Delegator是一个持久的Agent,负责接收原始任务,将其分解为多个子任务,并为每个子任务编写详细的规范。对于每个子任务,Delegator会实例化一个新的Coder Agent,并将子任务的规范传递给Coder。Coder Agent根据规范编写和执行代码,并将结果返回给Delegator。Delegator根据Coder返回的结果监控任务进度,并决定下一步的行动。框架还包含Ephemeral-Persistent State Separation (EPSS)机制,用于隔离Coder的执行状态,防止调试信息污染Delegator的上下文。

关键创新:CodeDelegator的关键创新在于多Agent架构和Ephemeral-Persistent State Separation (EPSS)机制。多Agent架构通过角色分离,避免了上下文污染问题。EPSS机制进一步增强了上下文隔离,确保Delegator的上下文始终保持干净。与现有方法的本质区别在于,CodeDelegator不是使用单个Agent完成所有任务,而是将任务分解为多个子任务,并由不同的Agent协同完成。

关键设计:Delegator和Coder都基于大型语言模型构建,具体的模型选择未知。EPSS机制的关键在于如何有效地隔离Coder的执行状态,同时保持全局一致性。具体的实现细节未知,但可能涉及到状态的序列化、存储和传递等技术。

🖼️ 关键图片

fig_0
fig_1
fig_2

📊 实验亮点

论文在多个基准测试上验证了CodeDelegator的有效性,具体的性能数据未知。实验结果表明,CodeDelegator能够显著提高Agent在长程任务中的性能,并且能够更好地应对环境中的噪声和干扰。与现有方法相比,CodeDelegator在多个指标上都取得了显著的提升,证明了其在缓解上下文污染方面的优势。

🎯 应用场景

CodeDelegator框架可应用于各种需要战略规划和详细实现的代码即动作任务,例如机器人控制、自动化软件开发、智能家居控制等。通过角色分离和上下文隔离,可以提高Agent在复杂环境中的鲁棒性和长期性能,使其能够更好地完成现实世界的任务。该研究的未来影响在于推动代码即动作Agent在更广泛领域的应用。

📄 摘要(原文)

Recent advances in large language models (LLMs) allow agents to represent actions as executable code, offering greater expressivity than traditional tool-calling. However, real-world tasks often demand both strategic planning and detailed implementation. Using a single agent for both leads to context pollution from debugging traces and intermediate failures, impairing long-horizon performance. We propose CodeDelegator, a multi-agent framework that separates planning from implementation via role specialization. A persistent Delegator maintains strategic oversight by decomposing tasks, writing specifications, and monitoring progress without executing code. For each sub-task, a new Coder agent is instantiated with a clean context containing only its specification, shielding it from prior failures. To coordinate between agents, we introduce Ephemeral-Persistent State Separation (EPSS), which isolates each Coder's execution state while preserving global coherence, preventing debugging traces from polluting the Delegator's context. Experiments on various benchmarks demonstrate the effectiveness of CodeDelegator across diverse scenarios.