Multi-Model Access for Office AI Agents: Model Selection and Cost Calculation

    This article explains why office AI agents need multiple models and how to design multi-model access from an engineering perspective. It covers task tiering, a unified access layer, routing and fallback, quota multiplier cost calculation, and time-based scheduling. It also includes a code skeleton and checklists. All prices, multipliers, and timeout values are examples. Actual values should come from your platform's billing documentation and your own load testing.

    Why Office AI Agents Need Multiple Models

    Office tasks vary widely. Organizing the notes from one meeting only requires quickly pulling out the key points. A cross-department budget analysis may require a model to read long documents, verify numbers, and produce complete reasoning. The two kinds of tasks differ in how much they depend on model capability, response time, and cost.

    If an office AI agent connects to only one model, it usually runs into three problems:

    • Overqualified: Simple tasks still use a high-tier model, so each call costs more than it needs to.
    • Underqualified: Complex tasks have omissions or gaps in reasoning, and people must redo the work.
    • Single point of failure: When the model service becomes unstable, the entire office workflow stops.

    A multi-model setup matches each type of task to a suitable model and keeps the service running when errors occur. Three foundations make this possible:

    1. Unified access layer: Business code calls one internal interface and does not depend directly on each provider’s SDK or parameter format.
    2. Model profiles: For each model, record its capability level, typical latency, unit price, quota multiplier, and availability. Profile data can be updated.
    3. Routing rules: Based on task tier, deadline, and budget, decide the preferred model, backup models, and degradation conditions. Rules should be explainable, so every routing result can be traced to specific conditions.

    Break Down Task Requirements First: Quality, Latency, and Cost

    Before selecting models, the team needs to split requirements into measurable dimensions.

    Quality determines whether a model can deliver results directly. Stability in complex reasoning, long-context understanding, and structured output all fall under quality. The team should measure accuracy and completeness with a manually labeled evaluation set rather than relying on subjective impressions. The evaluation set should cover real business samples, with at least several dozen examples per task type, and the labeling standards should be documented.

    Latency falls into two categories. Interactive scenarios focus on time to first token and total completion time, because users become less satisfied the longer they wait. Background batch tasks focus on throughput and tolerate higher latency for individual calls. The two types of tasks should use different timeout thresholds and concurrency strategies.

    Cost includes the fee for each call and the cost of rework. A cheap model that needs repeated manual corrections may not have a lower total cost. The cost calculation should therefore include model fees, retry fees, and manual review time.

    Based on these dimensions, tasks can first be divided into three tiers:

    Tier Typical tasks Quality requirement Latency requirement Suggested model tier
    Simple Meeting highlight extraction, format conversion, short-text polishing Basically accurate is enough Interactive, fast first token Lightweight model
    Medium Email drafting, spreadsheet data organization, single-document summarization Complete structure, few omissions Interactive, a few seconds acceptable Standard model
    Complex Cross-document analysis, budget verification, multi-step reasoning Reliable reasoning, verifiable numbers Can be asynchronous, minute-level delays acceptable High-tier model

    The tiers in this table should be validated with the evaluation set. The team can first run a representative task from each tier, record accuracy, latency, and cost, and then decide the default mapping.

    Designing the Unified Access Layer

    The unified access layer is the foundation of a multi-model design. It has four responsibilities: hiding differences between provider interfaces, standardizing request and response structures, managing keys and quotas centrally, and logging each call with its metrics.

    When implementing it, keep these points in mind:

    • Expose only one function or one HTTP interface to callers. Its inputs include the task tier, prompt, expected output format, and time limit.
    • Internally, write an adapter for each model that converts the provider’s parameter names, message formats, and error codes into a unified internal structure.
    • Read keys from environment variables or a key management service. Never write them into code, configuration files, or logs.
    • Log the model name, tier, latency, input and output token counts, whether a retry occurred, and whether a fallback occurred. Do not log full sensitive document content.

    Routing and Fallback

    Routing rules decide which model receives a request first. Fallback rules decide what the system does when the preferred model fails.

    An executable rule set usually includes these parameters:

    • Timeout threshold: Interactive tasks can use 10 to 20 seconds, and batch tasks can use 60 seconds or more. The exact values should be based on load test data.
    • Retry count: Retry timeouts and 5xx errors one or two times with exponential backoff. Do not retry 4xx errors. Return the error reason directly.
    • Circuit breaker: If a model’s failure rate exceeds the threshold over a recent period, stop sending it new requests. After a while, probe its recovery with a small amount of traffic.
    • Fallback model: Configure one backup model for each tier. A backup model may perform worse than the preferred model, so fallback results should be marked in the interface or in the result metadata.
    • Manual fallback: If all models fail, send the task to a manual queue and notify the owner.

    The fallback checklist is as follows:

    1. Does every tier have at least one backup model?
    2. Is the total time spent on timeouts and retries still within what users can accept?
    3. Are fallback results labeled, so they are not published directly as if they came from the preferred model?
    4. Does circuit breaker recovery use probe traffic, instead of switching all traffic back at once?
    5. Are alerts sent to a channel the owner can see?

    Quota Multiplier Cost Calculation

    Models may consume platform quota in different ways. Some platforms charge by token. Others set a quota multiplier for each model, so the same call may consume several times more quota on a high-tier model than on a lightweight one. The calculation must define every variable in the formula.

    A common estimation formula is:

    Quota consumed by this call = (input tokens ÷ 1000 × input price + output tokens ÷ 1000 × output price) × quota multiplier × time-of-day coefficient

    The variables and their sources are:

    • Input price and output price: Use the provider’s current billing documentation, and record the date you checked it.
    • Quota multiplier: Use the platform’s rules. Some platforms adjust multipliers during promotions.
    • Time-of-day coefficient: If the platform gives discounts or surcharges at certain times, enter the actual rule. If there is none, use 1.
    • Input and output token counts: Use the usage fields returned by the API. Do not replace them with rough word counts.

    Keep these conditions in mind during calculation:

    • Cache hits, batch interfaces, and streaming output may be billed differently, so the formula needs separate handling for each.
    • Retries and fallback calls also consume quota. Report them separately in cost reports.
    • During peak concurrency, quota may run out before the budget does, so set daily and per-user quota limits.

    The following example uses assumed numbers to show the method. It does not reflect any real platform’s prices. Assume a lightweight model with an input price of CNY 0.001 per 1,000 tokens, an output price of CNY 0.002 per 1,000 tokens, a multiplier of 1, and a task using 2,000 input tokens and 500 output tokens, with a time-of-day coefficient of 1:

    (2000 ÷ 1000 × 0.001 + 500 ÷ 1000 × 0.002) × 1 × 1 = CNY 0.003

    If the same task goes to a high-tier model with a multiplier of 3, and its unit price is assumed to be five times the figures above, the result is 0.003 × 5 × 3 = CNY 0.045. This number only shows how multipliers and unit prices compound. It does not represent the price on any real platform.

    Time-Based Scheduling

    Time-based scheduling uses differences in load and billing across the day to plan when non-interactive tasks run. Common practices include:

    • Run batch tasks during off-peak hours, such as generating daily reports overnight or organizing documents on a schedule.
    • Set concurrency limits for batch jobs so they do not exhaust the quota and slow down daytime interactive tasks.
    • On platforms with time-based discounts, concentrate deferrable tasks in discounted periods. Confirm the scope in which the discount applies.
    • Keep a separate channel for urgent tasks so they do not wait in the queue.

    Before scheduling, confirm two things: whether the task’s deadline allows a delay, and whether someone is waiting for the result. Only tasks that can be delayed belong in an off-peak queue.

    Monitoring and Cost Definitions

    Without monitoring, a multi-model setup cannot be improved over time. Track at least the following metrics:

    • Request volume, success rate, and P50 and P95 latency, grouped by tier and model.
    • Token usage, quota consumption, and average cost per task, grouped by model.
    • Fallback rate and circuit breaker trips. A sudden rise in these numbers calls for investigating provider or network problems.
    • Manual rework rate, which shows whether a low-cost model actually reduces total cost.

    The team should use one consistent definition of cost. We recommend defining cost as model fees plus retry fees plus the estimated cost of manual review, and showing these three items separately. Comparing only unit prices can lead to misleading conclusions.

    Sample Code

    The following code is a skeleton for routing and fallback. It omits the real network calls. The caller must pass an invoke function that connects to the specific provider. Model names are placeholders, so replace them with the real names from your platform.

    1. import os
    2. import time
    3. # Read the key from an environment variable. Do not write it into code or logs.
    4. API_KEY = os.environ.get("LLM_API_KEY")
    5. if not API_KEY:
    6. raise RuntimeError("Missing environment variable LLM_API_KEY")
    7. # Model configuration: names are placeholders. Adjust timeouts and retries based on load test results.
    8. MODELS = {
    9. "model-large": {"timeout": 60, "retries": 1},
    10. "model-small": {"timeout": 15, "retries": 2},
    11. }
    12. # Preferred model order for each task tier
    13. FALLBACK_ORDER = {
    14. "complex": ["model-large", "model-small"],
    15. "simple": ["model-small", "model-large"],
    16. "medium": ["model-large", "model-small"],
    17. }
    18. def route(task_tier, prompt, invoke):
    19. """Select a model by tier, fall back in order on failure, and raise an exception to send the task to manual review if all models fail."""
    20. if task_tier not in FALLBACK_ORDER:
    21. raise ValueError(f"Unknown task tier: {task_tier}")
    22. last_error = None
    23. for model_name in FALLBACK_ORDER[task_tier]:
    24. cfg = MODELS[model_name]
    25. for attempt in range(cfg["retries"] + 1):
    26. try:
    27. result = invoke(model_name, prompt, timeout=cfg["timeout"], api_key=API_KEY)
    28. return {"model": model_name, "degraded": model_name != FALLBACK_ORDER[task_tier][0], "output": result}
    29. except TimeoutError as e:
    30. last_error = e
    31. time.sleep(min(2 ** attempt, 8))
    32. except Exception as e:
    33. # Retrying a 4xx error is pointless, so move to the next model.
    34. last_error = e
    35. break
    36. raise RuntimeError("All models failed; task moved to the manual queue") from last_error

    The degraded field marks fallback results. The business layer should use it to tell users that a result came from a backup model. The error handling only separates timeouts from other exceptions. A real project needs to handle each provider’s error codes separately and include circuit breaker status in its decisions.

    Common Mistakes and Troubleshooting Checklist

    Common mistakes include:

    • Writing keys into code or logs, which can expose them. Check repository history and log output.
    • Setting timeouts too long, so users wait without feedback. Show progress indicators for interactive tasks.
    • Failing to label fallback results, so they are published as if they came from the preferred model.
    • Choosing models by unit price alone and ignoring rework costs, which can raise total cost.
    • Retrying without backoff, which amplifies traffic during a provider outage and speeds up quota exhaustion.

    When troubleshooting, check the following in order:

    1. Review the model name, error code, and latency in the logs to tell whether the problem is on the provider side or in the local system.
    2. Confirm that environment variables are set correctly in the runtime environment and that the key is valid and has sufficient permissions.
    3. Compare fallback rates over the past week to see whether a particular model has been consistently failing.
    4. Check quota usage against the billing documentation to confirm that no unexpected high-multiplier model was called.
    5. Sample fallback results to confirm that the fallback did not drop critical information.

    Conclusion and Ongoing Iteration

    The value of multi-model access is that each type of task gets a suitable model, and the service keeps running when errors occur. A team can start with three steps: define task tiers and an evaluation set, implement the unified access layer with basic fallback, and record the usage and latency of every call.

    Later iterations should focus on a few metrics: accuracy by tier, total cost per task, fallback rate, and manual rework rate. Model profiles should be updated regularly, since providers’ prices, multipliers, and performance can change. After each change, rerun the evaluation set before deciding whether to adjust the default mapping.