Multi-Model Integration in AI Agents: Architecture and Cost Governance

    AI agents used in office and productivity settings often face tasks with very different requirements for capability, response speed, and cost. Since no single model is optimal for every scenario, products increasingly integrate multiple model providers and select a model by task or user. This article discusses how a unified access layer, provider adapters, and a model registry can isolate vendor-specific complexity, and how a normalized quota system with per-model cost multipliers can make consumption transparent and controllable. It also covers practical metering rules: show multipliers in the UI, settle by actual token usage, and define refund or no-charge behavior for failed requests.

    Background: Multiple Models Are Now Common in Office AI Agents

    Office-focused AI agents need to handle a wide range of tasks: text polishing, meeting notes, table analysis, code snippet generation, and long-document retrieval. These tasks have different requirements for model capability, response speed, and cost. A single model can rarely achieve the best result in every scenario. Therefore, more products are integrating third-party models alongside their in-house models, with either the user or the system choosing the model for each task.

    Multi-model integration offers three direct benefits. First, the same task can be handled at the desired trade-off point between capability and price. Second, if one model service experiences a disruption, the system can switch to a backup model and reduce perceived interruptions. Third, the product can cover more languages, domains, and context-length requirements.

    Multi-model integration also brings engineering complexity. Different providers have different request formats, response fields, billing units, rate limits, and error codes. If business code calls each provider’s interface directly, adding a new model means modifying logic in many places. This article starts from that problem and discusses how a unified architecture can lower integration cost while keeping cost and stability under control.

    A Unified Access Layer: Isolate Differences with Adapters

    The core approach is to add a unified access layer between the business layer and model providers. Business code programs against an internal interface only; each provider’s differences are encapsulated in its own adapter.

    This layer usually contains three components:

    1. Unified request and response structure: Business code uses only internal message formats, generation parameters, and usage fields.
    2. Provider adapters: Each model has an adapter that converts an internal request into the provider protocol and normalizes the returned result.
    3. Model registry: Records model identifiers, capability tags, cost multipliers, operational status, and priority so the routing module can query them.

    The following example shows the basic shape of this structure.

    1. from dataclasses import dataclass
    2. from typing import Protocol
    3. @dataclass
    4. class ChatRequest:
    5. messages: list[dict]
    6. max_tokens: int = 1024
    7. temperature: float = 0.7
    8. @dataclass
    9. class ChatResponse:
    10. text: str
    11. input_tokens: int
    12. output_tokens: int
    13. model_id: str
    14. class ModelProvider(Protocol):
    15. name: str
    16. def chat(self, req: ChatRequest) -> ChatResponse:
    17. ...
    18. class VendorAdapter:
    19. """Map an internal request to a vendor-specific protocol and normalize the response."""
    20. def __init__(self, client, name: str, model_id: str):
    21. self.client = client
    22. self.name = name
    23. self.model_id = model_id
    24. def chat(self, req: ChatRequest) -> ChatResponse:
    25. raw = self.client.create(
    26. model=self.model_id,
    27. messages=req.messages,
    28. max_tokens=req.max_tokens,
    29. temperature=req.temperature,
    30. )
    31. # Field names follow each vendor's documentation; this shows the mapping pattern.
    32. return ChatResponse(
    33. text=raw["output"],
    34. input_tokens=raw["usage"]["prompt_tokens"],
    35. output_tokens=raw["usage"]["completion_tokens"],
    36. model_id=self.model_id,
    37. )

    This design keeps extension cost low. Adding a new model requires only implementing an adapter and adding an entry to the registry; business logic does not need to change.

    Common differences the adapter layer needs to handle include system prompt placement, the parameter name for maximum output length, return formats for streaming and non-streaming responses, data structures for tool calls, and the meaning of error codes. Concentrating these differences in the adapter layer prevents them from spreading into business code.

    Quota Metering: Normalize Different Model Costs into One Unit

    Model unit prices vary significantly. If users cannot directly see the consumption difference, they may choose high-cost models in situations that do not require them, causing quota to be consumed quickly. A reasonable approach is to define a unified base metering unit and assign a cost multiplier to each model.

    The calculation is:

    quota consumed = actual usage / 1000 × base unit price per 1,000 tokens × model cost multiplier

    Here, actual usage is the sum of input tokens and output tokens. The multiplier reflects the relative cost of the model, while the base unit price is set by product strategy. The following code demonstrates this calculation. The multipliers in the example are illustrative only and do not represent any real model pricing.

    1. COST_MULTIPLIER = {
    2. "lite-model": 0.4,
    3. "standard-model": 1.0,
    4. "advanced-model": 2.5,
    5. }
    6. def charge_quota(resp: ChatResponse, base_unit_per_1k: float = 1.0) -> float:
    7. multiplier = COST_MULTIPLIER[resp.model_id]
    8. total_tokens = resp.input_tokens + resp.output_tokens
    9. return total_tokens / 1000 * base_unit_per_1k * multiplier

    In implementation, keep the following metering design points in mind:

    • Show the multiplier in the UI. Users should see the consumption difference when they select a model, so they can make informed choices.
    • Settle by actual returned usage. At the start of a request, the system can pre-deduct quota based on the maximum output length. After the response is returned, settle according to actual usage and refund the difference.
    • Define clear rules for failed requests. Failures caused by timeouts or server errors should generally be fully refunded or not charged at all. These rules should be documented in the product documentation.