Post

The Cost of an Agent Step

Cutting what each agent step costs: cache hits, thin orchestrators with specialist subagents, and cache-aware routing, with judge-based quality checks.

The Cost of an Agent Step

Agents make many model calls per task, and each call resends a growing context. Write-ups from Oct 19–21 show where the money goes and which levers cut it: prompt-cache hits, a thin deterministic orchestrator that hands narrow work to specialists, smaller post-trained models for those specialists, and serving that keeps a session’s KV cache close. Cloudflare and Shopify also checked that quality held.

Part of This Week in AI & Systems #2: Hardening the Agent Stack.


What’s new this week

  • Cloudflare (Oct 19) cut the cost of its AI code reviewer by 68%, from $2.43 to $0.77 per review, and the median review time from 4m 09s to 1m 32s.
  • Meta (Oct 19) described a “thin orchestrator” for its data-pipeline agents: a deterministic router that hands all domain work to 14 specialist subagents. An InfoQ article the same day frames agents as the next step after microservices, with decisions rather than functions as the unit of decomposition.
  • Shopify (Oct 21) described how it post-trains open models as “task experts” for Sidekick subagents. For one subagent, a post-trained model scores slightly higher than the frontier model at about 90% lower serving cost.
  • llm-d 1.0 (Oct 20). Google and the llm-d community released a Kubernetes-native serving stack with cache-aware routing, tiered KV cache and flow control for bursty agent traffic.
  • AWS and vLLM (Oct 19). Bi-directional KV transfer lets disaggregated serving reuse earlier turns instead of recomputing them.
  • The Pragmatic Engineer (Oct 20) gathered AI spending data from 27 companies and found that few can yet say what the spending returns.

Why it matters. Per-token prices keep falling. MiniMax’s M3.1 Flash (Oct 19) is listed at $0.15 per million input tokens. But an agent’s bill grows with the number of calls and the size of the context resent on each call. The posts this week treat cost as a property of the agent’s design, not just of the model’s price list.

Key ideas

  • Measure where tokens go first. Before its changes, Cloudflare’s review spend split into 43% cache writes, 34% cache reads and 23% output tokens. Most of the money went on context the model had already seen. Tokens per review had more than tripled since April, even with a 97% cache hit rate.
  • Check the first call of each session. Cloudflare found that the first request in a session read a cached prefix only 14–26% of the time. The shared agent prompt and per-run details such as the working directory and date sat in one cached block, so the shared part was never stored on its own. Splitting that block, removing wasted calls and sharing one prefix across three reviewers produced about 40% of the savings. Model and effort changes, tested in randomized splits, produced the rest.
  • Cheaper settings need a quality check. Cloudflare had judges from two providers rate a blinded sample of 657 findings. Code quality at high effort found about as many real problems with less noise. Medium effort lost real findings for code quality and performance, so code quality is moving to high effort and the other reviewers are being tested at high next.
  • Keep the router thin. Meta’s first design, one agent loaded with all the domain knowledge, began applying one subsystem’s conventions to another once its context grew. The replacement is a 1,300-line orchestrator that follows a fixed seven-step protocol; only the delegation step uses LLM reasoning, inside a subagent that loads just its own knowledge files. Configuration prep for a new data column fell from three to four days by hand to under an hour. “Which subagent handles this?” is a routing decision, the post argues, so an LLM should not make it.
  • Bound the loop. InfoQ’s article (Mallika Rao) warns that evaluation-driven retries, unlike retries on explicit errors, are hard to bound and can raise latency and backend load. It recommends latency budgets, retry limits, limits on reasoning depth and deterministic fallback paths.
  • Narrow tasks suit small post-trained models. Shopify’s GraphQL subagent reads about 40 tokens for every one it writes. A post-trained Nemotron 3.5 Lightning (3B of 30B parameters active) went from a judge score of 37.7 to 74.5 over six loops, against 73 for the frontier model. It responds 7× faster at the median. A nightly “self-healing” step repaired 69% of the failed production conversations it tried and fed them back as training data.
  • Route each step to the replica that holds its context. llm-d’s router sends requests to replicas that already cache the prompt prefix and spills KV cache to host memory, SSD or Managed Lustre. On an agentic coding workload on Ironwood TPUs, Google reports more than 85% lower median time to first token and 2.4× throughput compared with a plain Kubernetes Service.
  • Don’t recompute earlier turns. In disaggregated serving, KV cache normally flows only from prefill to decode nodes. AWS’s vLLM change lets decode nodes send it back on the next turn, cutting time to first token by up to 1.6× for Qwen3-32B and 3.3× for GLM-5-FP8 at the longest prompts tested. Below a configurable threshold, recomputing is cheaper than transferring.

Diagram of three cost levers for an agent step: a model call can be made cheaper by fixing prompt-cache hits, by moving narrow subagents to post-trained open models, or by routing to replicas that hold the session's KV cache; the prompt-cache and model levers feed a quality check with judges and acted-on findings, while the KV-cache lever's dashed link is marked latency/throughput only Diagram of three cost levers for an agent step: a model call can be made cheaper by fixing prompt-cache hits, by moving narrow subagents to post-trained open models, or by routing to replicas that hold the session's KV cache; the prompt-cache and model levers feed a quality check with judges and acted-on findings, while the KV-cache lever's dashed link is marked latency/throughput only Composite of the Cloudflare, Shopify, llm-d and AWS write-ups; not any one source’s diagram. Tap to enlarge.

Analysis: the cheapest change in these reports is often the most boring one, such as prompt ordering, before any model swap. Meta reports time saved rather than token costs, but a router that does no LLM reasoning and specialists with small, isolated contexts are what allow each step to get its own model, as Shopify does for its subagents. Teams that self-host gain the serving-side levers (routing and KV reuse); teams on hosted APIs mostly have the caching and model-choice levers. Open question: the Pragmatic Engineer data suggests most companies still cannot tie AI spending to outcomes, which makes per-step cost the easier number to manage than return.

Reading list

Grouped loosely: application-side savings (Cloudflare, Shopify), orchestration patterns (Meta, InfoQ), serving-side savings (llm-d, AWS) and spending context (The Pragmatic Engineer, MiniMax, Google Cloud).

Background and prior art

This post is licensed under CC BY 4.0 by the author.