Token Cost Optimization for Office Agents: A Practical Guide

    This guide explains why token costs for office AI agents are driven by the execution framework rather than model pricing. It breaks down where tokens are spent, shows how harness design, task routing, output constraints, and observability reduce consumption, and outlines a practical rollout path for engineering teams.

    1. Why Office Agent Cost Is No Longer Decided by Unit Price

    The most common way to estimate the cost of an office agent is to look at the model’s price per thousand tokens. In real office workflows, that view breaks down quickly: for the same task and the same model, switching the execution framework can change token consumption by several times. Office work is mostly a compound flow of multiple steps, long context, and repeated reads and writes, so cost is determined by the execution path, not by unit price.

    A recently published set of data from a platform illustrates the point. In a test covering roughly fifty typical office tasks—investment research analysis, marketing growth, document writing, presentation generation, data processing, and application development—the average cost per task for the same model varied significantly across execution frameworks. The low-consumption tier stayed within a free-tier mechanism covering more than eighty percent of usage, while the high-consumption tier reached several yuan per task. Setting the specific product aside, the lesson for engineering teams is clear: the main battlefield for cost governance is the execution framework, not procurement negotiation.

    2. Breaking Down the Cost Model: Where Tokens Go

    Optimization starts with a computable cost model. Token spending for one office task can be abstracted as:

    1. total cost ≈ Σ(input tokens × input price) + Σ(output tokens × output price)
    2. input tokens ≈ system prompt + tool definitions + message history + retrieved chunks + current instruction
    3. output tokens ≈ reasoning + tool call arguments + final deliverable + repeated output from retries

    This yields four main sources of waste:

    1. Context redundancy: every turn re-injects the full history and all tool definitions, so input tokens grow linearly or even quadratically with the number of turns.
    2. Cache misses: an unstable prefix (timestamps, random IDs, or changing notes placed first) invalidates prefix caching and forces full recomputation of the input.
    3. Uncontrolled output: without length and format constraints, models tend to produce lengthy explanations, and output tokens often run more than twice the expected amount.
    4. Over-reasoning and ineffective retries: simple tasks are forced into multi-step planning, or an entire run restarts after a parameter validation failure, creating a loop where “more errors mean more cost.”

    3. Why the Execution Framework (Harness) Is the Cost Lever

    The execution framework is the engineering layer around the model: prompt assembly, context management, tool orchestration, caching strategy, failure recovery, and result validation. It determines what the model sees, how many steps it takes, and how long it writes. The same model capability produces completely different consumption curves under different frameworks. Key optimization points include:

    • Stable prefix design: keep invariant content (role definition, tool contracts, output specifications) at the very front of the context and push volatile content (time, session ID, user input) to the back to maximize prefix cache hit rate.
    • Layered context: retrieve and locate relevant parts of long documents before expanding locally instead of loading the whole document; compress conversation history with rolling summaries.
    • Lean tool contracts: expose only the tools and fields the current task needs, replacing long natural-language descriptions with enums and default values.
    • Budgeted orchestration: set token and step budgets per task, and degrade or converge once the budget is exceeded instead of continuing to reason.

    Illustrative budget control logic:

    1. class Budget:
    2. def __init__(self, max_steps=8, max_tokens=12000):
    3. self.max_steps = max_steps
    4. self.max_tokens = max_tokens
    5. self.used_tokens = 0
    6. def allow(self, step_tokens):
    7. return (self.used_tokens + step_tokens) <= self.max_tokens
    8. def run_task(task, model, budget=Budget()):
    9. plan = decompose(task) # task decomposition; simple tasks run in a single step
    10. for step in plan[: budget.max_steps]:
    11. prompt = assemble(step) # stable prefix + minimal necessary context
    12. if not budget.allow(estimate(prompt)):
    13. return degrade(task) # degrade: return a usable result instead of growing further
    14. out = model.call(prompt, max_output_tokens=1024)
    15. budget.used_tokens += estimate(prompt) + len(out)
    16. if validate(out):
    17. return out
    18. return fallback(task)

    4. Task Tiering: Reserve Expensive Models for What Actually Needs Them

    Not every office task requires strong reasoning. A three-tier routing scheme works well:

    Tier Task characteristics Recommended strategy
    L1 lightweight rewriting, summarization, format conversion, field extraction low-consumption model + strict output length cap
    L2 standard document drafting, spreadsheet processing, script generation mid-tier model + one validation retry
    L3 complex cross-source investment research, long-chain data analysis high-capability model + stepwise budget control

    Routing decisions should rely on quantifiable signals—input length, whether external data is needed, and the number of past failures—rather than subjective assignment. In practice, if L1 and L2 cover more than eighty percent of request volume, average overall cost typically drops by an order of magnitude.

    5. Prompt and Output Constraints: The Cheapest Optimization

    • Specify the delivery format: require results in a structured format such as a table or key-value structure to cut explanatory filler.
    • Cap the length: set a word or item limit and require no repetition when there is no added information.
    • Get it right in one pass: write validation rules into the prompt (required fields, consistent units, placeholders for anomalies) to minimize rework.
    • Remove persona overhead: delete pleasantries, disclaimers, and other tokens that carry no information.
    1. Task: extract fields from the text below and output them as a key-value structure.
    2. Constraints: output only the result, no explanation; fill missing fields with null; total length under 200 words.

    6. Observability: No Measurement, No Optimization

    Cost governance has to be built on data. Collect the following metrics and track trends through logging services and monitoring alerts:

    • token distribution per task (P50/P95), not just the mean;
    • prefix cache hit rate, average number of turns, and tool call count;
    • retry rate and the distribution of validation failure reasons;
    • cost per task = total credits consumed ÷ number of tasks successfully delivered.

    When P95 diverges sharply from the mean, a few long-chain tasks are usually draining the budget and should be the first candidates for process trimming.

    7. Rollout Path and Common Pitfalls

    A four-step path is recommended: establish baseline measurement first, then apply prefix stabilization and context layering, then roll out task-tier routing, and finally introduce budgets and degradation. Three pitfalls are common: switching to a stronger model blindly, which can raise cost; keeping the full history at all times, which inflates input; and looking only at average cost while ignoring the extreme consumption of long-tail tasks.

    8. Conclusion

    Competition on office agent cost is fundamentally competition on execution framework engineering. By treating cache hit rate, output length, and reasoning depth as design constraints, and combining them with task tiering and observability, teams can compress most routine tasks into a very low or even free consumption range without sacrificing delivery quality. This methodology is vendor-agnostic and reusable by any office agent built on general-purpose model services.