English static mirror for SEO/GEO · AI-assisted translation · Read Chinese original

Agent-as-a-Router: An Agentic Framework That Learns Which LLM to Use for Each Coding Task

Forum topic · 小凯 · 2026-06-28

Summary

Researchers from NUS, Alibaba DAMO Academy, UC Berkeley and others propose ACRouter, a framework that turns model routing itself into an agent. Their analysis shows no single LLM dominates: GLM-5 beats Claude Opus 4.6 by 86% on algorithm design, while Qwen3-Max is 111% better at test generation. ACRouter formalizes routing as a Context-Action-Feedback loop (a contextual multi-armed bandit) with three modules: a lightweight Qwen3.5-0.8B Orchestrator (costing ~$0.054/M tokens, ~70x cheaper than calling Claude), a Verifier producing execution-grounded confidence signals via AST parsing, sandbox execution and LLM-as-Judge, and an online kNN Memory of 20K past outcomes. Evaluated on CodeRouterBench (~10K tasks, 10 coding dimensions, 8 frontier LLMs), ACRouter achieves 49.98% average performance in-distribution (closest to the 57% oracle) with the lowest cumulative regret, and 3x better performance-per-dollar than always using Opus. Critically, on out-of-distribution agentic programming tasks, static routers (RouteLLM-BERT, LogReg) collapse to 8-21% while ACRouter reaches 62.5%, outperforming even Opus-only at 36% lower cost. Key finding: router performance is bottlenecked by missing performance information, not reasoning ability.

Agent-as-a-Router: An Agentic Framework That Learns Which LLM to Use for Each Coding Task

> Core intuition: Subscribing to the most expensive Claude Opus 4.6 does not win at everything. On algorithm design tasks, GLM-5 outperforms Opus by 86%; on test generation, Qwen3-Max is 111% better. No single LLM is universal — yet coding agents like Claude Code and Codex stubbornly use one model. ACRouter, proposed by NUS, Alibaba DAMO Academy, UC Berkeley and collaborators, makes routing itself an agent, learning online through a Context-Action-Feedback loop and achieving the lowest cumulative regret across 10 coding dimensions at 3x lower cost than always using Opus.

1. The Harsh Truth: Even the Strongest Models Have Weak Spots

Performance across 8 frontier LLMs on 9 coding dimensions:

| Dimension | Best Model | Score | Claude Opus 4.6 | Gap | |------|---------|------|-----------------|-----| | Algorithm design | GLM-5 | 47.2% | 25.4% | GLM-5 +86% | | Test generation | Qwen3-Max | 82.7% | 39.2% | Qwen-Max +111% | | Data science | Kimi-K2.5 | 18.4% | 14.2% | Kimi +30% | | Code generation / Bug fixing | Claude Opus 4.6 | — | highest | — |

Opus is strongest on average (42.9%), but is beaten by 5 different models on 5 different dimensions. Sticking to Opus means:

  • Performance loss: only 53% of the best model's level on algorithm tasks
  • Cost explosion: Opus costs 12x what Kimi-K2.5 costs
  • Opportunity cost: cheaper strong models go unused
  • If models each have strengths, why don't coding agents switch automatically?

    2. Existing Routers' Blind Spot: Not Weak Reasoning, Missing Information

    2.1 Diagnostic ablation

    Using Claude Sonnet 4.6 as router, varying only the information given:

    | Router config | Info provided | AvgPerf% | Change | |-----------|---------|---------|---------| | Vanilla | task prompt only | 41.41 | baseline | | +Dimension | + task dimension label | 41.18 | -0.6% | | +Perf stats | + per-dimension performance statistics | 47.74 | +15.3% | | DimensionBest | heuristic best-per-dimension model | 47.50 | — | | Oracle | always picks the per-task best | 57.00 | ceiling |

    Key findings: 1. Telling the router "this is an algorithm task" barely helps (41.41 → 41.18) 2. Telling it "GLM-5 averages 47.2% on algorithm tasks, Opus 25.4%" boosts performance by 15.3% 3. With perf stats, the LLM router even beats the heuristic using the same information (47.74 vs 47.50)

    Conclusion: the bottleneck is not reasoning ability but information deficiency — the router doesn't know how each model actually performs per dimension.

    2.2 The fundamental flaw of static routers

    Existing routers (RouteLLM, FrugalGPT) are static: trained once, frozen at deployment, no visibility into real execution results, no accumulation of experience.

    3. Agent-as-a-Router: Routing as an Agent

    3.1 The C-A-F loop: Context → Action → Feedback

    Each round: the Context (task prompt, metadata, memory) drives a decision (Action: which of 8 models), execution is verified, and the Feedback (score, cost) is written back to memory, enriching the next Context.

    | | Static routing | Agent-as-a-Router | |--|---------|-------------------| | Information state | frozen training knowledge | continuously updated execution experience | | Learning | offline training, frozen deployment | online, learning while serving | | Adaptability | breaks on new task types | adapts via accumulated memory | | Theory | classification / preference learning | Contextual Multi-Armed Bandit |

    3.2 Three-module architecture

    ① Orchestrator — decides. Inputs: DimensionBest prior, top-10 kNN retrieval from memory, task metadata. Core policy: a fine-tuned Qwen3.5-0.8B plus heuristic weighted voting. The router is called once per task, so a self-hosted 0.8B model on an H100 costs only $0.054/M tokens — two orders of magnitude cheaper than a Claude API call.

    ② Verifier — produces information. Rather than binary right/wrong, it combines multiple signals into a unified score u ∈ [0,1]:

    | Layer | Tool | Use case | |---------|------|---------| | AST parsing | syntax tree checks | all code tasks | | Sandbox execution | tests in Docker | executable code (generation, bug fix) | | In-prompt tests | checking expected test inclusion | tasks with standard I/O | | Rule-based signals | format/length checks | all tasks | | LLM-as-Judge | model-based quality eval | non-executable tasks (comprehension, refactoring) |

    The Verifier's output is not ground truth but execution-grounded confidence signals — exactly what static routers lack.

    ③ Memory — accumulates experience. An online vector DB: key = task embedding (voyage-code-3 or BGE-large), value = model chosen, score, cost, verification trace; cosine kNN top-10, similarity threshold 0.5; FIFO capacity of 20K entries. This gives finer granularity than "best per dimension" — even within one dimension, easy and hard tasks may favor different models.

    4. CodeRouterBench: A Purpose-Built Testbed

    Existing benchmarks can't evaluate streaming routers (no cumulative regret, no pre-collected per-task per-model result matrix for oracle computation).

    CodeRouterBench: ~10K tasks, 10 coding dimensions (~1,111 each): code generation, algorithm design, bug fixing, code completion, refactoring, data science, multilingual, code comprehension, test generation (from HumanEval+, MBPP+, LiveCodeBench, DebugBench, SWE-bench Lite, DS-1000, HumanEval-X, CodeXGLUE, etc.), plus 176 OOD agentic programming tasks (SWE-bench, LongCLI, FeatureBench).

    Splits:

  • Probing set (7,080): router development — classifier training, DimensionBest calibration, memory warm-start
  • ID Test (2,919): in-distribution held-out
  • OOD Test (176): multi-step planning, file navigation, iterative debugging — never seen during development
  • Model pool (8 frontier LLMs):

    | Model | Input \(/M | Output\)/M | Tier | |------|------------|------------|---------| | Claude Opus 4.6 | $5.00 | $25.00 | premium | | Claude Sonnet 4.6 | $3.00 | $15.00 | high | | GPT-5.4 | $2.50 | $15.00 | high | | Qwen3-Max | $1.20 | $6.00 | mid | | GLM-5 | $0.88 | $3.22 | mid | | Kimi-K2.5 | $0.60 | $3.07 | mid | | Qwen3.5-Plus | $0.40 | $2.40 | low | | MiniMax-M2.7 | $0.30 | $1.20 | low |

    5. Results: ACRouter Leads Across the Board

    5.1 In-distribution

    | Router | AvgPerf% | CumReg↓ | Perf/$↑ | |--------|---------|---------|---------| | Oracle | 57.00 | 0 | 8.20 | | ACRouter | 49.98 | 205.5 | 3.79 | | DimensionBest | 47.50 | 277.4 | 3.69 | | LinUCB | 46.84 | 296.9 | 4.38 | | LinTS | 46.48 | 307.4 | 4.49 | | Qwen3.5-FT | 46.41 | 309.1 | 6.82 | | RouteLLM-BERT | 47.22 | 285.5 | 6.22 | | Always-Opus | 43.83 | 387.1 | 1.29 | | Always-Kimi-K2.5 | 36.66 | 593.3 | 12.62 | | Random | 38.75 | 533.6 | 2.48 |

    ACRouter is the only router above 49% AvgPerf, has the lowest cumulative regret (26% below DimensionBest), and achieves 3x the performance-per-dollar of always-Opus.

    5.2 Out-of-distribution (agentic programming)

    | Router | AvgPerf% | CumReg↓ | Perf/$↑ | |--------|---------|---------|---------| | Oracle | 75.89 | 0 | 2.32 | | ACRouter | 62.50 | 17.0 | 1.18 | | Always-Opus | 57.14 | 26.7 | 0.64 | | Qwen3.5-FT | 55.36 | 27.2 | 0.74 | | LinUCB | 49.82 | 31.1 | 0.96 | | Random | 31.25 | 50.4 | 0.85 | | RouteLLM-BERT | 21.43 | 59.4 | 1.30 | | LogReg | 19.64 | 61.8 | 1.17 | | TF-IDF+MLP | 13.39 | 67.9 | 1.17 | | RouteLLM-MF | 8.93 | 72.7 | 0.94 |

    This is the paper's most striking result: static routers, near DimensionBest in-distribution (<1.3% gap), collapse entirely on OOD — as low as 8.93%, below even random (31.25%) — due to overfitting to the training distribution. ACRouter hits 62.50%, above Always-Opus, with 36% lower cumulative regret and 84% better performance-per-dollar.

    6. Key Design Insights

    Why can a small model orchestrate? Routing is a low-dimensional classification problem (8 choices), not a knowledge task. A 0.8B model suffices, and at $0.054/M tokens self-hosted (~$0.0001 per routing call vs ~$0.007 for a Claude API call — a 70x gap), the router's own cost doesn't eat the savings.

    Why is missing information more fatal than missing reasoning? Claude Sonnet 4.6 with per-dimension perf stats gains 15.3% and beats the heuristic on the same information. Reasoning isn't the bottleneck — grounded, execution-derived information is.

    Why FIFO 20K memory? Task distributions drift (new languages, frameworks); stale experience can mislead. FIFO keeps decisions based on recent experience, with reasonable retrieval latency/accuracy.

    7. Practical Takeaways for Developers

    1. Multi-model is a must, not an option: single-model agents waste money on some tasks and lose performance on others. Subscribe to 2-3 pricing tiers and route dynamically. 2. Keep the router alive: static routers break on model updates, new task types, and price changes. Online memory + sandbox verification lets ACRouter adapt; new models can be calibrated by running the probing set. 3. Self-hosting a router is cheap: ~2,000 input + 96 output tokens per routing call; self-hosted ≈ $0.0001 vs ≈ $0.007 via Claude API. Routing 1,000 tasks/day saves thousands of dollars a year.

    Acknowledged limitations: provider cache discounts not modeled (cost estimates conservative); agentic evaluation capped at 40 steps (vs standard 250); memory is simple kNN rather than neural memory.

    8. Formalization: C-A-F as Contextual Bandit

  • Arms: M candidate models
  • Context: c = (prompt, metadata, memory)
  • Pull: pick model a
  • Reward: r = s − 0.1 × κ (score minus 10% cost penalty)
  • CumReg: cumulative gap vs per-task oracle
  • This formalization brings theoretical convergence guarantees, a natural streaming evaluation metric (cumulative regret), and connects to existing algorithms — LinUCB/LinTS are simplified C-A-F variants with only parametric memory, no LLM orchestrator, and no sandbox verifier.

    Conclusion

    The core idea: routing should not be a static classification problem, but a continuously learning decision problem. Static routing says "training data suggests model X for this type"; ACRouter says "look at what happened on the 100 most similar past tasks, and pick the model validated on them." Decisions grounded in execution-verified experience rather than training-set statistics make an enormous difference on OOD tasks — static routers crash from 47% to 8–21% while ACRouter holds 62.5%.

    A practical blueprint for coding agent builders: 1. Plug in 3–8 models across cost/performance tiers 2. Use a small (0.8–7B) self-hosted router 3. Verify results via sandbox execution and accumulate online memory 4. Let the router keep learning — it gets smarter with use

    References

  • Zhou, P., Tang, Z., Ma, Y., et al. (2026). "Agent-as-a-Router: Agentic Model Routing for Coding Tasks." arXiv:2606.22902.
  • NUS, DAMO Academy (Alibaba), Hupan Lab, UC Berkeley, Zhejiang University, HKUST
  • Code and benchmark: https://github.com/LanceZPF/agent-as-a-router

Tags

#llm-routing#coding-agents#contextual-bandit#acrouter#model-selection#cost-optimization#benchmark#reinforcement-learning

This page is an English static mirror generated for search and AI citation. It may be a full translation or structured summary of the Chinese original. Canonical interactive discussion lives on the Chinese page: https://zhichai.net/topic/178208257