Multi-Model Office Agent Architecture: Design and Engineering Practice
The article discusses engineering design for multi-model office AI agents, covering heterogeneous model access, unified adapters, model capability profiles, routing and fallback, task orchestration, context management, tool safety, data compliance, and quality and cost evaluation. It presents an architecture-level view of how to select and operate multiple models for office tasks while keeping business logic independent of specific model providers.
1. Background and Problem
AI Agents in office scenarios need to handle a wide range of tasks, including document drafting, spreadsheet analysis, meeting-minutes summarization, and email drafting. These tasks place very different requirements on models. Some tasks emphasize response speed, such as instant Q&A and text polishing. Some tasks depend on long context, such as organizing contracts or reports that run to hundreds of pages. Other tasks require stable structured output, such as extracting action items and owners from meeting transcripts.
A single model can hardly be optimal across all dimensions at the same time. As a result, more and more office products adopt a multi-model strategy: some capabilities are handled by in-house models, while others are connected to external models, and the system selects the appropriate executor based on task characteristics.
This article discusses the design of this architecture from an engineering perspective, covering the model access layer, routing strategy, task orchestration, quality evaluation, and cost control. The examples in this article are generic design sketches and do not correspond to the interfaces of any specific product.
2. Core Challenges of Multi-Model Access
2.1 Heterogeneous Interfaces and Protocols
Different model services vary in request formats, authentication methods, streaming output protocols, and error code definitions. If business code directly depends on the field names of a specific service, later replacement or addition of models will require changes that spread across the entire business layer.
2.2 Inconsistent Capability Boundaries
Models differ in context window length, tool-calling format, JSON output stability, multilingual capability, and other aspects. The same prompt may produce noticeably different results on two models, so it cannot be assumed that models are interchangeable without difference.
2.3 Fluctuations in Cost and Latency
Model calls are usually billed by token or by request, and both unit price and latency may change with load. In long tasks, using the most capable model at every step can quickly drive up cost.
2.4 Availability and Compliance
External services may experience rate limiting, timeouts, or temporary unavailability. When enterprise data is involved, it is also necessary to clarify which content is allowed to be sent to which services.
3. Overall Architecture Design
It is recommended to split the system into five layers:
- Access layer: receives user requests, completes identity verification, and checks quotas.
- Task understanding layer: identifies task type, complexity, and data sensitivity level.
- Routing and scheduling layer: selects models according to policy and handles fallback.
- Model adaptation layer: converts internal unified requests into the native protocols of each model.
- Observability and evaluation layer: records call logs, quality metrics, and cost data.
The layers communicate through unified internal data structures, and business logic is unaware of specific models.
3.1 Unified Model Interface
The core of the model adaptation layer is a unified interface. Each external model implements an adapter, as shown below:
from abc import ABC, abstractmethodfrom dataclasses import dataclass@dataclassclass ChatRequest:messages: list[dict] # Unified message structure with role and contentmax_tokens: int = 1024temperature: float = 0.2tools: list[dict] | None = None@dataclassclass ChatResponse:text: strinput_tokens: intoutput_tokens: intlatency_ms: intmodel_id: strclass ModelAdapter(ABC):model_id: str@abstractmethoddef chat(self, req: ChatRequest) -> ChatResponse:"""Convert a unified request into the protocol of a specific model and return a unified response."""...
The adapter is only responsible for protocol conversion, error code mapping, and timeout control. The business layer only calls chat and does not care about the field names of the underlying service.
3.2 Model Capability Profiles
Maintain a capability profile for each model, including context length limit, whether tool calling is supported, stability of structured output, unit cost, and recent average latency. Profile data should come from internal evaluation results and be updated regularly to avoid relying on outdated judgments for a long time.
4. Routing Strategy Design
Routing is the decision-making core of a multi-model system. There are three common types of strategies.
4.1 Routing by Task Type
Divide tasks into several categories, such as polishing, summarization, long-document analysis, structured extraction, and code generation, and bind each category to a recommended model. This approach is direct and has low maintenance cost, making it suitable for the early stage.
4.2 Routing Under Cost and Latency Constraints
Set latency ceilings for interactive tasks and cost ceilings for batch tasks. The scheduler first filters candidate models that satisfy the constraints, then ranks them by quality score and selects the executor.
4.3 Failure Fallback and Circuit Breaking
When a model repeatedly times out or its error rate exceeds a threshold, the system should automatically switch traffic to a fallback model. After an interval, it should probe recovery with a small amount of traffic, and gradually switch back after stability is confirmed.
Below is a simplified routing example to illustrate the idea:
ROUTING_POLICY = {"polish": {"primary": "model_fast", "fallback": "model_general"},"long_doc": {"primary": "model_long", "fallback": "model_general"},"extract_json": {"primary": "model_struct", "fallback": "model_general"},"codegen": {"primary": "model_code", "fallback": "model_general"},}DEFAULT_POLICY = {"primary": "model_general", "fallback": "model_general"}def select_model(task_type: str, unhealthy: set[str]) -> str:policy = ROUTING_POLICY.get(task_type, DEFAULT_POLICY)if policy["primary"] not in unhealthy:return policy["primary"]return policy["fallback"]
The model identifiers in the example are placeholders. In actual deployment, they should be replaced with internally registered model IDs. Health status is usually calculated from real-time metrics in the observability layer.
5. Agent Task Execution Flow
Office Agents usually cannot complete a task with a single call. Instead, they proceed through a loop of “understand the goal, decompose steps, execute, validate, and deliver.”
- Goal parsing: convert the user’s natural-language goal into a structured task description, clarifying input materials, output format, and acceptance criteria.
- Plan generation: split the goal into several subtasks and mark their dependencies.
- Step-by-step execution: each subtask calls the corresponding model or tool, and the result is written into the task context.
- Result validation: use rules or independent checking logic to determine whether the output meets the acceptance criteria; if not, retry or roll back.
- Delivery preparation: merge intermediate results into the final document, spreadsheet, or message, with sources and modification records attached.
5.1 Context Management
The context of multi-step tasks grows quickly. A common practice is to keep the full content of the most recent turns, save summaries for earlier steps, and store key facts in structured state for reference by later steps. This controls input length and reduces repeated billing.
5.2 Security Boundaries for Tool Calls
Tools called by an Agent may read or write files, send messages, or query logs. Each tool should declare its permission scope, validate parameters before execution, and require user confirmation for irreversible operations such as deletion, sending, and publishing. Tool return content should also be treated as data rather than instructions, to avoid being misled by injected content.
6. Data Security and Compliance
A multi-model architecture expands the scope of data flows, so rules need to be clarified at the design stage.
- Data classification: classify documents and fields into public, internal, and sensitive levels, with different levels allowed to flow to different model scopes.
- Data masking: before sending data to external services, replace or mask fields such as phone numbers, ID card numbers, and bank card numbers.
- Key management: access credentials for each model are stored in a key management service, and plaintext is not kept in code or logs.
- Audit trails: record the model ID, data level, request time, and initiator of each call for later tracing.
7. Quality Evaluation and Cost Control
7.1 Offline Evaluation
Build a fixed evaluation set for each task type, including input samples and human-labeled reference answers or scoring criteria. Whenever a model is changed or a prompt is adjusted, first compare accuracy, format compliance rate, and average duration on the evaluation set before deciding whether to roll out.
7.2 Online Metrics
It is recommended to continuously monitor the following metric:
- Task completion rate: the proportion of tasks that the Agent completes without human intervention.
