arXiv:2601.14914cs.CL2026-01被引 2

用角色分离解决代码代理中的上下文污染问题

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

  • 拆分规划与实现角色,避免调试信息干扰
  • 新任务分配新代理,保持上下文干净
  • 适合长周期复杂代码任务的自动化系统

大型语言模型使智能体可通过可执行代码表达动作,比传统工具调用更具表现力。但真实任务既需策略规划又需细节实现,单一代理同时承担会因调试痕迹和中间失败导致上下文污染,影响长期性能。本文提出 CodeDelegator 多代理框架,通过角色专业化分离规划与实现:持久化的 Delegator 负责任务分解、编写规范并监控进度,不执行代码;每个子任务由新实例化的 Coder 代理处理,上下文仅包含其规范,避免历史失败影响。通过引入临时-持久状态分离(EPSS),隔离各 Coder 执行状态,同时保持全局一致性,防止调试信息污染 Delegator 上下文。在多个基准上的实验验证了该方法在多样化场景下的有效性。

原文摘要 · Abstract (English)

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.

代码生成多智能体上下文污染

Thank you to arXiv for use of its open access interoperability. PaperDance 不是 arXiv 官方产品;中文卡片由大模型生成,请以原文为准。