Engineering · Agents, measured

Why an AI agent's bill grows with the square of its steps Six questions cost $4.60. Most of it paid for the same text, sent again and again.

In 30 seconds
  • An AI agent answers in steps: search, read, think, search again. At every step it sends the model everything it has gathered so far.
  • So the cost of a run grows with the square of its steps. 25 steps that each add 3,000 tokens send about a million tokens in all, although no single call is larger than about 75,000.
  • We saw it on six questions over long documents: $4.60, one question alone $2.02. Most of the problem was ours: documents with no pages, and old results that were never shrunk.
  • The fixes are known: shrink old results, keep every tool's output bounded, cap what a question may spend, and cache what is resent where the host discounts it. Ours took the same six questions from $4.60 to $1.24.
$4.60
six questions, one agent, seven long documents
$2.02
the most expensive single question: about 2 million input tokens
131k
the model's context window: no call came near it, so nothing was cut and nothing warned
What happened

A test of six questions, and a bill nobody expected.

We were testing how our agent handles a long contract and the documents that change it: a 300-page original, amendments, and later versions that restate the whole text. We took seven public filings, put them in one folder and asked six questions through exactly the path our product uses: hybrid search with a reranker, a page reader, a text search, and an open-weights 27-billion-parameter model on a fast host at $0.99 per million input tokens.

Four answers were right, two were confidently wrong (a story for another article). The bill was the surprise: $4.60, of which $2.02 for one question. At that price, $2.02 means about two million input tokens, for a question whose answer fits in a paragraph.

How an agent loop works

Every step resends every step before it.

A model keeps no memory between calls. To take its tenth step, an agent sends the model the question, the instructions and the results of the nine steps before. The eleventh call sends all of that again, plus the tenth result. The total grows like 1 + 2 + 3 + … + n: with the square of the number of steps.

Steps, each adding about 3,000 tokensLargest single callSent in all
5about 15,000about 45,000
10about 30,000about 165,000
25about 75,000about 975,000

Arithmetic: step k sends the k results gathered so far. Instructions and the question add a fixed amount to every call.

Two things make this easy to miss. No single call is large, so the context window never fills and nothing is cut or refused. And the last call looks cheap; it is the sum that is not. Add a final step that rereads everything to check the answer, and a long question can cost a hundred times a short one.

The context window limits each call. Nothing limits the sum, unless you do.
The bug it exposed

A document with no pages, and a reader that always opened the cover.

Our agent reads a document a page at a time, at most 12,000 characters per read. A PDF has pages. The filings we used were HTML, and HTML has none, so each 300-page document was one "page 1". Every time the agent asked to read the page where a passage sat, it got the first 12,000 characters: the cover and the table of contents. It learned nothing, so it searched and read again, and every useless read was carried, whole, into every later step.

A second gap made it worse. Our agent speaks to models in two ways, as JSON or through the model's own tool calls. The JSON loop already shrank old results into short notes; the tool-call loop, which this model uses, did not. Each page read rode along to the end.

What the industry does

Resending everything is standard. Four things keep it affordable.

Most agent frameworks work this way, and so do the coding assistants built on them. They stay affordable because of four habits:

  • Prompt caching. The part of a call that has not changed since the last one is read from the host's cache and, at most providers, billed at a fraction of the price. That turns the square back into something close to a straight line. Not every host discounts it: the one we used caches automatically (11,264 of 11,296 prompt tokens came back cached in our check) but bills cached input at the full rate, so there it saves time, not money.
  • Shrinking old results. After a few steps, a tool's raw output is replaced by a short note or a one-line stub, while the model's own reasoning stays. Anthropic's API offers this as context editing; published research has found that simply masking old tool outputs does about as well as summarising them, for far less.
  • Compaction. Past a threshold, the conversation is summarised and the agent carries on from the summary.
  • Bounded tools. Every tool returns a limited amount, and says where the rest is. A "page" that can be a whole book breaks this.
What we changed

Pages for every document, notes instead of raw results, and a ceiling.

  • Every document has pages. A file that stores none (HTML, text, markdown, a Word file) is cut at the first blank line after each 4,000 characters, about a printed page. Nothing is added or removed, and a citation can point to a page again.
  • Long pages come in parts. A spreadsheet tab with thousands of rows is one page; the reader now returns it in parts, each repeating the table's header row, and can jump straight to the part holding given words.
  • Old results become notes in both loops. Each result is shown whole once; at the next step it is condensed into the facts that bear on the question, with their sources.
  • A ceiling per question. Once a question has spent its budget, the agent must answer from what it has gathered, and the answer says so.

Before and after, same documents, same questions, same model and host

QuestionBeforeAfter
1. The current headline amount$0.03 · wrong (an older version)$0.20 · right
2. When it ends$0.69 · wrong$0.26 · wrong
3. Is a restriction still in force?$0.07 · right$0.05 · right
4. How the amount changed over time$0.97 · right$0.10 · right
5. Every change to the original, listed$2.02 · right$0.40 · right (stopped at its budget)
6. Which rate applies now (not in the documents)$0.82 · said so$0.24 · said so
All six$4.60 · 4 right$1.24 · 5 right

The cost fell by almost three-quarters, and the most expensive question by four-fifths. The first question cost more after the change: before, the agent answered after a single search, from an older version of the document, and was wrong. Reading the right page cost a little more and found the right figure. One run of six questions: the accuracy change is a hint, not a result.

An agent that can read without limit will. The limits belong in the design, not in the invoice.
How we measured

What this says, and what it does not.

  • Seven public filings from one company: one original, two amendments, and four later versions of a second contract, three of them restating the whole text. Six questions. One run, so read the costs as an order of magnitude, not a benchmark.
  • Agent: our own loop, up to 25 steps, hybrid search with a reranker, a page reader capped at 12,000 characters, a final step that rereads the gathered passages to check the answer. Model: an open-weights 27B model at $0.99 per million input tokens and $1.49 per million output tokens. Both runs on 21 November 2026, the second with a budget of $0.30 for the steps of each question.
  • The token figures for the most expensive question are worked out from its cost and the price; the step-by-step trace was not saved in that run.

For how retrieval feeds the agent, see Is RAG worth the trouble over Elasticsearch?; for answers with every source published, VectoGrid scores 90% on FinanceBench.

Is your agent paying for the same text twice?

Talk to us

Published 21 November 2026 · Philippe Vergnet, VectoGrid