Multi-Model Integration in Practice: Building a Unified Office AI Platform

    This article explains how to build a unified office AI platform that connects multiple LLM services behind a single gateway. It covers a layered architecture, protocol normalization with adapters, task-based routing, prompt and structured-output governance, and cost observability, showing how to treat cost per task as a first-class design metric.

    1. Background: Fragmented Office Workflows and Rising Costs

    Real office work rarely involves a single type of request. Writing a weekly report requires structured summarization, reading long documents requires long-context understanding, processing spreadsheets requires structured output, meeting notes require speech transcription and key-point extraction, and writing code snippets requires stronger reasoning. No single model stays best at every dimension, so teams often integrate multiple model services. That creates new problems: scattered entry points, different authentication schemes, inconsistent parameter naming, and mismatched billing metrics, with costs piling up unnoticed.

    A key signal from the source material is that the call multiplier for some lightweight models was reduced. For heavy users, such an adjustment may look minor, but scaled by daily call volume, the savings are substantial. This points to an engineering principle: model selection should not focus only on single-call quality, but should include “cost per task” as a first-class metric in the architecture.

    2. Target Architecture: One Platform, Three Model Tiers, One Entry Point

    A layered architecture is recommended to decouple “capabilities” from “implementations”:

    • Access layer: a unified gateway handling authentication, rate limiting, auditing, and metering.
    • Routing layer: selects models by task type, context length, and latency budget.
    • Capability layer: three model tiers with clear roles—lightweight and fast, general and balanced, and deep reasoning.
    • Governance layer: prompt version management, evaluation sets, canary releases, and rollback.
    • Observability layer: logging service, monitoring and alerting, and a cost dashboard.

    The core of the unified gateway is “protocol normalization.” Request field names vary widely across providers. Define an internal abstraction in the gateway, then write adapters to convert:

    1. # Example: unified abstraction and adapters
    2. from dataclasses import dataclass
    3. from typing import List, Dict, Any
    4. @dataclass
    5. class ChatRequest:
    6. messages: List[Dict[str, str]]
    7. temperature: float = 0.3
    8. max_tokens: int = 1024
    9. task_type: str = "general" # summary / code / reasoning / chat
    10. class Adapter:
    11. def to_provider_payload(self, req: ChatRequest) -> Dict[str, Any]:
    12. raise NotImplementedError
    13. def from_provider_response(self, raw: Dict[str, Any]) -> str:
    14. raise NotImplementedError
    15. class Router:
    16. def __init__(self, adapters: Dict[str, Adapter]):
    17. self.adapters = adapters
    18. def pick(self, req: ChatRequest) -> str:
    19. if req.task_type == "summary":
    20. return "light" # lightweight and fast
    21. if req.task_type == "reasoning":
    22. return "deep" # deep reasoning
    23. return "balanced" # general and balanced
    24. def chat(self, req: ChatRequest) -> str:
    25. key = self.pick(req)
    26. payload = self.adapters[key].to_provider_payload(req)
    27. raw = self.adapters[key].call(payload) # implementation omitted
    28. return self.adapters[key].from_provider_response(raw)

    3. Routing Strategy: Turning Multipliers into Scheduling Rules

    The key to cost optimization is not negotiating lower prices, but routing more traffic to cheaper capabilities. Practical rules include:

    1. Task tiering: summaries, rewrites, classification, and extraction go to lightweight models; complex reasoning and long-chain code go to deep models.
    2. Context budget: split and pre-summarize very long text before sending it to the model, avoiding payment for redundant context.
    3. Cache first: build a semantic cache for frequent repeated questions; a cache hit returns immediately and effectively reduces cost to zero.
    4. Fallback path: automatically switch to a backup model when the primary model times out or is rate-limited, ensuring availability.
    5. Batching and async: merge requests for non-real-time tasks and use an async queue to smooth peaks.

    An example policy configuration:

    1. routing:
    2. summary: { model: light, max_tokens: 512, cache: true }
    3. chat: { model: balanced, max_tokens: 1024, cache: true }
    4. reasoning: { model: deep, max_tokens: 2048, cache: false }
    5. fallback:
    6. - balanced
    7. - light

    4. Prompt and Output Governance: Consistency Matters More Than the “Strongest Model”

    The biggest risk of running multiple models in parallel is output style drift. Treat prompts as code: separate templates from variables, store version numbers, and require review for changes. Maintain a small evaluation set for each task (a few dozen cases is enough), run regression tests when models or prompts change, and make decisions based on pass rates rather than subjective impressions.

    For structured output, use a three-step approach of “constraint + validation + retry”: first require a strict format, then validate against a schema, and retry once with the error message if validation fails.

    1. import json, re
    2. def strict_json(text: str, schema_keys: list) -> dict:
    3. m = re.search(r"\{.*\}", text, re.S)
    4. if not m:
    5. raise ValueError("no json found")
    6. obj = json.loads(m.group(0))
    7. missing = [k for k in schema_keys if k not in obj]
    8. if missing:
    9. raise ValueError(f"missing keys: {missing}")
    10. return obj

    5. Cost Observability: Making Every Dollar Attributable

    Without metering, there is no optimization. Add instrumentation at the gateway to record task type, model tier, input and output tokens, latency, and cache hit status, and send it to a logging service. Then set cost-per-task thresholds on monitoring and alerting. A sudden cost spike in weekly-report tasks often means prompt bloat or cache invalidation, not simply “more usage.”

    A simple cost estimation formula:

    1. Daily cost ≈ Σ(task volume_i × average tokens_i × unit price_i × (1 - cache hit rate_i))

    Modeling a change like a multiplier reduction as a drop in unit price_i makes the benefit visible: the larger the call volume and the lower the cache hit rate, the more significant the absolute savings from a price cut.

    6. Engineering Implementation Checklist

    • Deploy the unified gateway first; prohibit business code from calling any model API directly.
    • Maintain a model inventory with owners, and define the applicable boundaries of each tier.
    • Store prompts and evaluation sets in version control so changes can be rolled back.
    • Provide end-to-end timeout, retry, circuit breaking, and fallback plans.
    • Allocate the cost dashboard by team and scenario, and review routing rules monthly.
    • Data compliance: redact sensitive content before it leaves the gateway, and minimize data retention.

    7. Conclusion

    The essence of “one platform for all office tasks” is not piling features together, but using a unified entry point, intelligent routing, and strict governance to turn multi-model capabilities into measurable, schedulable, and replaceable infrastructure. When the unit price of lightweight models drops, a more decoupled architecture yields more direct benefits; when a provider needs to be replaced someday, only an adapter needs to change.