How to Reduce Token Costs for Office AI Agents
Office agents built on the same model can consume several times more tokens depending on how they are wrapped. This article explains the three main sources of token consumption: cache hit rate, output length, and over-reasoning. It also explains why the execution framework (the harness) is the key variable, and how to build a cost estimation table, apply practical optimizations such as model tiering and routing, context compression, cache reuse, and reasoning depth control, track the metrics that matter, and troubleshoot when costs fail to drop.
Introduction: How to Reduce Token Costs for Office AI Agents
Agents are now widely used across office scenarios such as document writing, data processing, investment research, marketing copy, and application development. Many teams ask the same questions: Why can different office agents consume several times more tokens when they use the same model for similar tasks? How can token costs be reduced? What mistakes are commonly made? And how should you choose a model and a compression strategy?
The answer is usually not just “switch to a cheaper model.” Much of the difference comes from the agent’s surrounding execution framework, known as the harness. The harness controls context organization, tool dispatch, reasoning depth, output length, and retry policies. Understanding the harness explains cost differences better than comparing model parameters alone.
This article covers the three main sources of token consumption, the execution framework, cost estimation, optimization strategies, metrics and monitoring, and common mistakes. It offers a practical approach to cost control.
1. Three Root Causes of Token Consumption Differences
Cache Hit Rate: Check Platform Support First
Many agents repeatedly send the same system prompt, tool definitions, long documents, or fixed business instructions. If this content is recomputed on every call, input token costs rise quickly as the number of turns grows. The higher the cache hit rate, the less you are billed for the same content twice.
Keep in mind, though, that caching does not take effect automatically. It requires the model or platform to support mechanisms such as prefix caching, prompt caching, or session caching. Support varies by provider, and the following conditions usually apply:
- Stable prefix: The system prompt, tool definitions, and fixed context should not change frequently.
- Defined cache scope: Some caches only cover the prefix, some can cache tool definitions, and some only cover conversation turns.
- Limited TTL: Caches may expire, after which content is recomputed.
- Different billing: Cache hits may be billed at a discounted rate, or may only apply to specific input types.
- Complex invalidation rules: Timestamps, random IDs, or dynamic variables in the prefix can break the cache.
In multi-turn conversations, long-document processing, and tasks with fixed prompts, whether the cache hits often determines the cost. If the model does not support caching, however, you cannot rely on caching to cut costs.
Output Length: Not Shorter Is Better, More Accurate Is Better
Output tokens usually cost more than input tokens and directly affect generation latency. Verbose explanations, repeated restatements, and unnecessary formatting all increase output volume per task.
Controlling output length is not about making answers shorter. It is about making them more precise. Useful practices include:
- Setting a reasonable
max_tokenslimit. - Requesting structured output such as tables, lists, or JSON.
- Switching from “explain first, then answer” to “conclusion first, then details.”
- Trimming unnecessary background explanation.
- Limiting word count or the number of key points for summarization tasks.
Precise output is more valuable than long output and is easier to keep under cost control.
Over-Reasoning: An Easily Overlooked Cost Black Hole
In agent scenarios, models sometimes produce long reasoning traces for simple tasks. These reasoning tokens are hard to notice but are still billed. Triggering deep reasoning for a simple Q&A is like hitching a heavy cart to a small horse: slow and expensive.
The key to controlling over-reasoning is to assess task complexity and match reasoning depth to it. If the model API supports reasoning budget or reasoning effort parameters, you can set different limits for different tasks. If it does not, do not assume you can simply “turn off reasoning.” Control costs through task routing, prompt constraints, and fewer tool turns instead.
2. Why the Harness Is the Core Variable
All three root causes above are ultimately tied to the harness.
- Context management: The framework decides what goes into the context window and how much. Irrelevant history lowers cache hit rates and inflates input costs. Intelligent trimming removes ineffective content.
- Tool-calling strategy: Hitting the right tool once is cheaper than repeatedly failing and retrying.
- Retry and error-correction logic: Unconstrained retries turn a single failure into multiple billed calls.
- Prompt engineering: The more stable and concise the system prompt, the better for cache reuse and output control.
- Cache-compatible design: Whether the framework understands a provider’s caching rules affects real cache hit rates.
The cost-effectiveness of an agent therefore depends not only on model selection, but also on harness tuning.
3. Do the Math First: Cost Estimation Table and Formulas
Before optimizing, build a cost estimation table. The formulas below are illustrative. Confirm actual unit prices, cache discounts, and billing methods against the provider’s documentation.
| Item | Illustrative formula | Notes |
|---|---|---|
| Base cost per call | Input tokens × input unit price + Output tokens × output unit price | Minimal cost model |
| Input cost after caching | Hit tokens × cache hit unit price + Missed tokens × input unit price | Only applies when caching is supported |
| Retry amplification cost | Cost per call × number of retries | Failed retries multiply the cost |
| Total cost per task | Σ (cost per call × retry factor) | Useful for estimating the real cost of a task |
| Cache savings | Cost without cache − cost with cache | Shows whether cache optimization is effective |
With this table, teams can see whether cost comes mainly from input, output, retries, or cache misses.
4. Practical Cost Optimization Strategies
Model Tiering and Routing: How to Choose?
The most direct way to cut costs is to use lightweight models for simple tasks and reserve high-capability models for complex ones. You can assess task complexity and dynamically select the model and parameter limits accordingly.
# The code below is illustrative pseudocode. Replace model names, parameters,# and the complexity evaluation function before real use.# estimate_complexity, lite, standard, and advanced must be replaced with the# models and logic that fit your business and vendor.def estimate_complexity(task):"""Illustrative: estimate complexity from task type, length, intent, etc.In practice, implement this with rules, a classifier, or manual labels."""if task["type"] in ["format", "rewrite_short", "classify"]:return "simple"elif task["type"] in ["report", "summary_long", "data_extract"]:return "medium"else:return "complex"def select_model(task):complexity = estimate_complexity(task)if complexity == "simple":# Example model name; replace it with a model from your vendor.return {"model": "lite", "max_tokens": 1024, "temperature": 0.3}elif complexity == "medium":return {"model": "standard", "max_tokens": 4096, "temperature": 0.5}else:return {"model": "advanced", "max_tokens": 8192, "temperature": 0.7}
Keep the following in mind when using this approach. lite, standard, and advanced are placeholder names. You should also redefine estimate_complexity based on your business tasks, user intent, and the capability boundaries of the models. For high-value complex tasks, do not pick an underpowered small model just to save money.
Prompt and Context Compression: What to Watch Out For?
The goal of context compression is to cut ineffective input while keeping the information the task requires. Recommendations:
- Keep the order of the system prompt and fixed context stable.
- Trim the system prompt and avoid frequent changes.
- Apply a sliding window or summarization to conversation history.
- Inject tool definitions on demand instead of loading all of them at once.
- Put dynamic variables, timestamps, and random IDs in an unstable region so they do not pollute the stable prefix.
# Illustrative pseudocode: if the provider's API supports prefix caching, use# the corresponding parameter; if not, just keep a stable prefix and compress# the history.def build_request(user_query, system_prompt, compressed_history, tools=None):messages = [{"role": "system", "content": system_prompt},*compressed_history,{"role": "user", "content": user_query},]request = {"messages": messages,"tools": tools or [],}# Add the prefix-caching parameter only if the provider's API supports it.# Do not fake cache parameters when it does not.return request
Common mistakes:
- The prefix changes frequently, invalidating the cache.
- Over-summarizing, which loses key business information.
- Injecting all tool definitions at once, which bloats input and lowers cache hit rates.
- Embedding timestamps, user IDs, or random values in the system prompt.
- Failing to separate stable context from dynamic context.
Cache Reuse and Reasoning Depth Control: What to Watch Out For?
For reusable intermediate results, such as retrieved snippets, parsed documents, and database query results, cache them locally to avoid regenerating them. For reasoning depth, distinguish what the API supports:
- If the model API supports reasoning budget or effort parameters, set per-task limits.
- If it does not, do not assume you can simply “turn off deep reasoning.”
- Control reasoning costs indirectly through task routing, prompt constraints, fewer tool turns, and constrained output structures.
For example, prompt simple Q&A with “no need for complex reasoning,” and allow multi-step reasoning only for complex analysis tasks. At the same time, set a reasonable limit on output length and trim redundant content.
Task Tiering and Free-Tier Mechanisms
From a product and engineering perspective, you can offer free or low-multiplier billing for low-consumption tasks such as simple Q&A, formatting, and lightweight summarization. Paid capacity can then focus on high-value tasks.
Keep in mind that a free tier is a product pricing strategy, not the same as model cost optimization. Whether it applies depends on business goals, user scale, risk controls, and budget. Without rate limiting and anti-abuse mechanisms, a free tier can lead to uncontrolled costs.
5. How to Measure Optimization Results: Metrics and Formulas
Set up measurable metrics:
- Average tokens per task = Total tokens consumed / Number of tasks completed
- Cost per task = Total cost / Number of tasks completed
- Cache hit rate = Cached tokens / Total input tokens
- Average output length = Total output tokens / Number of calls
- Retry amplification rate = Cost from retries / Total cost
- Share of free or low-consumption tasks = Number of low-consumption tasks / Total tasks
Wire these metrics into logging, monitoring, and alerting. Only by observing them continuously under real traffic can you spot cost anomalies and judge whether optimization is working.
6. Common Troubleshooting Checklist
If costs do not drop after optimization, check the following in order:
- Did dynamic content end up in the system prompt, preventing cache hits?
- Are prompts changed frequently, breaking prefix stability?
- Is the output longer than the task actually needs?
- Are simple tasks being routed to high-capability models by mistake?
- Does the retry logic lack a maximum attempt limit?
- Are all tool definitions injected at once, bloating the input?
- Does the free tier lack rate limiting, causing a surge of low-value calls?
7. Conclusion
Cost competition for office agents is essentially competition between execution frameworks. Token consumption differences come mainly from three sources: cache hit rate, output length, and over-reasoning. All three are shaped by the harness through context management, tool dispatch, retry logic, and prompt engineering.
When cache hit rate, output length, and task tiering are all handled well, cost per task can drop significantly. The exact magnitude depends on model unit price, caching mechanisms, task structure, and retry strategy, so rely on real monitoring data. With model tiering and routing, context compression, cache reuse, reasoning depth control, and task tiering, developers can control costs more reliably at the same level of model capability. This makes office agents both useful and affordable.
