Token Cost Optimization for Office Agents: A Practical Guide
This guide explains why token costs, rather than output quality, often become the first bottleneck when office agents move from demos into daily production. It breaks down the four key variables behind cost differences—cache hit rate, output length, over-reasoning, and context bloat—and shows how the surrounding execution framework (harness) shapes the cost curve through tiered routing, structured output constraints, minimal retries, and observability. It also covers quota and free-tier design patterns, plus a deployment checklist for keeping high-frequency tasks in a low- or zero-cost range.
1. Why “Affordable” Is Harder Than “Effective”
When an office agent moves from a demo into daily production, the first issue a team hits is usually not quality but the bill. A task that looks simple—organize meeting notes and generate a weekly report—may involve intent recognition, document retrieval, document parsing, structured extraction, template rendering, and result self-checking. Each step triggers one or more model calls. The task itself is not complex, but once call count and context length stack up, token consumption grows non-linearly.
In practice, this kind of cost is measured along three dimensions: average cost per task, the share of tasks covered by a free mechanism, and the cost multiple between different implementations running the same task. The phenomenon described here optimizes all three at once: lowering the consumption multiplier for high-frequency, lightweight models, and making low-consumption tasks free, so that most everyday tasks fall into a zero-cost range.
The key point is that cost differences come mainly not from model unit price but from the engineering capability of the execution framework (harness). With the same model and the same task, different implementations can still differ several-fold in token consumption, for four main reasons.
2. Four Key Variables Behind Cost
2.1 Cache Hit Ratio
Office tasks have strong repetitive patterns: the same system prompt, the same operations manual, and the same output template recur across hundreds or thousands of calls. If the framework places stable prefixes in a reusable position and keeps them byte-for-byte identical, that portion of the input can hit the cache and be billed at a lower rate. Otherwise, any jitter in fields such as timestamps, random IDs, or dynamic ordering invalidates the prefix, and the entire context degrades to full-price input.
Practical points: put invariant content first and volatile content last; avoid concatenating the current time or random numbers into prompts; and apply a stable sort to retrieval results before injecting them.
2.2 Output Length
Output tokens are usually more expensive than input tokens and are the most easily overlooked source of waste. Typical problems include making the model restate source text that was already provided, generating long explanatory preambles, and emitting natural-language output for structured data that a program should render. A better approach is to constrain the output contract—return only the necessary fields and leave formatting to a deterministic template engine.
2.3 Over-Reasoning
Over-reasoning means the model expands unnecessary multi-step thinking or repeatedly self-checks on simple tasks. It increases not only token usage but also latency. The way to address it is task tiering: route deterministic tasks such as extraction, classification, and formatting to small models or a rules engine; escalate to larger models only for tasks that require cross-document reasoning or trade-off decisions.
2.4 Context Bloat
Across multiple turns, history messages, tool return values, and intermediate artifacts keep accumulating. Without trimming, the input at step 10 can be several times that of step 1. Common practices are to keep only conclusion-level summaries, trim fields from tool returns, and move large objects to external storage while passing only a reference ID.
3. Optimization Paths in the Harness Execution Framework
The harness is the execution layer wrapped around the model, responsible for orchestration, context management, tool invocation, and failure retries. Its design quality directly determines the cost curve.
# Example: layered context assembly + output contract constraintSTABLE_PREFIX = SYSTEM_PROMPT + TOOL_SCHEMA # invariant content first, improving cache hitsdef build_context(task, history, ref_store):# 1) History trimming: keep only conclusion summaries, not full textsummary = summarize(history) if len(history) > 3 else history# 2) Externalize large objects: pass only reference IDs to avoid context bloatrefs = [ref_store.put(x) for x in task.large_payloads]# 3) Volatile content last, to avoid breaking the prefix cachereturn STABLE_PREFIX + render(summary, refs, task.instruction)def run(task, history, ref_store):tier = route_by_difficulty(task) # task-tier routingresp = model(tier, build_context(task, history, ref_store),response_format=CONTRACT) # return only necessary fieldsreturn validate(resp) # on failure, retry only the necessary step
Four reusable engineering habits: first, tiered task routing, handing deterministic work to rules or small models; second, structured output constraints, replacing natural-language checks with schema validation; third, minimal failure retries, re-running only the failed step rather than the whole chain; fourth, observability, using logging services and monitoring alerts to track input, output, cache hits, and failure rate per task, forming a cost baseline that supports continuous optimization.
4. Designing Quotas and Free Mechanisms
From a product perspective, combining “free high-frequency lightweight tasks” with “quota-based billing for very low-frequency tasks” is an effective way to improve accessibility. The logic is that the tasks that truly consume resources account for a small share of daily office work; most requests are short conversations, formatting, and field extraction, with very low unit cost, so covering them with free quota significantly lowers the barrier to use. Quota can also be granted through daily check-ins and new-user trial periods to help users form stable usage habits.
For enterprise readers, the same approach applies to cost management in internal platforms: set quota pools and alert thresholds for different teams, throttle or degrade high-frequency low-value calls, and reserve sufficient budget for high-value tasks.
5. Deployment Checklist
- Is the stable prefix byte-for-byte identical, and is the cache hit rate included in monitoring metrics?
- Are there large objects that can be externalized, and does the context pass only references?
- Is output forced to be structured, with rendering handed to a template engine?
- Is tiered task routing in place, or are simple tasks still using large models?
- Is there a per-task cost dashboard with threshold alerts?
- Do free quota and quota-pool policies cover high-frequency scenarios, and is there anti-abuse throttling?
6. Conclusion
The cost competitiveness of an office agent is essentially an externalization of engineering optimization capability. Only by governing all four variables—cache hits, output length, reasoning depth, and context size—and pairing them with sensible quota and free mechanisms can high-frequency daily tasks stay reliably in a low- or even zero-cost range. Baidu AI Cloud continues to invest in related engineering practices and general cloud product capabilities (such as container platforms, object storage, logging services, and monitoring alerts) to support enterprises in building agent applications with observability and controllable cost.
