Chad Research · Paper 11

The economics of small contexts.

An agent that re-sends its whole transcript on every turn pays for its history again and again. Prompt caching softens the bill but not the shape. We work through the arithmetic of cost per task, the provider pricing mechanics, and the serving-side effects of small contexts, with a calculator you can adjust.

11 min read15 references

Abstract

The cost of an agent is not set by how many tokens it writes, but by how many tokens it reads, and how many times. An accumulating loop reads its entire history on every call, so total input grows with the square of the number of turns. Compiled small contexts keep each call’s input roughly constant.

Prompt caching changes the price of re-reading, not the fact of it. We lay out the formulas, show how the main providers price cached and uncached tokens, and look at the serving side: prefill and decode, prefix sharing, batching. The result is a simple rule that Chad is built around. Put a stable, shared prefix first and cache it. Compile everything else small and fresh.

Where the bill comes from

Every model call has two phases. Prefill processes the input prompt in parallel; decode generates output tokens one at a time. Splitwise characterizes the first as compute-intensive and the second as memory-intensive, and finds that token generation underuses GPU compute even with state-of-the-art batching [3]. Pope et al. make the same contrast on PaLM 540B: 76% model FLOPs utilization when processing input tokens in large batches, while low-batch generation is bounded by per-token latency [2]. DistServe shows that running both phases on the same GPUs creates interference between time-to-first-token and time-per-output-token, and that separating them serves up to 7.4× more requests under latency constraints [4].

Providers fold this into per-token prices. Anthropic lists output tokens at five times the input price across its current models, with separate prices for cache writes and cache reads [11]. For agents, though, the output side is usually small and stable: a tool call, a patch, a short plan. The input side is where the strategies diverge.

The accumulating loop is quadratic

A typical agent appends every turn’s reasoning, tool call and tool result to its transcript, then sends the whole transcript back for the next call. With an initial prompt of P tokens and T tokens appended per turn, the context at turn k is P + (k−1)·T, and the total input over n turns is:

input(n) = n·P + T · n(n−1)/2 // quadratic in turns

A compiled context of fixed size C costs n·C: linear. With P = 8k, T = 3k and 40 turns, the accumulating loop sends 2.66M input tokens. Forty compiled calls of about 6k send roughly 243k, about eleven times fewer.

Cumulative input tokens sent, by turn

Accumulating loop (P = 8k, T = 3k per turn) vs. compiled contexts of ~6k per call. Thousands of tokens.

Computed from the formula above with example parameters.

The compute picture is steeper still. Self-attention’s time and memory are quadratic in sequence length [1]. FlashAttention removes the memory blow-up and makes attention IO-aware, but it computes exact attention, so the arithmetic remains quadratic [1]. During decode, every new token reads the KV cache of the whole context, which grows linearly with length (see Paper 02). A long transcript is expensive on every axis: tokens billed, FLOPs in prefill, bytes read per generated token.

Tokens re-processed, turn after turn

Each column is one model call. Example parameters: P = 8k, T = 3k per turn; compiled S = 3k cached + D = 3k. Same vertical scale on both rows.

accumulating loop0 tokens sent
compiled small contexts0 tokens sent
re-sent history (cacheable at best)new tokensstable prefix (cached)compiled dynamic part
turn0 / 40
cumulative ratio, sent tokens1.0×
context at this turn8k vs 6k

The area under each row is the total input the model processes for the task. Accumulating: n·P + T·n(n−1)/2, quadratic in turns. Compiled: n·(S + D), linear. Prefix caching discounts the dim part of the top row on the bill, but those tokens still sit in the context window on every call.

What prompt caching actually charges

Prompt caching lets a provider reuse the processed state of a prompt prefix it has seen recently. The mechanics are similar across providers, and so are the constraints.

  • Anthropic prices a 5-minute cache write at 1.25× the base input price, a 1-hour write at 2×, and cache reads at 0.1× on most models (lower on some recent ones). The cache is built in order (tools, then system, then messages), a hit requires an exact prefix match, and a change at one level invalidates that level and everything after it. Prompts below a model-specific minimum (from 512 to 4,096 tokens, depending on the model) are not cached at all [10]. Anthropic notes that caching pays off after one read for the 5-minute cache and after two for the 1-hour cache [11].
  • OpenAI caches automatically on supported models, bills cached input at a discount, and recommends putting static instructions and shared reference material first, moving dynamic content to the end, appending rather than rewriting earlier turns, and keeping tool definitions stable [12].
  • Google enables implicit caching by default on Gemini 2.5 and newer models, with minimum prompt sizes of 2,048 or 4,096 tokens depending on the model [13].

Anthropic prompt caching price multipliers

Relative to the model's base input price, as listed in Anthropic's documentation (most models).

Source: Anthropic prompt caching and pricing documentation [10] [11]. Some recent models list a lower read multiplier.

Caching helps the accumulating loop a great deal, and any fair comparison must include it. But it has three limits for long-running agents.

  1. The prefix must stay byte-identical. Summarizing, compacting or reordering the transcript, which long agents eventually must do, invalidates everything after the first change.
  2. The cache expires. A 5-minute lifetime is short next to a CI run or a human approval. An agent that waits pays the write multiplier again.
  3. Dynamic content defeats it. Lumer et al. evaluated prompt caching across OpenAI, Anthropic and Google on more than 500 agent sessions. They report cost reductions of 41–80% and time-to-first-token gains of 13–31%, and find that caching only the system prompt gave the most consistent benefit, while full-context caching could even hurt latency because dynamic tool results trigger cache writes that are never reused [14].

The most reliable thing to cache is a stable prefix that many calls share. That is exactly what a compiled context has, and what an accumulating transcript does not.

Cost per task, worked out

The calculator below puts both strategies side by side with the same number of calls and the same output per call. The accumulating loop can use prefix caching on its transcript; the compiled side caches a stable prefix S and pays full input price for its dynamic part D.

Cost per task: accumulate or compile

Same number of model calls and the same output on both sides. Prices are adjustable examples, not a quote from any provider.

accumulating loop
compiled small contexts
accumulating = pin · Σk=1..n (P + (k−1)·T) + pout · n · O
compiled = pin · (w·S + (n−1)·r·S + n·D) + pout · n · O
……
……
…accumulating ÷ compiled

Cumulative cost after each turn. With caching on, the accumulating loop pays the write multiplier w on each newly appended block and the read multiplier r on the rest of the transcript, assuming every call lands within the cache lifetime. The compiled side writes its stable prefix once, reads it on later loops, and pays full input price for its dynamic part. Prices default to example values; enter your provider's.

With the defaults (example prices of $3 input and $15 output per million tokens, 1.25× write, 0.1× read, 40 turns), the arithmetic gives:

  • Accumulating, no caching: about $8.34 per task, dominated by re-sending the transcript.
  • Accumulating, with caching: about $1.59. Caching recovers most of the gap, under the generous assumption that every call lands within the cache lifetime.
  • Compiled small contexts: about $0.77, of which $0.36 is output, the same on both sides.

Read the second line carefully: with ideal caching, the cost gap shrinks to about 2×. The case for small contexts does not rest on the bill alone. The cached transcript still occupies the context window on every call, still costs attention compute and KV reads on the provider’s side, and still dilutes the intent (see Paper 01). Pricing can also depend on prompt length: Anthropic prices Claude Haiku 5.5 prompts over 100,000 tokens at a higher rate, including their cached portions [11].

The serving side: sharing and batching

If you run your own inference, the same structure shows up as throughput.

  • Batching. Orca introduced iteration-level scheduling, which lets requests join and leave a running batch at each step instead of waiting for the slowest sequence [5]. PagedAttention stores the KV cache in pages to reduce fragmentation and improves throughput by 2–4× over earlier systems [6]. How many sequences fit in a batch depends on KV memory, which grows linearly with context length. Small contexts mean bigger batches on the same GPU.
  • Prefix sharing. vLLM’s automatic prefix caching hashes each KV block together with the tokens before it, so requests that share a prefix reuse the same blocks [8]. SGLang’s RadixAttention organizes cached prefixes in a radix tree and reports up to 6.4× higher throughput on workloads including agent control and multi-turn chat [7]. Hydragen computes attention over a shared prefix once for the whole batch and reports up to 32× higher end-to-end throughput; its throughput falls by less than 15% when the shared prefix grows from 1K to 16K tokens, where baselines lose over 90% [9].

Reported serving gains from batching and prefix reuse

Each paper's own reported speedup over its baselines. Different models, hardware and metrics: read as direction, not comparison. Hover for details.

Sources: vLLM [6], SGLang [7], DistServe [4], Hydragen [9].

All of these gains depend on the same property: many requests that share a long, identical prefix and differ in a short suffix. An accumulating agent produces the opposite, one request per agent with a long, unique history.

How Chad applies it

Chad’s context compiler was designed with this cost structure in mind. Each agent loop starts empty and receives a context of about 6k tokens, assembled in a fixed order:

  1. Global domain best practices, identical across every loop in the organization. This is the most widely shared prefix, so it is placed first.
  2. The validated intent and acceptance criteria, identical across every loop working on that intent.
  3. Related changes found by a ClickHouse query over git history decomposed into rows linked to intents.
  4. Validated actions, stored as input → output pairs.
  5. The atomic task and target files.

The first two layers form a stable prefix that providers can cache and that self-hosted runtimes can share across concurrent loops. The last three are small and dynamic, so they are compiled fresh, never cached and never carried forward. Many loops run in parallel, each short-lived, each with a context whose size does not depend on how long the work has been going on.

Chad does not grow the context, so its cost per call does not grow with the age of the task. Spend scales with the number of atomic tasks, not with the square of the number of turns.

Limits & next steps

The comparison above is a model with example parameters, and real workloads vary. More loops mean more calls, and each call carries fixed overhead (tool definitions, the stable prefix, the compile step itself). Anthropic reports that its multi-agent research system uses about 15× the tokens of a chat interaction [15], a reminder that decomposition can raise spend when contexts are duplicated instead of compiled. A stable prefix shorter than the provider’s caching minimum is not cached at all. And when outputs dominate (long generated files, verbose reasoning), input strategy matters less.

Chad has no published cost measurements yet. We are instrumenting real repositories to report cost per validated task, cache hit rates and latency for both strategies, and will publish the results here.

References

  1. Dao, T., Fu, D. Y., Ermon, S., Rudra, A., Ré, C. FlashAttention: Fast and Memory-Efficient Exact Attention with IO-Awareness. NeurIPS, 2022.
  2. Pope, R. et al. Efficiently Scaling Transformer Inference. MLSys, 2023.
  3. Patel, P. et al. Splitwise: Efficient generative LLM inference using phase splitting. ISCA, 2024.
  4. Zhong, Y. et al. DistServe: Disaggregating Prefill and Decoding for Goodput-optimized Large Language Model Serving. OSDI, 2024.
  5. Yu, G.-I. et al. Orca: A Distributed Serving System for Transformer-Based Generative Models. OSDI, 2022.
  6. Kwon, W. et al. Efficient Memory Management for Large Language Model Serving with PagedAttention. SOSP, 2023.
  7. Zheng, L. et al. SGLang: Efficient Execution of Structured Language Model Programs. NeurIPS, 2024.
  8. vLLM project. Automatic Prefix Caching (design document). vLLM documentation.
  9. Juravsky, J. et al. Hydragen: High-Throughput LLM Inference with Shared Prefixes. arXiv:2402.05099, 2024.
  10. Anthropic. Prompt caching. Claude API documentation, accessed November 2026.
  11. Anthropic. Pricing. Claude API documentation, accessed November 2026.
  12. OpenAI. Prompt caching. OpenAI API documentation, accessed November 2026.
  13. Google. Context caching. Gemini API documentation, accessed November 2026.
  14. Lumer, E. et al. Don't Break the Cache: An Evaluation of Prompt Caching for Long-Horizon Agentic Tasks. arXiv:2601.06007, 2026.
  15. Anthropic. How we built our multi-agent research system. 2025.