Reducing Token Costs for Office AI Agents: Practical Harness Optimization

    As office AI agents move into real business use, the question has shifted from "can we build this?" to "how do we run it reliably at low cost?" This article explains why token consumption varies widely between agents that use the same model, and shows that the difference usually comes not from the model itself but from the agent execution framework, or Agent Harness. It covers the main sources of token cost, why the Harness drives cost, and a practical engineering checklist covering cost measurement, prompt caching, context compression, output constraints, model routing, and a go-live verification process.

    $As office AI agents move into real business scenarios, the question companies care about has shifted from “can we build this?” to “how do we run it reliably at low cost.” When two agents use the same large language model, their token consumption can differ substantially. The cause is usually not the model itself, but the agent execution framework, known as the Agent Harness. The Harness handles task decomposition, context management, tool calling, failure retries, and model scheduling, and it determines how many tokens a given task actually consumes. This article focuses on reducing costs for office AI agents and lays out the technical logic and a practical engineering checklist you can apply.

    1. Why Are Agent Token Costs High?

    The cost of an office AI agent is generally made up of both input tokens and output tokens. Different providers bill differently for input, caching, output, and long contexts, so before optimizing anything, you should establish a baseline. The main cost sources are cache hit rate, output length, and over-reasoning.

    1.1 Cache Hit Rate

    System prompts, tool definitions, and conversation history often account for a large share of the input. If the same prefix is recomputed on every request, costs climb. Prompt Caching reduces repeated computation by reusing the KV Cache of a stable prefix. When the cache is hit and the provider’s billing rules allow it, a repeated prefix can usually be billed at a significantly reduced rate; the actual effect depends on cache lifetime, the minimum prefix length, the billing model, and the request interval.

    The key to a higher hit rate is keeping the prefix stable. Timestamps, random session IDs, and dynamic user information should be moved to the end of the prompt to avoid polluting the stable prefix.

    1. # Bad example: dynamic content enters the prefix, so the cache is easily invalidated
    2. prompt = f"Current time: {datetime.now()} Session ID: {uuid4()} You are an office assistant. Answer: {user_input}"
    3. # Good example: stable system prefix + trailing dynamic variables
    4. SYSTEM_PREFIX = "You are an office assistant. Answer concisely: state the conclusion first, then add any necessary detail."
    5. prompt = SYSTEM_PREFIX + f"\nUser question: {user_input}"

    1.2 Controlling Output Length

    Output tokens are usually weighted more heavily in billing, and long output also increases latency. Much of this cost comes from “overly verbose generation,” where content that could be answered in one sentence is expanded into a long explanation. Ways to optimize include setting a word limit, requiring the conclusion first and details after, using fixed fields and a JSON Schema, and forbidding repetitive explanations. In batch processing and high-frequency Q&A scenarios, the cumulative gains from controlling output length are significant.

    1.3 How to Avoid Over-Reasoning?

    Models that support chain-of-thought consume reasoning tokens. But tasks such as summarization, format conversion, field extraction, and simple Q&A do not require complex reasoning. If deep reasoning is enabled uniformly for every request, it creates over-reasoning costs. The approach is to disable unnecessary reasoning based on task type, or to limit reasoning length in the model output.

    2. Why Does the Harness Determine Cost?

    The execution framework is the orchestration system that sits outside the model. For the same model, cost differences between different Harnesses mainly come from four areas:

    1. How context is organized: full concatenation versus on-demand retrieval, and whether conversation history is summarized on a rolling basis.
    2. How tool calls are orchestrated: whether there are duplicate calls, ineffective calls, or long chains of waiting.
    3. How failures are recovered: whether retries are restrained, and whether a maximum number of rounds and a timeout are set.
    4. How reasoning is triggered: whether deep reasoning is enabled based on complexity rather than applied uniformly.

    The goal of Harness optimization is to find a sustainable balance point between task completion quality and token spend.

    3. Engineering Practice: How to Reduce Token Consumption?

    3.1 Start With a Cost Measurement Template

    You need baseline data before optimizing; otherwise you cannot judge whether a cost reduction is effective. It helps to build a measurement table like this:

    Metric Description
    Task type Q&A, summarization, extraction, analysis, multi-step planning, etc.
    Model tier Lightweight model, standard model, reasoning model
    Input tokens Including system prompt, tool definitions, and context
    Output tokens The content finally generated by the model
    Cache hit rate Share of the prefix served from cache, or the billing savings
    Tool call count Average number of calls per task
    Cost per request Actual cost calculated from provider pricing
    Quality spot check Success rate, pass rate, manual rework rate

    By continuously sampling tasks and tracking these numbers, you can turn a vague “feels expensive” into comparable, optimizable engineering metrics.

    3.2 How to Improve Prompt Cache Hit Rate?

    • Keep the system prompt, tool descriptions, and role settings unchanged.
    • Move dynamic content such as time, IDs, and user input to the end.
    • Avoid frequently changing prompt versions.
    • Design requests around the provider’s cache lifetime and minimum prefix length.
    • Fix the request structure for high-frequency tasks to reduce invalid variation.

    3.3 How to Compress Context?

    Continuously concatenating long conversations causes context to balloon. You can use:

    • Rolling summaries: keep key conclusions and constraints while compressing the historical process.
    • On-demand retrieval: inject only the material needed for the current task via RAG.
    • Tool result trimming: keep only the summary, key fields, and necessary evidence.
    • Structured storage: write process information into the task state instead of repeatedly stuffing it into the prompt.

    3.4 Output Constraints and Reasoning Suppression Checklist

    To avoid reconfiguring this repeatedly, you can organize it into an action checklist:

    • Simple tasks: answer directly, without elaborating reasoning.
    • Complex tasks: require step-by-step reasoning, but limit the length of reasoning passages.
    • Structured tasks: output JSON, tables, or fixed fields.
    • Batch tasks: limit word count and forbid pleasantries.
    • High-risk tasks: add a validation step, but avoid excessive retries.

    Example system prompt:

    1. You are an office assistant. State the conclusion first, then add any necessary detail. Keep the total output under 200 words.
    2. If the task is extraction, output JSON only, with no explanation.

    3.5 How Do Model Routing and Tiered Scheduling Reduce Cost?

    Not every task needs the most powerful model. You can grade tasks by complexity and route them to a model with a matching cost. Complexity thresholds should not be hard-coded from experience; they need to be determined through evaluation on sampled tasks. Common experience shows that most low-complexity tasks can be routed to a lightweight model, but a quality fallback must be in place.

    1. def route_model(task):
    2. complexity = estimate_complexity(task)
    3. if complexity < 0.3:
    4. return "light_model"
    5. elif complexity < 0.7:
    6. return "standard_model"
    7. else:
    8. return "reasoning_model"

    When putting this into practice, note that misrouting can introduce quality risk. You should keep an escalation mechanism, for example switching to the standard or reasoning model when the lightweight model fails repeatedly or returns low confidence.

    4. How to Design Cost-Controllable Mechanisms?

    Product billing mechanisms can lower the barrier to adoption, but they must be combined with token optimization. Common approaches include tiered multipliers, discounts for low-consumption tasks, trial quotas, and transparent metering. It is worth emphasizing that any free or discounted mechanism should be based on measured token metering. After optimization, costs should be described as “significantly lower than before, with the exact result depending on task distribution, model pricing, and cache hit rate,” rather than as unconditionally approaching zero.

    Reasonable mechanism design includes:

    • Setting a lower multiplier for high-frequency, low-complexity tasks, with clear applicability conditions published.
    • Setting clearer pricing tiers for long-text, multi-tool, and multi-turn planning tasks.
    • Showing input, output, cache savings, and tool call counts on the bill.
    • Building anomaly cost alerts to prevent runaway spend from retry loops or overly long contexts.

    5. Go-Live Checklist: How to Verify Cost Reduction Is Effective?

    It is recommended to proceed in the following order:

    1. Baseline measurement: record the task distribution, token consumption, and cost before optimization.
    2. Cache optimization: verify whether the stable prefix improves the cache hit rate.
    3. Context compression: check whether long-conversation summaries and RAG injection reduce redundancy.
    4. Output constraints: verify whether word limits, formatting, and reasoning suppression reduce output tokens.
    5. Model routing: sample-evaluate the routing accuracy for the lightweight model, and record the fallback rate.
    6. A/B quality evaluation: compare cost, success rate, user satisfaction, and manual rework rate.

    Quality metrics should include at least: task completion rate, field extraction accuracy, answer pass rate, failure retry rate, and cost per effective task. Only when cost drops and quality stays stable can an optimization be considered truly effective.

    For office AI agents, reducing token costs is not a single-point trick but a systems-engineering effort driven by the Harness. If companies can combine caching, context management, output constraints, model routing, and a metering system, they can build a more stable cost advantage when scaling into production.