Multi-Model Integration Architecture for AI Agent Office Platforms

    This article presents a practical architecture for connecting multiple LLMs in an AI Agent office platform. It covers a unified model abstraction layer that hides protocol differences behind adapters, a three-tier routing strategy based on rules, cost, and quality, controlled tool calling and result sanitization for office workflows, cost and quota observability, and evaluation, canary release, and version governance. The goal is to balance output quality, cost, and compliance while keeping the model layer pluggable.

    1. Background and Problem Definition

    A clear trend has emerged in the industry: AI Agent office products no longer bind their capabilities to a single in-house model. Instead, they connect to multiple third-party general-purpose LLMs and route different tasks to different models. For example, after an update, one office agent product added several third-party general-purpose models alongside its own lightweight and enhanced models, covering scenarios such as long-context understanding, structured generation, and code and tool calling.

    In engineering terms, this is not as simple as “adding a few more API keys.” The real difficulties come down to four areas:

    1. Capability heterogeneity: models differ significantly in context window, function-calling protocol, output format stability, and concurrency quotas.
    2. Uncontrollable cost: token-based billing combined with parallel calls across multiple models can easily lead to runaway spending.
    3. Quality variance: the same prompt can perform very differently across models, and without evaluation there is no basis for model selection.
    4. Compliance and data boundaries: office scenarios involve enterprise documents, so data egress policies must be configurable and auditable.

    The following sections describe an architecture that can be put into practice.

    2. A Unified Model Abstraction Layer: Consolidating Differences in One Place

    The first principle of multi-model integration is that the upper layers should not be aware of the underlying models. Define a unified model capability interface and encapsulate differences inside adapters:

    1. class ModelAdapter(Protocol):
    2. name: str
    3. max_context: int
    4. supports_tools: bool
    5. async def chat(self, req: ChatRequest) -> ChatResponse: ...
    6. @dataclass
    7. class ChatRequest:
    8. messages: list[Message]
    9. tools: list[ToolSchema] | None = None
    10. temperature: float = 0.3
    11. max_tokens: int = 1024
    12. trace_id: str = ""
    13. @dataclass
    14. class ChatResponse:
    15. text: str
    16. tool_calls: list[ToolCall] | None
    17. usage: Usage # input/output token counts
    18. model: str
    19. latency_ms: int

    The key point is that each adapter converts protocol differences (message roles, tool declaration formats, streaming chunk structures) into internal standard structures. Upper-layer business logic depends only on ChatRequest/ChatResponse. When adding a new model, you only need to implement an adapter and register it with the factory, without changing business code.

    3. Routing Strategy: Match Tasks to Models Instead of Forcing Models to Handle Tasks

    Routing is the core value of a multi-model architecture. A three-tier routing approach is recommended:

    • Rule-based routing: hard-split by task type. For example, summarization and rewriting go to lightweight models; long-document review goes to long-context models; tasks requiring strict JSON output go to models with strong structured capabilities.
    • Cost-based routing: prefer lower-cost models as long as quality meets the bar, and set a per-request cost cap.
    • Quality-based routing: dynamically weight models based on historical evaluation scores and real-time success rates, with automatic fallback and retry on failure.

    Illustrative logic:

    1. def route(task: Task, policy: Policy) -> str:
    2. if task.kind == "long_doc_review":
    3. return policy.long_context_model
    4. if task.kind == "structured_extract":
    5. return policy.json_strong_model
    6. candidates = [m for m in policy.enabled if m.cost <= task.budget]
    7. return max(candidates, key=lambda m: m.score * m.health)

    Circuit breaking is essential: when a model repeatedly times out or its error rate exceeds a threshold, traffic automatically switches to a backup model, and the response is marked as degraded for later traceability.

    4. Tool Calling and Office Scenario Orchestration

    The value of an office agent lies in “getting things done”: reading and writing documents, retrieving from knowledge bases, initiating approvals, and generating spreadsheets. In a multi-model environment, tool calling must satisfy three requirements:

    1. Unified tool schema: use a single model-agnostic tool description, which each adapter translates into a format the target model accepts.
    2. Least privilege: each tool declares the data scope it needs, and sensitive operations require secondary confirmation.
    3. Controlled result backfill: tool return values are trimmed and desensitized before entering the context, avoiding feeding large blocks of enterprise data directly to the model.

    A typical controlled backfill example:

    1. def sanitize(tool_result: dict, allow_fields: set[str]) -> str:
    2. trimmed = {k: v for k, v in tool_result.items() if k in allow_fields}
    3. return json.dumps(trimmed, ensure_ascii=False)[:2000]

    5. Cost, Quotas, and Observability

    Multiple models inevitably add metering complexity. Recommended practices:

    • Log the model name, input/output tokens, latency, and whether degradation occurred for every call, writing it all to a centralized logging service.
    • Set per-user/per-tenant daily quotas and overall budget thresholds in monitoring and alerting; when exceeded, automatically degrade to a lightweight model or queue requests.
    • Build dashboards that report average cost and success rate by task type, serving as the basis for adjusting routing weights.

    Pseudocode for budget control:

    1. if usage.daily_cost + req.est_cost > tenant.budget:
    2. model = policy.fallback_light
    3. else:
    4. model = route(task, policy)

    6. Evaluation, Canary Release, and Version Governance

    Multi-model integration without evaluation is flying blind. Implementation recommendations:

    1. Build an offline evaluation set covering five task categories: summarization, extraction, rewriting, question answering, and tool calling, with no fewer than several hundred real, desensitized samples per category.
    2. Use multiple metrics: accuracy, format compliance rate, tool-calling success rate, P95 latency, and cost per task.
    3. Canary release: route 5% of traffic to a new model first, observe success rate and cost, then gradually increase the share.
    4. Version locking: bind prompt templates to model versions and record them to ensure reproducible results.

    7. General Cloud Capabilities from Baidu AI Cloud’s Perspective

    In enterprise practice at Baidu AI Cloud, this type of architecture typically relies on general cloud product categories: a container platform to host adapters and orchestration services, object storage to hold evaluation sets and audit logs, a message queue to smooth asynchronous task peaks, and logging and monitoring services for cost and quality observability. Keeping the model layer pluggable while the business layer stays stable is the key to controlling complexity and risk.

    8. Conclusion

    The essence of multi-model integration is turning “model selection” from product hard-coding into an operable engineering capability. A unified abstraction layer solves heterogeneity, routing strategy solves matching, tool orchestration solves execution, and metering plus evaluation solve controllability and optimization. Getting these four things solid allows an AI Agent office platform to achieve a sustainable balance among quality, cost, and compliance.