Code as Orchestration: Self-Evolving Multi-Agent Collaboration through Executable Scripts

Xuanwei Hu, Ziyin Qiu, Hanjun Wang, Rui Wang, Yiran Zhao, Jing Kong, Yanchen Deng, Bo AnarXiv 2026

TL;DR

Coordinating multiple AI agents on complex tasks usually forces a trade-off: rigid, predefined workflows are easy to inspect but brittle, while letting an LLM improvise at runtime is flexible but opaque. COS (Code as Orchestration System) bridges this gap by expressing each task's multi-agent coordination as an explicit, executable script. When a script's output isn't supported by the evidence, COS diagnoses the failure from execution traces, rewrites the orchestration script from scratch, and carries over verified findings in a persistent fact store—achieving state-of-the-art results on deep research and open-ended scientific reasoning without updating model weights or needing ground-truth answers.

What Problem Does This Paper Address?

Multi-agent systems can tackle massive problems—from deep web research to scientific discovery—by dividing labor among specialized agents. The catch is orchestration: deciding which agent runs when, how they pass information, and how to recover when a search hits a dead end.

Existing approaches struggle with this in two ways:

  1. Predefined workflows (e.g., MetaGPT, Dify) hardcode stages and routing rules. They are predictable and easy to audit, but they can't adapt when a research task unexpectedly turns from parallel searching into sequential fact-checking.
  2. Runtime LLM delegation lets a lead agent decide what to do on the fly. While flexible, it makes the overall control flow impossible to inspect in advance and prone to silent deviations (such as an agent fabricating data instead of calling a required tool).

Recent code-based orchestration methods either don't adapt within a single ongoing task, or they rely on validation sets and ground-truth answers to evolve. COS tackles intra-task self-evolution: adapting the orchestration code mid-task using only execution feedback.

Methods

COS separates what the system knows from how it coordinates, operating in an iterative loop (up to $N_{\max} = 3$ rounds) across three components:

Figure 1. COS framework. The Planner generates a plan, and the Orchestrator translates it into a validated orchestration script. The PlanReviewer and the CodeReviewer check the plan and the script, respectively. Agent execution maintains shared facts and traces. The EvoReflector assesses task completion and diagnoses failures when further orchestration is needed. The EvoReflector determines whether to approve the round through completion assessment.
  1. Code-Based Multi-Agent Orchestration: A Planner drafts a natural-language plan, which is vetted by a PlanReviewer. An Orchestrator then translates the approved plan into an executable script specifying agent calls, conditionals, bounded loops, and parallel execution. Before running, the script passes through AST static analysis, a simulated preflight run, and a CodeReviewer.
  2. Execution & Shared Memory: A ScriptRuntime executes the script. Crucially, findings are not trapped inside the script's local variables. Workers submit claims and evidence to a persistent FactStore, where an EvidenceAgent reviews submissions, resolves duplicates, and flags conflicts. Meanwhile, TraceStore and FactFlow log execution histories and data dependencies.
  3. Intra-Task Self-Evolution: After each round, an EvoReflector checks whether the candidate answer is actually supported by the frozen FactStore. If requirements remain unmet, it diagnoses the gap using the execution traces and writes a Failure Report. COS then regenerates a brand-new orchestration script for the next round—restructuring agent assignments and dependencies without inheriting the previous script's structure, while reusing all verified facts already in FactStore.

Datasets

The authors evaluate COS and all baselines using DeepSeek-V4.1-Flash as the shared backbone model across four existing benchmarks (no new benchmarks are introduced):

  • BrowseComp: Evaluates the ability to uncover hard-to-find information via extensive web browsing.
  • xbench-DeepSearch-2510: Tests complex search and information retrieval.
  • FrontierScience-Olympiad (FSO): Olympiad-level scientific reasoning in physics, chemistry, and biology.
  • FrontierScience-Research (FSR): Open-ended scientific research tasks, scored on a 10-point rubric (success = $\ge 7/10$).

(Web search and webpage retrieval are enabled for BrowseComp and xbench-DeepSearch-2510, and disabled for FSO and FSR, where Python execution remains available.)

Key Insights and Ideas

  • Decoupling memory from control flow enables clean rewrites: Because FactStore persists independently of the script, COS can throw away a bloated or broken Round 1 script and generate a lean, targeted Round 2 script without losing any hard-won evidence.
  • Self-evolution shines brightest on open-ended research: On FSR, COS's biggest gains come from recovering from failed scripts or missing verification steps—for instance, splitting a single overloaded verifier into two parallel verifiers targeting specific unmet conditions.
  • Diminishing returns on extra rounds: On a 50-question BrowseComp ablation, raising the round cap from 1 to 3 boosts accuracy from 64% to 72%. Pushing it to 5 rounds only adds 2 percentage points (74%) while driving up token usage (4.51M to 5.88M) and time (53.16 to 71.65 minutes). Because approved tasks stop early, most tasks (26 of 50 under the 3-round cap) finish in Round 1.

Key Results

Under matched settings with DeepSeek-V4.1-Flash, COS outperforms ReAct, Frontier Agent, and DeepSeek Harness (DSH) on the hardest research benchmarks:

  • BrowseComp: 89.65% accuracy, beating Frontier Agent (87.28%), DSH (80.33%), and ReAct (73.93%).
  • FrontierScience-Research (FSR): 53.33% success rate, exceeding DSH (31.67%) by 21.67 percentage points, ReAct (23.33%) by 30.00 points, and Frontier Agent (20.00%) by 33.33 points.
  • FrontierScience-Olympiad (FSO): 87.00% accuracy, tying DSH and Frontier Agent and beating ReAct (85.00%).
  • xbench-DeepSearch-2510: 78.00% accuracy, outperforming Frontier Agent (74.00%) and ReAct (72.00%), and trailing DSH (79.00%) by 1 percentage point.

Limitations and Future Work

  • Fixed building blocks: COS only evolves the orchestration script; it cannot invent new agent roles, tools, or runtime interfaces. If a task requires a missing capability, a developer must add it to the catalog.
  • Base model ceiling: The quality of the generated scripts is bounded by the planning and coding capabilities of the underlying LLM.
  • Computational overhead: Additional evolution rounds add LLM calls and latency, though this cost is only incurred for tasks that fail to gain approval in Round 1.
  • No cross-task reuse: Currently, COS generates scripts from scratch for each task; archiving and reusing effective orchestration patterns across similar tasks is left for future work.

Summary updated

BibTeX
@misc{hu2026code,
  author = {Xuanwei Hu and Ziyin Qiu and Hanjun Wang and Rui Wang and Yiran Zhao and Jing Kong and Yanchen Deng and Bo An},
  title = {{Code as Orchestration: Self-Evolving Multi-Agent Collaboration through Executable Scripts}},
  year = {2026},
  eprint = {2612.03504},
  archivePrefix = {arXiv},
  url = {https://arxiv.org/abs/2612.03504},
}
Figure