Multi-Model Routing and Review Workflows for Coding Agents
This article describes a reusable architecture for coding agents that sit on a heterogeneous model pool: a scheduler that picks models by capability, health, and cost; an agent that executes tasks with snapshots and tool boundaries; and a human review loop that pauses at high-risk or ambiguous steps. It covers routing with fallback and circuit breaking, confirmation cards, observability metrics, and practical engineering guidance.
1. Why Heterogeneous Models Break Collaboration
In real development work, a coding agent rarely runs in isolation. It calls one or more large models for requirement understanding, code generation, bugfixing, and context continuation. Models differ in capability mix, response stability, and interaction style: some are strong at reasoning and code but stiff in natural language and instruction following; others communicate clearly but stop short on complex refactors. Availability is also not constant—the same routing entry may land on different models over time, so latency and quality swing.
The general engineering question is: how do you build a stable, fallback-capable, reviewable coding-agent workflow on a heterogeneous model pool? This article does not discuss a specific product. It abstracts a reusable design. The core is three layers: the scheduler decides who does the work, the coding agent decides how the work is done, and the review loop decides who confirms and how to continue. Clear boundaries keep the pipeline controllable when model quality fluctuates.
2. Architecture: Scheduler, Model Pool, Coding Agent, Review Loop
A typical setup has four parts:
| Component | Responsibility | Design focus |
|---|---|---|
| Scheduler | Choose a model by task type, capability tags, and health | Priority chain, circuit breaking, fallback, idempotency |
| Model pool | Hold instances with different capability tags | Capability tagging, cost/latency tiers |
| Coding agent | Run coding tasks, keep state, call tools | State snapshots, tool boundaries, interrupt detection |
| Review loop | Surface confirmation cards to humans at key points | Card types, minimum information set, interrupt fatigue |
Flow: the agent receives a task and issues a capability request (for example strong reasoning + long context + code generation). The scheduler picks the best currently available model from the routing table. After the model returns, the agent continues with tool calls. On high-risk operations, semantic ambiguity, or missing external dependencies, it pauses, emits a review card, and resumes after a human choice. State must be durable so work can continue after model switches or outages.
Simplified routing:
from dataclasses import dataclassfrom enum import Enumclass Capability(Enum):REASONING = "reasoning"CODING = "coding"DIALOGUE = "dialogue"LONG_CONTEXT = "long_context"@dataclassclass ModelProfile:name: strcapabilities: setcost_tier: int # 1 low, 2 mid, 3 highlatency_tier: int # 1 fast, 2 mid, 3 slowhealthy: bool = Truepriority: int = 100 # lower number = higher prioritydef route(request_caps: set, pool: list[ModelProfile]) -> ModelProfile | None:candidates = [m for m in poolif m.healthy and request_caps.issubset(m.capabilities)]if not candidates:return None# Priority first, then cost and latencycandidates.sort(key=lambda m: (m.priority, m.cost_tier, m.latency_tier))return candidates[0]
The principle is capability match first, then priority, then cost and latency. Production systems still need health probes, circuit-break counters, and fallback chains.
3. Routing: Priority Chains, Fallback, Circuit Breaking
The goal is not “always pick the strongest model,” but a stable balance of availability and quality. A practical pattern is: a daily workhorse handles most tasks; when conditions allow, the scheduler prefers a stronger model and falls back to the baseline if it is unavailable. That is a three-way decision: priority chain + capability tags + health.
Capability tags. Do not hard-code model names. Tag each model (reasoning, code generation, long context, dialogue/clarification). The agent declares a required capability set; the scheduler matches sets. Adding or retiring a model is a tag change, not an agent rewrite.
Priority and fallback chains. For a given capability set, define an ordered chain, for example high-capability reasoning model → same-family standby → general baseline. Trigger fallback on timeout, invalid output format, consecutive failures past a threshold, or failed health probes. Do not drop task state: resume from the latest snapshot instead of restarting.
Circuit breaking and recovery. Track failure rate and tail latency in a sliding window per instance. Trip the circuit past thresholds so unhealthy instances are skipped. Recover with half-open probes: a few requests, then full restore if success rate is acceptable.
Idempotency and retry bounds. Tool calls may have side effects (write files, commit changes). The routing layer should retry only read-only or idempotent requests. Side-effecting operations need application-level idempotency keys so fallback does not double-execute.
Explicit cost and latency trade-offs. Stronger models often cost more and run slower. Allow routing tiers by task class: exploratory work on a low-cost chain, critical refactors on a high-quality chain. Keep tiers in configuration, not scattered in code.
4. Human–Agent Collaboration: Interrupt Points and Confirmation Cards
Agents should not decide every step alone. When work stops, the system should present option cards so the user reviews the next move. That is interrupt detection + card UX.
Typical interrupts: high-risk operations (delete files, change config, irreversible commands), semantic ambiguity (several reasonable readings of the requirement), missing external dependencies (credentials, permissions, human input), and key decisions below a confidence threshold. Predict these before execution, not only after failure.
A card’s minimum information set: step summary, why it interrupted, options and their effects, and a default recommendation. Three kinds: confirm (continue/cancel), clarify (pick an interpretation), authorize (temporary permission or scope). Options should carry machine-readable effect IDs so the agent can branch on resume instead of parsing free text.
{"card_id": "step-042","kind": "clarify","reason": "“Optimize the query” has two interpretations","options": [{"id": "A", "label": "Add indexes only", "effect": "narrow_scope"},{"id": "B", "label": "Rewrite the query", "effect": "expand_scope"},{"id": "C", "label": "Hand off to a human", "effect": "handoff"}],"default": "A"}
Interrupt fatigue: cards on every step burn patience. Set an interrupt budget (for example at most N human interventions per task), batch low-risk confirms, and interrupt high-risk steps alone. Support “don’t ask again for similar operations in this session,” with a clear, revocable scope.
5. Observability and Evaluation
Useful metrics include:
- Route hit rate: share of requests that land on a model with the requested capabilities
- Fallback rate: share that hit the fallback chain, split by model and task type
- Task completion and first-pass rate: share finished without human correction
- Human intervention rate and average interrupts: load on the review loop
- Card confirmation latency: time from display to choice (clarity of the card)
- Tail latency and failure rate: per instance, for circuit-break tuning
Log each routing decision: requested capabilities, candidates, final choice, reason, fallback path. Log each interrupt: trigger, card type, user choice, later outcome. Use the same structured logs for debugging and offline evaluation. Cover typical coding tasks and edge cases, regress regularly, and watch completion vs. intervention after routing changes. In A/B tests, control task-difficulty mix so model skill is not mistaken for policy quality.
6. Engineering Practice
- Configure, don’t hard-code. Routing tables, priority chains, circuit thresholds, and interrupt budgets belong in a config center with canary rollout and fast rollback.
- Clear tool boundaries. Whitelist agent tools; declare whether each is idempotent and whether it needs authorization. Scheduler and review loop use that for retry and interrupt policy.
- Snapshots and resume. Persist task state so model switches or restarts continue from the last checkpoint.
- Least privilege. Authorization on cards should be minimal, with expiring temporary credentials and auditable scope.
- Evolve gradually. Enable multi-model routing and card review on low-risk tasks first, then expand after metrics exist.
7. Conclusion
Multi-model routing plus a coding agent is an engineering trade-off among capability, stability, and control. The scheduler answers availability (“which model”), the agent answers execution (“how to finish”), and the review loop answers governance (“who decides at critical points”). Capability tags, fallback chains, state snapshots, and structured cards tie them together so coding assistance on mixed models stays both smooth and reliable. Predictable fallback and clear human confirmation often matter more than chasing a single strongest model.
