LLM Workloads and KV Cache Reuse in the Agent Era
As AI agents move into everyday workflows, LLM workloads shift from single-turn question answering to long, multi-step reasoning with external state. This article breaks down the two defining traits of agent workloads—extremely high input-to-output token ratios and dynamically loaded context—and explains why prefix-based KV cache matching yields low hit rates. It then outlines practical strategies: layered context with a stable prefix, predictable loading formats, compression and summarization, orchestration and cache coordination, and metric-driven tuning. Readers will learn where the main efficiency bottleneck now sits and how to reduce cost and time-to-first-token without sacrificing output quality.
1. Background: Agents Have Fundamentally Changed the Workload Shape
Over the past year, agent applications with tool-calling and long-horizon planning capabilities have spread quickly. Developers, business builders, and even non-technical users now embed them in daily workflows to generate code, organize documents, and execute multi-step browser actions. After sustained, heavy usage, one conclusion stands out: in the agent era, LLM workloads are no longer the traditional “one question, one answer” pattern. They are long-chain, multi-turn, stateful reasoning processes, and token consumption has risen sharply. Efficiency is back in the spotlight.
A traditional conversational workload is simple: a prompt goes in, a response comes out, and input and output are roughly the same order of magnitude. An agent workload breaks a task into stages—planning, retrieval, tool calls, result injection, re-planning—and each stage resends the prior context to the model. This creates two structural changes, examined below.
2. Trait 1: Extreme Input-to-Output Ratio Makes Prefill the Main Cost
Across many real tasks, the ratio of input tokens to output tokens often reaches 100:1, and in complex scenarios it can approach 1000:1. In other words, the model generates very little; most compute is spent reading and understanding context—the Prefill phase.
The causes are straightforward:
- Every agent step reassembles system instructions, tool descriptions, prior trajectories, and loaded documents into the context.
- Structured tool results (log fragments, retrieval results, page text) are often far longer than the model’s conclusions.
- For consistency, context only grows across turns, so early content is recomputed repeatedly.
The direct consequence is a shift in focus from decode throughput to reusing and scheduling prefix computation. When input dominates, even a small reduction in Prefill cost is amplified across the total bill and time-to-first-token. Schematically, the cost of one task can be approximated as:
Total cost ≈ Σ(input tokens per step × input price) + Σ(output tokens per step × output price)≈ input-dominated term + negligible output term
3. Trait 2: Context Is Dynamically Loaded, Not Statically Fixed
The second trait is less obvious but has a bigger impact on caching. Agent workloads dynamically load large amounts of relatively static content into context: mature skill documentation, conversation memory, business knowledge documents, and—in multimodal scenarios—images and audio/video clips.
“Dynamic” shows up in two ways: uncertain load timing and uncertain load position. Skill documents are typically injected only when the model decides to invoke that capability; memory entries are inserted after relevance retrieval; retrieval results shift position with recall order. As a result, the same content can appear at completely different offsets in two adjacent requests.
4. Why Cache Hit Rates Are Naturally Low: The Prefix Matching Constraint
The context caching mechanisms offered by mainstream inference services generally follow a “longest common prefix, exact match” rule: only tokens that match from the very beginning can hit, and once a difference appears at any position, everything after it must be recomputed. Combined with dynamic loading, this is close to disastrous:
Request 1: [system instructions][skill A doc][user question]Request 2: [system instructions][skill B doc][skill A doc][user question]↑ divergence here; all of skill A doc is recomputed
From an engineering standpoint, the root cause of low hit rates is not insufficient cache capacity but that the addressability of cache keys is broken by context concatenation order. A common industry practice is to price cached hits significantly lower than misses (often a several-fold to tenfold gap). Under workloads with input-to-output ratios of 100:1 to 1000:1, converting most input from “miss” to “hit” can theoretically bring close to an order-of-magnitude cost reduction. Note that the exact multipliers and billing methods are defined by the service provider; architecture design should target the general goal of “increasing the reusable proportion” rather than relying on a fixed number.
5. Actionable Optimization Strategies
5.1 Layered Context and a Stable Prefix
Split context into an “extremely stable layer (system instructions, tool schemas, long-term rules)—a moderately stable layer (skill docs, domain knowledge)—a volatile layer (current retrieval results, user input),” and concatenate strictly in that order. The earlier and less mutable the stable layers, the longer the reusable prefix.
[extremely stable: role/rules/tool declarations][moderately stable: on-demand skills and knowledge blocks, kept verbatim within each block][volatile: retrieval fragments, history summaries, current-turn instructions]
5.2 Make Loading Predictable
Define fixed slots and a fixed serialization format for dynamic content (for example, sort by identifier, fix field order, use a uniform timestamp format) so a single space or field reorder does not trigger a full recompute. Reference skill documents verbatim; avoid runtime string concatenation and template tweaks.
5.3 Compression and Summarization Up Front
For long documents, do offline chunking and summarization first, turning thousands of tokens of raw material into a stable short summary that enters the prefix, and fetch the original only when needed. Replace full trajectory replay with rolling summaries to control growth and improve prefix stability.
5.4 Orchestration and Cache Coordination
In task orchestration, reduce unnecessary branch reordering; inject parallel tool results in a fixed order; maintain explicit memory of reusable intermediate conclusions to avoid repeated reasoning. If a container platform hosts the inference service, you can pair it with object storage to keep reusable context snapshots, use a message queue to smooth bursty requests, and rely on logging and monitoring/alerting to pinpoint where hit rates drop.
5.5 Drive Tuning with Metrics
Track at least four metrics: prefix hit rate, average input-to-output ratio, time-to-first-token, and cost per task. Looking at hit rate alone is misleading; evaluate it jointly with task success rate—over-compressing context can raise hit rate while hurting quality.
6. Cloud Implementation Notes and Common Pitfalls
In cloud environments, you can combine general-purpose capabilities: a container platform for elastic inference and orchestration, object storage for skill libraries and knowledge snapshots, a message queue for peak shaving, and logging plus monitoring for full-chain tracing. Baidu AI Cloud is typically used in such scenarios to provide elastic compute and supporting data and observability capabilities; refer to the official documentation for specific specifications and policies.
There are three common pitfalls: treating caching as a pure backend capability and ignoring the decisive role of application-layer concatenation order; pursuing extreme compression at the cost of task success rate; and optimizing a single request while ignoring the cumulative effect of multi-step tasks. The right approach is to treat context engineering as a first-class concern, on par with model selection and tool design.
7. Conclusion
The two traits of agent workloads—high input-to-output ratios and dynamic loading—point to one conclusion: the main battlefield for efficiency has moved from decode to Prefill reuse. Through layered context, stable prefixes, predictable loading, summarization up front, and a metrics feedback loop, developers can significantly improve cost and latency without sacrificing quality. This is also a foundational engineering capability that system design in the agent era must invest in for the long term.
