Token Cost Optimization for Office Agents: A Practical Guide

    This guide explains why office AI agents with the same model and tasks can have vastly different token costs, and how engineering decisions in the execution harness drive that gap. It covers the four main sources of cost variance, a measurable metrics framework, five harness optimization techniques, a method for designing task tiers and free quotas, a reproducible A/B testing approach, and common anti-patterns to avoid. Readers will learn how to build metrics first, run single-variable experiments, and standardize practices to bring most daily tasks into a zero-cost range.

    1. Background: The Cost Structure of Office Agents and Common Optimization Pitfalls

    Over the past year, office agents have evolved from “being able to chat” to “being able to deliver.” Task shapes have expanded from single-turn Q&A to long-chain, multi-step execution: reading documents, fetching data, generating charts, producing presentations, and running scripts. Longer tasks directly drive up both token consumption and the number of calls, turning the cost curve from “negligible” into something that “needs governance.”

    Many teams’ first instinct is to switch to a smaller model. Yet practice often reveals a counterintuitive phenomenon: with the model and task held identical, actual consumption across different agent applications can differ by several times. This shows that cost is not determined by model unit price alone; the real variable is the engineering quality of the execution framework (harness).

    Three common pitfalls:

    • Focusing only on unit price, not total cost per task. A low unit price combined with repeated retries and repeated context transmission can lead to higher total cost.
    • Focusing only on averages, not distributions. A small number of long-tail tasks contribute most of the consumption, and averages hide the long tail.
    • Treating free quotas as a marketing tactic rather than a designable cost mechanism. If the free tier does not match the real task distribution, both user experience and cost goals will fail simultaneously.

    2. Four Real Sources of Cost Variance

    With the model and task held constant, consumption differences are mainly determined by the following four factors, almost all of which fall on the engineering side rather than the model side.

    1) Cache hit ratio. Every round, an agent must resend the system prompt, tool descriptions, and historical context to the model. If the prefix is stable and reusable, it can hit the cache and only the incremental portion is billed. Conversely, timestamps, random IDs, and dynamic sorting invalidate the prefix and drive the hit rate toward zero.

    2) Output length. Chain-of-thought reasoning, verbose intermediate conclusions, and repeated summary paragraphs all linearly amplify output-side consumption, and output is usually more “expensive” than input.

    3) Over-reasoning. Routing simple tasks to a strong reasoning mode is the most typical waste. Tasks like classification, extraction, and formatting do not need long-chain reasoning.

    4) Retries and rollbacks. Tool call failures, structured output validation failures, and timeout reruns all cause the same task to be billed multiple times.

    3. A Quantifiable Metrics System

    To govern cost, you first need to measure it. It is recommended to establish at least the following metrics and bucket them by task type:

    • Average consumption per task (in both currency and tokens)
    • Free mechanism trigger rate (what proportion of tasks fall into the low-consumption free tier)
    • Cache hit rate and prefix stability
    • Average output token ratio (output / total tokens)
    • Ineffective retry rate and tool call success rate
    • Task tiering accuracy (the proportion of simple tasks misrouted to high-cost modes)

    Among these, the “free mechanism trigger rate” is the metric closest to the user experience: it directly determines whether “daily office work really costs nothing.” Industry practice shows that when the multiplier is lowered and free access is opened for low-consumption tasks, free coverage for daily high-frequency tasks can reach over 80%, and average cost per task drops to the sub-cent level.

    4. Five Levers for Harness Optimization

    1) Prefix solidification and cache-friendly design. Place stable system prompts, tool lists, and output specifications at the front, and dynamic content at the back; avoid inserting timestamps and random values into prompts.

    1. [Stable prefix] Role definition + tool descriptions + output format constraints + safety policy
    2. [Semi-stable section] User preferences, common templates
    3. [Volatile section] Current time, session context, retrieved snippets

    2) Model tiered routing. Use a lightweight model for high-frequency simple tasks, and upgrade only when complex planning is needed.

    1. def route(task):
    2. if task.type in ("classify", "extract", "format", "summarize_short"):
    3. return "light_model", {"reasoning": "off", "max_output": 800}
    4. if task.steps > 5 or task.needs_code:
    5. return "strong_model", {"reasoning": "medium", "max_output": 4000}
    6. return "mid_model", {"reasoning": "low", "max_output": 2000}

    3) Hard output length constraints. Set output limits and structured templates for each task type. Constraining before generation is more economical than trimming afterward.

    4) Idempotency and resumable execution. Set an idempotency key for each step so that a failure reruns only the failed step, not the entire chain.

    1. def run_step(step, ctx):
    2. key = f"{ctx.task_id}:{step.id}"
    3. if cache.exists(key):
    4. return cache.get(key)
    5. result = call_model(step, ctx)
    6. cache.set(key, result, ttl=3600)
    7. return result

    5) Front-loaded structured output validation. Use schema validation instead of “generate first, review manually later” to reduce full-round reruns caused by non-compliant formatting.

    5. Designing Task Tiers and Free Quotas

    The free mechanism is not about “giving away quota”; it is about aligning the cost distribution with the user’s real usage distribution. A practical approach has three steps:

    • Task profiling: Count the types and average input/output sizes of high-frequency tasks to form a distribution histogram.
    • Threshold calibration: Set the free threshold near the upper quartile of high-frequency task consumption, so that the vast majority of daily tasks naturally fall into the free zone.
    • Quota pacing: Distribute small amounts of quota through daily check-ins and continuous-usage rewards, keeping light users at zero cost over the long term while heavy users pay smoothly.

    The supporting engineering requirement is that the “consumption multiplier,” a billing coefficient, must be adjustable: set different multipliers for different task tiers under the same model,压 low-consumption tasks to an extremely low multiplier, making it commercially equivalent to free while retaining a measurable cost basis.

    6. Validation: A Reproducible Cost Experiment

    It is recommended to run an A/B comparison on a fixed task set covering categories such as document writing, data processing, presentation generation, information extraction, and script development, with no fewer than ten examples per category, recording:

    1. Task category | Free trigger rate | Avg consumption | Cache hit rate | Output ratio | Retry rate
    2. Doc writing | 92% | 0.05 CNY | 78% | 31% | 3%
    3. Data process. | 89% | 0.07 CNY | 81% | 26% | 4%

    Change only one variable per comparison (for example, enabling prefix solidification only) to quantify the benefit each lever brings, avoiding the situation where “everything was optimized but you cannot tell which step made the difference.”

    7. Common Anti-Patterns

    • Placing a dynamic timestamp at the very front of the prompt, invalidating the entire cache.
    • Using the strongest reasoning tier uniformly for all tasks.
    • Rerunning the entire chain after a failure, lacking idempotency design.
    • Setting the free threshold arbitrarily, disconnected from the actual consumption distribution.
    • Tracking only averages without monitoring long-tail tasks.

    8. Conclusion

    The cost competitiveness of office agents is essentially the engineering ability to convert “model capability” into “cost per task.” When the five capabilities of cache hits, output constraints, tiered routing, idempotent retries, and adjustable multipliers are stacked together, bringing over 80% of daily tasks into the free tier is not a marketing slogan but a measurable and reproducible engineering result. For developers, the most reliable path to cost governance is to build metrics first, then run single-variable experiments, and finally solidify standards.