Agent-as-a-Router: Agentic Model Routing for Coding Tasks

Pengfei Zhou, Zhiwei Tang, Yixing Ma, Jiasheng Tang, Yizeng Han, Zhenglin Wan, Fanqing Meng, Wei Wang, Bohan Zhuang, Wangbo Zhao, Yang YouarXiv 2026

TL;DR

Instead of relying on a single massive Large Language Model (LLM) for all programming tasks, why not route each problem to the specific model best suited to handle it? This paper introduces Agent-as-a-Router, a framework that treats model routing as an evolving Context-Action-Feedback loop. Their implementation, ACRouter, dynamically learns model strengths via execution-grounded sandbox feedback, significantly outperforming static routers and cutting costs on both in-distribution and out-of-distribution coding tasks.

What Problem Does This Paper Address?

In the rapidly evolving landscape of AI coding assistants, most agents rely on a single, fixed LLM backend. However, no single model dominates every coding domain: one might excel at competitive algorithms, another at data science, and a third at writing test suites. Manually picking the best model per task is impossible at scale, making automatic model routing essential.

Existing routers treat this choice as a static, one-off classification problem. The authors discover that the fundamental bottleneck of these static routers isn't a lack of reasoning capability, but an information deficit. Because their internal states are frozen, static routers cannot adapt to deployment realities or know how well a model actually performed on a specific task.

Model performance varies significantly across different coding dimensions, meaning a single model rarely dominates.

Methods

To close this information gap, the authors propose formalizing routing as a Context-Action-Feedback (C-A-F) loop, drawing an algorithmic parallel to contextual multi-armed bandit problems.

They instantiate this framework as ACRouter (Agentic Coding Router), which consists of three core modules:

  1. Orchestrator: Composes the current context (task metadata, prior statistics, and historical memory) and uses a fine-tuned, lightweight model (Qwen3.5-0.8B) combined with heuristic rules to select the best model backend.
  2. Verifier: A sandbox-native evaluator that runs the selected model's code output (checking AST parsing, unit tests, etc.) to generate a real-time performance score without needing ground-truth answers.
  3. Memory: An online vector store that logs task embeddings alongside their execution outcomes. It uses $k$-NN retrieval to feed the top-10 most similar historical experiences back into the Orchestrator for the next task.
Comparison of static routing strategies versus the iterative, self-evolving Agent-as-a-Router framework.

Datasets

To evaluate streaming, regret-based routing, the authors built CodeRouterBench, a unified testbed containing ~10,000 tasks across 10 coding dimensions compiled from over 15 source benchmarks (e.g., HumanEval+, MBPP+, SWE-bench). The dataset includes verified execution scores from 8 frontier LLMs (including Claude Opus 4.6, Claude Sonnet 4.6, and GPT-5.4). It is split into:

  • Probing Set (7,080 tasks): Used to profile model strengths and train routers.
  • In-Distribution Test Set (2,919 tasks): Held-out single-turn coding tasks.
  • Out-of-Distribution (OOD) Test Set (176 tasks): Complex, multi-step agentic programming tasks derived from SWE-bench to test how well routers generalize to entirely new task distributions.

Key Insights and Ideas

  • Information Deficit is the Real Bottleneck: Simply adding prior performance statistics to a vanilla zero-shot LLM router yielded a 15.3% relative performance gain, proving that routers fail primarily because they lack information about model capabilities, not because they can't reason.
  • Coding Skill $\neq$ Routing Skill: Surprisingly, the strongest individual coding model in the pool (Claude Opus 4.6) performed the worst when tasked with acting as a zero-shot router.
  • Static Routers Collapse on OOD: Traditional trained classifiers (like RouteLLM or logistic regression) perform decently on in-distribution tasks but completely collapse on complex OOD agentic programming tasks, dropping below random choice. Dynamic routers that update their memory online are required to survive distribution shifts.

Key Results

  • Lowest Cumulative Regret: On in-distribution tasks, ACRouter achieved the highest average performance (49.98%) and the lowest cumulative regret (205.5), beating all static baselines and heuristics.
  • OOD Generalization: On the challenging OOD agentic programming tasks, ACRouter achieved a 62.50% resolution rate, outperforming the single best model strategy (Always-Opus at 57.14%) while dramatically reducing total monetary costs ($52.97 vs $89.28).
  • Pareto Frontier Advancement: ACRouter successfully pushes the cost-performance Pareto frontier upward, offering a superior trade-off between task quality and token expenditure.
Cumulative regret over time shows that static routers accumulate error rapidly on OOD tasks, while ACRouter stabilizes by learning from experience.

Limitations and Future Work

  • Cache Unobservability: Provider-side token caching is invisible to the router, meaning monetary cost calculations are approximations based on public API pricing.
  • Step Constraints: The OOD agentic evaluation was capped at 40 steps per task (instead of the standard 250) to keep the experimental compute budget tractable.
  • Future Directions: The authors suggest extending the C-A-F loop paradigm beyond model selection to other agentic choices, such as tool routing, sub-agent routing, and dynamic thinking-effort allocation.

Summary updated

BibTeX
@misc{zhou2026agent,
  author = {Pengfei Zhou and Zhiwei Tang and Yixing Ma and Jiasheng Tang and Yizeng Han and Zhenglin Wan and Fanqing Meng and Wei Wang and Bohan Zhuang and Wangbo Zhao and Yang You},
  title = {{Agent-as-a-Router: Agentic Model Routing for Coding Tasks}},
  year = {2026},
  eprint = {2606.22902},
  archivePrefix = {arXiv},
  url = {https://arxiv.org/abs/2606.22902},
}
Figure