Multi-Model Routing for Office AI Agents: A Practical Engineering Guide

    This article explains how to build a multi-model routing layer for office AI agents. It covers why single-model architectures fall short for mixed office workloads, the four layers of a routing system, request feature extraction, rule-based, scoring, and classifier-based decision strategies, fallback and retry handling for long-running tasks, cost and capacity governance, and a three-tier evaluation framework. It closes with a phased rollout path from observability to automated cost control. Readers will get concrete configuration and code examples they can adapt to their own routing stack.

    1. Why Office Agents Move to Multi-Model Routing

    Office workloads are highly uneven. Some tasks are deterministic with short inputs and short outputs, such as formatting cleanup, field extraction, and summarization. Others are far more demanding: cross-document reasoning, long-context comparison, and multi-round solution iteration. No single model can simultaneously deliver low latency, high stability, and low cost across all of these dimensions, which is why the industry has largely converged on a “multiple model backends behind a unified scheduling layer” architecture.

    Public market observations show that leading office agent products already serve monthly traffic in the tens of millions, with a several-fold gap between leaders and followers. That competitive pressure translates directly into a technical requirement: under the same compute budget, use smarter scheduling to spend limited model capacity where it matters most. This is the fundamental reason the value of a routing layer is amplified.

    It is worth stressing that routing is not simply “pick the strongest model.” It is a constrained optimization problem: minimize latency and cost while meeting a quality threshold and satisfying compliance and data residency requirements.

    2. The Four Layers of a Routing System

    A maintainable routing system is usually split into four layers, decoupled from one another through explicit contracts.

    1. Capability layer: each backend model maintains a capability profile covering context window, structured output support, function-calling stability, multilingual performance, concurrency quota, and price tier.
    2. Feature layer: extract features from each incoming request to form a decision vector the router can use.
    3. Decision layer: apply a policy (rules, scoring, a lightweight classifier, or a combination) to output the target backend and parameters.
    4. Execution and feedback layer: handle invocation, timeouts, retries, fallback, telemetry, and online evaluation feedback.

    Capability profiles are best managed as declarative configuration, which makes canary rollout and rollback straightforward:

    1. models:
    2. - id: m_fast
    3. context: 32k
    4. strengths: [classification, extraction, short_summary]
    5. p95_latency_ms: 900
    6. cost_per_1k: low
    7. - id: m_reason
    8. context: 200k
    9. strengths: [long_context, multi_hop_reasoning, code]
    10. p95_latency_ms: 4200
    11. cost_per_1k: high
    12. routing:
    13. policy: hybrid
    14. rules:
    15. - when: "input_tokens > 60000"
    16. route: m_reason
    17. - when: "task_type in [format, tag, translate_short]"
    18. route: m_fast
    19. fallback: [m_reason, m_fast]

    3. Request Feature Extraction Sets the Real Ceiling on Routing Quality

    The ceiling on routing quality is determined by feature quality, not by the decision algorithm. In practice, three categories of features are worth extracting:

    • Scale features: input length, estimated output length, number of attachments, and whether cross-document comparison is required.
    • Task features: task type (extraction, summarization, rewriting, generation, reasoning), whether strict structured output is required, and whether citation traceability is needed.
    • Constraint features: data sensitivity level, acceptable latency budget, tenant quota, and cost ceiling.

    A common mistake is looking only at input length. In real scenarios, a request with a short input that demands multi-hop reasoning is often harder on model capability than a long-input request, so task type and output constraints should carry more weight than length alone.

    4. Three Implementation Paths for Decision Policies, and How to Combine Them

    Rules first: explainable and easy to debug, well suited to cold start and strict compliance scenarios. The drawback is incomplete coverage, and maintenance cost grows as rules accumulate.

    Scoring model: compute a utility score for each candidate backend and take the maximum. Sketch:

    1. def score(model, feat, weights):
    2. return (
    3. weights["quality"] * model.quality_est[feat.task_type]
    4. + weights["speed"] * (1 - model.norm_latency)
    5. + weights["cost"] * (1 - model.norm_cost)
    6. + weights["compliance"] * model.compliance_fit[feat.sensitivity]
    7. )
    8. def route(candidates, feat, weights):
    9. best = max(candidates, key=lambda m: score(m, feat, weights))
    10. return best.id

    Lightweight classifier: train a task-to-backend mapping from historical telemetry. This suits teams with large traffic and ample labels. The key is to use “did the user retry, and did they accept the result” as weak labels, closing the loop.

    For production, a hybrid policy is generally recommended: rules cover hard constraints such as compliance and extra-long context, the scoring model handles the middle ground, and the classifier absorbs most traffic on high-frequency deterministic tasks to drive cost down.

    5. Engineering Details for Fallback, Retry, and Long-Running Tasks

    Routing must assume failures will happen. Three principles are recommended:

    • Declare the fallback chain explicitly, and ensure fallback still satisfies compliance constraints. Availability must never be bought by bypassing data requirements.
    • Retry only idempotent calls with determinable failures, to avoid duplicate billing and duplicate side effects.
    • Make long tasks asynchronous: return a task identifier first, then advance state through a message queue, record intermediate results in state storage, and let the frontend poll or subscribe to notifications.
    1. request -> feature extraction -> decision -> primary backend
    2. |-- timeout/error -> fallback backend
    3. |-- all failed -> queued retry + alert

    6. Cost Control and Capacity Governance

    The core of cost governance is “reserve expensive models for high-value requests.” Practical measures include: a dedicated small-model lane for high-frequency deterministic tasks; semantic caching for similar requests; per-tenant quotas and priorities; and isolating inference traffic of different priorities by queue on the container platform so long tasks do not crowd out interactive requests.

    On the capacity side, three metrics are worth watching together: average cost per request, fallback rate, and quota hit rate per backend. A sudden spike in fallback rate is usually the first signal of quota exhaustion or backend instability, and should be wired into monitoring and alerting.

    7. Evaluation: No Evaluation, No Routing Optimization

    Evaluation should have three tiers:

    1. Offline replay: replay different policies against a real, de-identified request set and compare the three-way metrics of quality, latency, and cost.
    2. Online canary: split traffic by tenant or percentage, and observe acceptance rate, retry rate, and manual edit rate.
    3. Long-cycle regression: run a fixed benchmark set weekly to prevent backend model upgrades from silently invalidating a policy.

    Log both the policy version and the model version in the logging service so that the routing decision for any historical request can be reproduced. This is critical for both troubleshooting and auditing.

    8. A Phased Rollout Path

    Phase one: make it observable — a unified gateway, unified telemetry, and capability profiles as configuration. Phase two: add rules and fallback, shoring up stability and compliance first. Phase three: introduce scoring and learned policies, validating gains with offline replay before canary rollout. Phase four: close the loop on automated capacity and cost, so policies adapt as traffic shifts.

    Overall, competition among office agents will ultimately come down to scheduling efficiency: whoever can reliably deliver higher-quality results with the same resources controls the entry point. Multi-model routing is the engineering foundation of that capability, and the combination of general-purpose building blocks from Baidu AI Cloud — model services, container platform, message queue, logging, and monitoring and alerting — provides standard components for building such a scheduling layer, letting teams focus their effort on the two areas that truly determine results: policy and evaluation.