Multi-Model AI Office Agent Architecture: Routing, Metering, and Cost Control

    This article explains how to build an AI office agent platform that schedules multiple heterogeneous models reliably and economically. It covers a four-layer architecture, a unified model abstraction with adapters, three generations of routing strategy from static rules to weighted scoring and feedback loops, quota metering with time-window scheduling, context governance in agent orchestration, and stability mechanisms such as fallback chains, circuit breaking, and idempotency. It also lists task-level evaluation metrics, cost control techniques, and the general cloud capabilities that support such a platform.

    1. Why an AI Office Agent Needs Multiple Models

    The core engineering problem behind a recent AI office product adding third-party models alongside its in-house model is a general one: how to make a productivity-oriented agent platform schedule multiple heterogeneous models stably and economically.

    A single-model architecture is enough for a PoC, but three problems surface in production:

    1. Capability mismatch. Long-document summarization, table extraction, code generation, and multi-turn tool calling place very different demands on a model. No single model is best at every subtask.
    2. Concentrated cost and capacity risk. When all traffic goes to one model, a rate limit or a price change directly threatens business continuity.
    3. No room for negotiation or optimization. Without alternatives, you cannot trade scheduling decisions for a better cost per task.

    The point of multi-model integration is to demote “model” from a fixed dependency to a replaceable compute resource, with the platform layer owning routing, metering, and fallback.

    2. Overall Architecture: Four Decoupled Layers

    Split the system into four layers that communicate through explicit contracts:

    • Access layer: a unified API gateway that hides differences in authentication, context length, and streaming protocols across models.
    • Routing layer: selects a model based on a task profile and outputs a model_id plus a fallback chain.
    • Execution layer: the agent orchestration engine, responsible for task decomposition, tool calls, and context management.
    • Metering layer: records quota consumption, latency, and success or failure for every call, providing data for policy optimization.

    The key design principle: business code must not hardcode any specific model identifier. Model selection should be the product of configuration and policy, not branching logic.

    3. Unified Access and an Abstract Interface

    The place where heterogeneous integration most easily gets out of control is the “least common denominator of parameters” problem. In practice, define an internal standard request and let adapters translate it to each backend:

    1. # Internal unified request structure (illustrative)
    2. @dataclass
    3. class ModelRequest:
    4. messages: list[dict] # role/content
    5. max_output_tokens: int
    6. temperature: float
    7. tools: list[dict] | None # tool/function definitions
    8. stream: bool
    9. task_type: str # summary / extract / code / chat
    10. # Unified adapter interface
    11. class ModelAdapter(Protocol):
    12. def supports(self, req: ModelRequest) -> bool: ...
    13. def invoke(self, req: ModelRequest) -> ModelResponse: ...

    Capability differences that must be handled explicitly include tool-calling support, streaming support, maximum context length, and whether a system prompt is accepted. For a model that lacks a capability, the routing layer should filter it out during candidate selection rather than retry after a failed call — retrying on failure significantly amplifies tail latency.

    4. Routing Strategy: From Rules to Scoring

    Routing is the value center of the whole design. Evolve it in three generations:

    Generation 1: static rules. Map a fixed model to each task type. Simple to implement, but unable to respond to load and cost changes.

    Generation 2: weighted scoring. Maintain a multi-dimensional score for each candidate model and pick the weighted best:

    1. score = w1 * quality_score \
    2. - w2 * normalized_cost \
    3. - w3 * normalized_latency \
    4. - w4 * current_load_factor

    current_load_factor is driven by recent error rates and rate limiting, which enables automatic avoidance.

    Generation 3: feedback loop. Write the pass rate of result validation back into quality_score for continuous self-optimization. Use sliding-window statistics in engineering so a single sample cannot pollute the score.

    5. Quota Metering and Scheduling Windows

    Two general mechanisms stand behind time-based discounts and consumption multipliers:

    1. Differentiated pricing model. The platform maintains a “model–time window–multiplier” configuration table, moving billing rules out of code into hot-reloadable configuration.
    2. Time-shifting of deferrable tasks. Not every task needs an immediate response. Split tasks into interactive ones (chat, completion) and batch ones (bulk summarization, report generation, log classification); the latter enter a queue and run in low-cost windows.
    1. # Scheduling configuration (illustrative)
    2. windows:
    3. - cron: "0 12-14 * * 1-5"
    4. discount: 0.5
    5. eligible: [batch_summary, batch_extract]
    6. routing:
    7. interactive: [model_a, model_b] # low latency first
    8. batch: [model_c, model_a] # cost first

    This peak shaving and valley filling lowers unit cost and smooths capacity pressure on the backend.

    6. Agent Task Orchestration and Context Governance

    The hidden cost of multiple models is repeated context transmission. If the same long document is carried through multiple turns, quota consumption multiplies. Countermeasures:

    • Structure and persist long documents first (store the original in object storage and pass only a summary plus locator information);
    • Retrieve fragments on demand via retrieval instead of stuffing everything into the context;
    • Compress and denoise tool-call results, keeping only conclusions and necessary evidence;
    • Set an upper bound on the context budget and trigger segmented processing when it is exceeded rather than truncating outright.

    For orchestration, use a three-stage “plan–execute–verify” flow: the planning stage decomposes subtasks and tags the capabilities they need; the execution stage routes by capability tag; the verification stage checks output with rules or an independent model, and on failure retries with feedback — and the retry should use a different model to avoid same-source errors.

    7. Stability: Fallback, Circuit Breaking, and Idempotency

    The biggest gain from multiple models is availability redundancy, provided the fallback path actually works:

    • Fallback chain: after the primary model is rate limited or times out, switch in a preset order while keeping session and tool state consistent.
    • Circuit breaking: after consecutive failures reach a threshold, temporarily remove a candidate and probe for recovery in a half-open state.
    • Idempotency: write-type tools must carry an idempotency key to prevent duplicate submissions from retries.
    • Observability: collect latency, success or failure, quota consumption, and task completion rate uniformly, and configure monitoring and alerts; avoid logging sensitive source text.

    8. Evaluating Results and Governing Cost

    Evaluation must happen at the task level, not the call level. A suggested metric set: task success rate, first-pass rate, average retries per task, quota cost per task, and end-to-end latency P95. Build a small offline evaluation set and run regression before any model or policy change to prevent “locally optimal, globally degraded” outcomes.

    Beyond scheduling windows, cost governance can also use output length limits, prompt trimming, and cache reuse (reusing results for frequent identical requests). Caching needs an explicit invalidation policy to avoid returning stale conclusions.

    9. Combining with General Cloud Capabilities

    You usually do not need to build all the infrastructure yourself; combine general cloud product categories: a container platform to host the agent runtime and scale elastically; a message queue to shave batch peaks; object storage for long documents and intermediate artifacts; logging and monitoring with alerting for observability; and a key management service to hold credentials for each backend. Baidu AI Cloud offers corresponding capabilities in these general categories and can serve as one foundation option for building such a multi-model scheduling platform.

    10. Conclusion

    Multi-model integration is not simply “adding a few more options” but an architectural upgrade: treat models as schedulable resources, hide differences behind a unified abstraction, balance quality, cost, and latency with scored routing, optimize unit cost with metering and scheduling windows, and protect delivery quality with fallback and verification. For an office agent, the ultimate competitive edge is how many usable results it can reliably deliver under the same quota — which is exactly where engineering optimization should focus.