Table of Contents
Fetching ...

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

Tianxiang Fei, Cheng Chen, Yue Pan, Mao Zheng, Mingyang Song

TL;DR

Context pollution from debugging traces limits long-horizon code-as-action agents. CodeDelegator mitigates this by separating planning (Delegator) from execution (Coders) and enforcing Ephemeral-Persistent State Separation (EPSS) with typed, schema-driven communication. Empirical results on $ au^2$-bench and MCPMark show substantial gains over ReAct and CodeAct, especially on complex tasks, with ablations confirming the value of both role separation and EPSS. This framework offers a scalable blueprint for robust, multi-agent collaboration in dynamic environments while maintaining planning efficiency and execution isolation.

Abstract

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.

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

TL;DR

Context pollution from debugging traces limits long-horizon code-as-action agents. CodeDelegator mitigates this by separating planning (Delegator) from execution (Coders) and enforcing Ephemeral-Persistent State Separation (EPSS) with typed, schema-driven communication. Empirical results on -bench and MCPMark show substantial gains over ReAct and CodeAct, especially on complex tasks, with ablations confirming the value of both role separation and EPSS. This framework offers a scalable blueprint for robust, multi-agent collaboration in dynamic environments while maintaining planning efficiency and execution isolation.

Abstract

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.
Paper Structure (43 sections, 6 figures, 6 tables, 1 algorithm)

This paper contains 43 sections, 6 figures, 6 tables, 1 algorithm.

Figures (6)

  • Figure 1: Comparison of action representations: ReAct uses structured text/JSON, while CodeAct uses executable Python code, enabling more complex logic within a single action
  • Figure 2: CodeDelegator in action: The persistent Delegator orchestrates a pricing analysis task by delegating sub-tasks to ephemeral Coders. Coder #1 (Data Collection) has completed and been discarded; Coder #2 (Data Cleaning) is actively debugging in an isolated context. Each Coder's execution traces (errors, retries) remain confined and never propagate to the Delegator's planning context, preventing context pollution.
  • Figure 3: Illustrative examples of agent trajectories and failure modes observed in the pilot study.
  • Figure 4: Overview of the CodeDelegator framework with two core mechanisms. Role Separation (top): A persistent Delegator decomposes tasks and performs adaptive control, while ephemeral Coders execute sub-tasks through interactive refinement with fresh contexts. EPSS (bottom): The dual-layer workspace architecture isolates execution traces in per-Coder sandboxes (Execution Layer) while maintaining global coherence in a persistent Orchestration Layer, enabling four key properties: orchestration without accumulation, fresh context per Coder, dual-layer isolation, and schema-driven communication.
  • Figure 5: $pass \textasciicircum 1$ accuracy by task complexity.
  • ...and 1 more figures