Multi-Model AI Agent Architecture for Office Platforms: Routing, Cost Control, and Governance
This article breaks down the engineering work behind connecting an office-focused AI Agent to multiple large language models. It covers a vendor-neutral model abstraction layer, a three-stage routing strategy from rules to statistics to learning, capability-to-model matching for office tasks with server-side schema validation, cost controls such as semantic caching and context trimming, and the stability, security, and governance practices required in production. It closes with a four-step rollout plan and the acceptance metrics teams should hold fixed before scaling traffic.
1. Background and the Core Engineering Problem
A recent AI Agent office product announced support for several third-party large models, along with a limited-time promotional plan. The underlying facts are only three: the product is an agent built for office scenarios; its capabilities now come from a mix of a self-developed model and multiple external models rather than a single in-house model; and its business model introduces a temporary price incentive.
Strip away the specific product, and the part that actually matters to developers is not who connected to whom, but a general engineering question: when an office agent moves from a single model to multiple models, how must the system architecture, governance approach, and cost model be restructured? That is the thread this article follows.
The drivers for multi-model adoption usually come from four directions:
- Capability complementarity: models differ in long-context understanding, structured output, code generation, and multi-turn tool calling.
- Cost tiering: lightweight models handle simple tasks, and only complex reasoning is escalated to a high-capability model, which lowers the overall bill significantly.
- Supply resilience: when a single vendor hits rate limits, becomes unstable, or ships a breaking version change, the business does not go fully unavailable.
- Compliance and data boundaries: some tasks require data to stay inside a specific network domain, so requests must be routed to different deployment forms by task.
2. A Unified Model Abstraction Layer: The First Design Decision
The most common reason multi-model integration fails is scattering each vendor’s API directly across business code. The correct approach is to define an internal abstraction that is independent of any vendor, and have business code depend only on that abstraction.
A sketch of the interface (language-agnostic, expressing the contract only):
interface ModelAdapter {id(): string // logical model identifiercapabilities(): Set<Capability> // supported capabilities: text/structured output/tool calling/long contextinvoke(request: ChatRequest): ChatResponsestream(request: ChatRequest): AsyncIterator<Chunk>estimateTokens(request): number}
Key design points:
- Decouple logical model names from physical models. Business code uses names like
reasoning-strongandchat-fast, and configuration decides which actual backend each maps to, so switching backends requires no business code change. - Declare capabilities rather than assume them. Each adapter explicitly declares whether it supports tool calling, structured output, and its context window limit, and the routing layer filters candidates accordingly.
- Unify error semantics. Normalizing rate limiting, timeouts, content blocking, and context overflow into a small set of error codes gives retry policies a single basis to work from.
- Unify metering. Every adapter reports input and output tokens plus call counts, producing a cost baseline that can actually be accounted for.
3. Routing Strategy: From Round Robin to Task-Aware Scheduling
Routing is where a multi-model architecture creates value. The recommended path is three stages — rules first, then statistics, then learning — to avoid adopting a complex model on day one.
Stage 1: Rule-based routing. Statically split traffic by task type and request characteristics, for example sending summarization and rewriting to a lightweight model and proposal writing or code generation to a strong reasoning model. Rules stay configurable:
routing:- name: summarymatch: { task: summarize, max_input_tokens: 8000 }model: chat-fastfallback: [reasoning-strong]- name: codematch: { task: code_generation }model: reasoning-strongtimeout_ms: 60000
Stage 2: Statistical routing. Collect success rate, time to first token, and per-task cost for each model under real traffic, then select dynamically using a weighted score; models that fail repeatedly are automatically down-weighted.
Stage 3: Learned routing. Train a lightweight classifier on a small labeled set to predict which model performs better on a given request, while keeping fallback rules and human-readable logs in place.
One thing must be implemented in engineering: a fallback chain. When the primary model is unavailable, alternatives are tried in order; if all fail, return a readable failure message rather than a blank result.
4. Breaking Down Office Capabilities and Matching Models
An office agent is not a single capability but an orchestration of several sub-capabilities. Matching models by capability is more economical than matching by overall strength:
- Document summarization and key-point extraction: favors long context and stable structured output.
- Table and structured data generation: favors strict format adherence, paired with schema validation.
- Meeting minutes to task breakdown: requires multi-step reasoning and entity consistency.
- Code and script generation: requires tool calling and executability verification.
- Retrieval-augmented question answering: beyond model quality, retrieval quality often matters more.
Structured output must be validated server-side. A sketch of the flow:
schema = load_schema("meeting_minutes.json")resp = adapter.invoke(ChatRequest(prompt=prompt, schema=schema))data = validate(resp.text, schema) # on failure, retry once with error detailsif not data:resp = adapter.invoke(ChatRequest(prompt=prompt + repair_hint, schema=schema))
5. Cost Control: Turning a Limited-Time Discount into Long-Term Bill Governance
A temporary price discount only reduces short-term spend; long-term cost is determined by architecture. Practical measures include:
- Semantic caching: cache results for frequent, similar requests, where a cache hit costs nothing in model spend; this needs a similarity threshold and an invalidation policy.
- Context trimming: rerank retrieved passages and keep only the highly relevant ones, and compress conversation history into a summary, which directly cuts input tokens.
- Tiered model pools: keep lightweight, standard, and strong-reasoning tiers available, and escalate based on task value.
- Budgets and quotas: set daily budgets and concurrency caps per tenant or department to prevent runaway calls from inflating the bill.
- A closed observability loop: put call volume, tokens, success rate, and per-task cost on the same dashboard so cost anomalies can be attributed.
6. Stability, Security, and Governance
- Timeouts and retries: automatically retry only idempotent requests, using exponential backoff with jitter to avoid retry storms.
- Rate-limit isolation: give each business line its own quota so a single hotspot does not drag down the whole system.
- Data boundaries: desensitize sensitive data before it leaves the domain, never log raw text, and manage all keys through a key management service.
- Content safety: filter both input and output, and retain audit trails for traceability.
- Version management: treat a model version change as a configuration change that goes through canary release and rollback, and keep a regression evaluation set.
7. Rollout Plan and Acceptance Metrics
A four-step sequence is recommended: build the abstraction layer and metering first, then add rule-based routing and the fallback chain, then introduce caching and context compression, and finally add statistical routing and a closed evaluation loop.
The acceptance metrics should stay fixed: task success rate, P95 time to first token, average cost per task, fallback trigger rate, and first-pass rate for structured output. Not expanding traffic when metrics fall short is the most effective discipline for controlling risk.
8. Conclusion
The essence of multi-model integration is turning “model selection” from a product decision into programmable infrastructure capability. On top of general-purpose capabilities such as the container platform, message queue, object storage, logging service, and monitoring and alerting offered by Baidu AI Cloud, a team can build this abstraction and routing layer itself, letting an office agent reach a sustainable balance among capability, cost, and stability.
