Multi-Model Office Agents: Unified Routing and Cost Metering in Practice

    Office agents handle tasks with very different context, reasoning, latency, and cost requirements. This article explains why multi-model access is necessary and breaks down interface heterogeneity, capability differences, cost and quota metering, availability, and data compliance. It then presents a layered architecture with a unified abstraction layer, routing strategies, quota multipliers, and observability practices for building configurable, measurable, and fallback-capable agent systems.

    1. Why Office Agents Need Multiple Models

    Office scenarios vary widely. Meeting notes, email drafting, spreadsheet information extraction, code snippet generation, and long-document question answering place different demands on context length, reasoning ability, response speed, and per-call cost. If the entire product is tied to a single model, two problems appear: simple tasks bear unnecessary cost, while complex tasks are limited by the capability boundary of one model.

    The value of multi-model access is turning “which model to use” into a configurable, observable, and fallback-capable decision rather than hardcoding it in business logic. This follows the same idea as read-write splitting, multi-replica redundancy, and multi-region deployment in backend engineering.

    Provider availability fluctuations, price adjustments, and changing compliance requirements all affect model selection. Managing models as replaceable external dependencies is a basic way to reduce risk.

    2. Problem Breakdown

    2.1 Interface Heterogeneity

    Different model services have different request formats, authentication methods, streaming output protocols, error codes, and rate-limiting policies. If the business layer calls each provider’s API directly, it creates large amounts of duplicated code and raises testing costs. The solution is to add a conversion layer between the business layer and providers.

    2.2 Capability Differences

    The same task category may perform very differently across models. For example, some models are more stable at structured output, while others are better at long-text summarization. Model selection should be based on offline evaluation results rather than subjective impressions. Evaluation should record quality scores for each task category and be rerun when model versions are updated.

    2.3 Cost and Quota Metering

    Most model services charge by the number of input and output tokens, and unit prices differ by model. The product side usually also needs to convert underlying usage into a user-understandable “quota” and display consumption in the interface. This means metering must be precise for every request and traceable to the specific model and user.

    2.4 Availability and Latency

    A single service may experience timeouts, rate limiting, or short-term unavailability. The system needs timeout control, retry policies, and fallback models to ensure that user requests eventually receive a result or a clear failure message.

    2.5 Data Boundaries and Compliance

    User documents may contain personal information or business secrets. Different providers have different data processing terms, such as whether data is used for training, whether it is stored across borders, and how long it is retained. These terms need to be checked before integration, and policies should restrict which tasks are allowed to call which models.

    3. Overall Architecture

    A layered structure is recommended, with clear responsibilities for each layer:

    • Access layer: receives business requests, performs authentication, parameter validation, and request-level rate limiting.
    • Unified abstraction layer: wraps each model’s calling method into a unified interface and exposes only standard generation results, streaming chunks, and finish reasons to upper layers.
    • Routing and policy layer: selects the target model based on task type, user tier, budget balance, and model health status.
    • Metering layer: records input and output usage for each call, converts it into quota according to multipliers, and writes it to the ledger.
    • Observability layer: collects latency, error rate, cost, and quality metrics for alerting and iteration.

    Layers communicate through well-defined data structures. Business code should not directly depend on private fields of a specific model; otherwise, replacing a model would require a large scope of changes.

    4. Unified Abstraction Layer Design

    The key to unified abstraction is defining a minimal common interface. The following example only illustrates the structure; class names and field names are generic.

    1. from dataclasses import dataclass
    2. from typing import Iterator, Protocol
    3. @dataclass
    4. class GenerateRequest:
    5. messages: list[dict] # Unified role-based message structure
    6. max_output_tokens: int
    7. temperature: float = 0.2
    8. task_type: str = "general"
    9. @dataclass
    10. class GenerateResult:
    11. text: str
    12. input_tokens: int
    13. output_tokens: int
    14. model_id: str
    15. finish_reason: str
    16. class ModelAdapter(Protocol):
    17. model_id: str
    18. def generate(self, req: GenerateRequest) -> GenerateResult: ...
    19. def stream(self, req: GenerateRequest) -> Iterator[str]: ...

    The design points are as follows.

    1. Requests and responses use internal structures and do not pass provider raw fields through to upper layers.
    2. Each adapter is responsible only for protocol conversion and does not contain routing or billing logic. This way, adding a new model requires only one adapter.
    3. Errors are mapped uniformly to internal error types, such as rate limit, timeout, content block, and parameter error. Upper layers use these to decide whether to retry, switch models, or return failure directly.
    4. Input and output token counts must be returned by the adapter because the metering layer depends on these numbers. If the provider does not return usage, a local tokenizer should be used to estimate it, and the record should be marked as an estimate so that reconciliation can distinguish it later.

    5. Routing Strategy

    Routing decides which model handles each request. There are four common strategies.

    1. Static mapping: configure a default model by task type. Summarization tasks use lower-cost models, while complex reasoning tasks use more capable models.
    2. Budget constraint: when the user’s remaining quota is insufficient, automatically switch to a model with a lower consumption factor and explain the reason for the switch in the interface.
    3. Health awareness: models with consecutive failures or latency above a threshold are temporarily removed from the candidate list and added back after periodic probing confirms recovery.
    4. Canary experiment: allocate a small portion of traffic to a new model, compare quality and cost metrics, and gradually increase the proportion after confirming the results.

    A route table example is as follows:

    1. ROUTE_TABLE = {
    2. "summarize": ["model_a", "model_b"],
    3. "code_assist": ["model_c", "model_a"],
    4. "extract": ["model_b"],
    5. }
    6. DEFAULT_MODEL = "model_a"
    7. def pick_models(task_type: str, budget_level: str,
    8. healthy: set[str], cost_factor: dict[str, float]) -> list[str]:
    9. candidates = ROUTE_TABLE.get(task_type, [DEFAULT_MODEL])
    10. if budget_level == "low":
    11. candidates = sorted(candidates, key=lambda m: cost_factor.get(m, 1.0))
    12. available = [m for m in candidates if m in healthy]
    13. # If all candidates are unavailable, fall back to the default model and let downstream degradation logic handle it
    14. return available or [DEFAULT_MODEL]

    The route table should be placed in a configuration center and support hot updates. If it is hardcoded in a release package, every adjustment requires redeployment, which slows emergency response.

    6. Quota Multipliers and Metering

    Users see quota, while the system records tokens at the underlying level. The two are converted through a multiplier. The calculation can be expressed as follows: quota consumed per request is derived from token usage through the applicable multiplier.