↓ Skip to main content

Cutting the Cost of AI Agents: Budgets, Guardrails and Narrow Tools

·2667 words·13 mins·Mathusuthan

An AI agent works in a loop: it plans, calls a tool, checks the result and acts. Each turn of the loop sends the whole history to the model again, so the input grows with every step. The bill depends on how much data each step carries and which model does the routine work, not on the length of the final answer. This post breaks down the cost with and without the architecture fix, including one case where the fix cost more.

What kind of application is this ?
#

This archetype gives an agent a goal, a set of tools and a rule book. The agent decides which tool to call, reads the result and decides the next step. At the end, it writes an action into a business system, for example a payment voucher or a dispatch plan.

Each task takes several model turns. In each turn, the model reads the rules, the task and all the tool results so far, then makes one or more tool calls. The deck calls this loop plan, call, verify, dispatch.

The deck gives three use cases. The first card uses the NovaMart lab’s real prompt and output. I wrote the other two for this post, to show the same pattern in other work.

1

Invoice reconciliation

Match a supplier's invoice against the purchase order and the warehouse goods receipt. Apply the payment policy. Then write the payment voucher.

Input

"Reconcile NovaMart supplier invoice INV-TS-2026-1184 (PO PO-NM-HYD-1184, claimed grand total INR 2,542,900.00) against live ERP records and commit the final voucher."

Prompt (excerpt; it follows a 15,600-character policy manual)

Obey strict max_step_budget = 4 (at most 1 tool call per step):
- Step 1: Call fetch_3way_match_bundle(invoice_id).
- Step 2: Call run_policy_tolerance_gate(invoice_id).
- Step 3: Copy the exact gate numbers into commit_reconciliation_voucher(...).
- Step 4: Emit a concise <=130-word audit summary.

Output (the committed voucher)

{
  "decision": "APPROVE_CLEAN",
  "authorized_net_principal_inr": 2155000,
  "authorized_gst_payout_inr": 387900,
  "gst_escrow_holdback_inr": 0,
  "debit_note_deduction_inr": 0
}

2

Claims adjudication

Check an insurance or warranty claim against the policy and the evidence. Decide how much to pay, and record the reason.

Input

"Claim CLM-20417: water damage to a refrigerator. Two photos and the purchase invoice are attached. Policy HOME-STD-2026."

Prompt written for this post

You have at most 4 steps. Call get_policy and get_claim_evidence. Then call check_coverage, which computes the payout. Call commit_decision with its result. Do not compute the amount yourself.

Output example

{
  "decision": "PART_PAY",
  "payout_inr": 18500,
  "reason_code": "DEPRECIATION_APPLIED"
}

3

Supply chain dispatch

When a delivery is late or stock is short, find the orders at risk. Move them to another warehouse and book a carrier.

Input

"The inbound truck to FC-BLR-01 is 6 hours late. 140 orders are promised for delivery tomorrow."

Prompt written for this post

You have at most 5 steps. Find the orders at risk. Check stock at the two nearest hubs. Book one carrier slot for the orders you move. Call commit_dispatch_plan once.

Output example

{
  "orders_moved": 140,
  "from_hub": "FC-HYD-01",
  "carrier_slot": "2026-11-25T05:30"
}

How I tested it. The NovaMart lab built the first use case: a three-way invoice match. NovaMart is a made-up Indian retailer, and all of its data is synthetic. The agent reads a SQLite database that holds the invoice, the purchase order and the goods receipt. It applies an accounts-payable policy manual and writes a voucher with five fields: the decision, the amount to pay, the tax to pay, the tax to hold back and the deduction. I used 12 invoices, and I worked out the right voucher for each one by hand from the manual: 5 routine invoices, 5 disputes and 2 that must be blocked. I ran four set-ups on every invoice, three times each. That is 144 runs, each one a real agent loop against the model APIs. This is a small sample, so read the results as what I saw in one lab, not as a benchmark.

The token profile and cost dynamics
#

The deck gives this profile for the archetype:

INPUT PER TASK
25,000 to 150,000+ tokens
Rules, tool definitions and the results of every step so far
OUTPUT PER TASK
1,500 to 8,000 tokens
Reasoning, tool calls and the final action
DYNAMICS
Multi-turn tool loops
Plan, call, verify, dispatch, then repeat
IN THE LAB
41,000 to 77,000 in
1,050 to 2,700 out, per invoice

“Multi-turn tool loops” is the key phrase. A model does not remember the last turn. So at each turn, the system sends everything again: the rules, the task, every earlier tool result and every earlier answer. Then it adds the new tool result on top. The input of turn 4 holds all of turns 1, 2 and 3. You pay for the same text many times.

Here is a real example from the NovaMart lab, without the lever. The invoice is a clean match: nothing is wrong with it. The agent has five tools that each return a full database table, plus a tool to write the voucher. The system prompt holds the policy manual and this protocol:

Example: one clean invoice, raw-table loop (Sonnet 5.5)

System prompt (after the policy manual)

Task (the user message)

What the model sent and received, turn by turn

Final answer

The agent called four tables in its first turn and one more in its second. Those tables returned about 21,600 characters of rows, most of them columns the policy does not need. From then on, every turn carried all of it again. Over four turns, the model read about 76,000 input tokens to fill in a voucher of five numbers. 69% of those tokens were text it had already read.

This changes where the money goes. In Archetype 1, a long answer made output the problem. Here, the input is about 90% of the cost. And the input grows with each turn, so a loop that runs longer costs more than in proportion.

The voucher was right. On these 12 invoices, the agent got every voucher right in all four set-ups. So the lever in this post is about cost and control, not about fixing wrong answers.

The architectural lever
#

The deck’s lever for this archetype is: “Enforce max-step loop budgets, deterministic guardrails, and Flash-tier routing for routine tool calls.” “Flash-tier” means a small, fast model, such as Google’s Flash models or Anthropic’s Haiku. The lab built all three parts. It also added two more changes that turned out to matter most.

1. A step budget
#

A step budget is a hard limit on the number of turns. In the lab, the “with” design has four steps: fetch the data, run the policy check, write the voucher, write a short summary. If the agent tries to go further, the loop stops.

In these runs, the budget never had to stop anything. The “with” runs took exactly four turns. The “without” runs had a safety limit of 12 turns, but took only 3.9 on average. The budget is a safety rail. It protects you from the rare run that loops for 30 turns. It did not save money on these invoices.

2. A deterministic guardrail
#

A guardrail is a rule that runs in code, not in the model. In the lab, a policy tool does the voucher arithmetic in code, from the manual’s rules. The tool that writes the voucher refuses to run until the policy tool has run. The model copies the tool’s numbers. It does not do the sums itself.

Without the tool, the model did the arithmetic itself, and it got all 72 vouchers right. So on these invoices, the guardrail did not change accuracy. What it changes is assurance: every “with” voucher carries a mark that code checked it. In a finance system, that mark is often what an auditor asks for.

3. Route routine work to a small model
#

With model routing, the agent starts on Haiku 5.5. If the policy tool finds a dispute that mixes two or more problems (for example, damaged units and an unauthorised price rise), the run switches to Sonnet 5.5 for the last two steps. Here, 2 of the 12 invoices were such disputes, so 6 of the 36 runs switched.

4. What the lab added: one narrow query and a cached manual
#

The “with” design makes two more changes that the deck does not name:

  • One narrow query. The agent gets one tool that joins the invoice, the order and the receipt, and returns only the fields the policy needs. It no longer pulls five full tables.
  • A cached policy manual. The manual and the tool definitions are the same for every invoice. The system marks them for context caching. The first turn writes them to the cache at a higher price. Each later turn reads them at 5% of the input price on Sonnet, or 10% on Haiku.

Compare the two designs on the same invoice. Choose an invoice and a model. Each bar shows the input of one turn. The full-color part is full price. The light part was read from the cache.

Same invoice, two designs

Without Raw tables, model does the sums

    With Narrow query, policy tool, 4 steps, cache

      Recorded runs from the lab (first of three runs). "Cold" means this run wrote the cache itself. "Warm" means the cached manual was already there, as in a busy system that reconciles invoices all day.

      Without the lever, a turn sends up to 24,000 full-price tokens. With it, a turn sends at most about 3,500. The manual is still there in every turn, but it is read from the cache.

      What saves the money? The lab also added the changes one at a time, on Sonnet. Caching the manual alone cut the cost by 28%. The narrow query then cut 61% of what was left. Adding the policy tool raised the cost by 19%, because it adds a turn. Moving the same design from Sonnet to Haiku cut 94%. So most of the saving comes from sending less data and using the small model. The guardrail buys assurance, not savings.

      5. Does the quality stay the same?
      #

      On these invoices, yes, in every set-up. Use the buttons to change between the two measures.

      Exact vouchers, of 36 runs

      Higher is better

      • All four set-ups got 36 of 36 vouchers exactly right. All five fields matched the hand-worked answer. So these 12 invoices cannot show a difference in accuracy. 36 of 36 still allows a true error rate of up to about 10%.
      • Only the “with” design has a code check. In all 72 “with” runs, the voucher carried the policy tool’s numbers, and the tool’s numbers match the hand-worked answers on all 12 invoices.
      • Model arithmetic can slip. In a side run with caching alone, Sonnet got 35 of 36. On one dispute, it wrote a net amount of 3,862,520 where the right answer was 4,862,520. The decision was right; one digit was wrong. A code check catches that kind of error.

      The cost savings
      #

      Here is the cost of each set-up. Use the buttons to change between a cold cache and a warm cache. Select a row to see what changed.

      Cost per 1,000 invoices

      Lower is better

      Show as a table

      Average of 36 runs per set-up, recomputed from the recorded tokens at the rate card below. Without the lever nothing is cached, so cold and warm are the same.

      On Sonnet, the lever works as the deck says. The cost falls from $153.41 to $51.22 per 1,000 invoices from a cold start, a 67% cut. With a warm cache it falls to $30.49, an 80% cut.

      On Haiku, the result is mixed, and I want to be clear about it. From a cold start, the lever made Haiku 32% more expensive: $10.42 against $7.89. With a warm cache, it was 25% cheaper: $5.94. Two things cause this:

      • Writing the cache costs extra. A cache write costs 1.25 times the normal input price. A cold run pays it at the start. On Haiku the input is already cheap, so the write is a large part of a small bill.
      • The switch to Sonnet is expensive. An invoice that stayed on Haiku cost about $0.0027. An invoice that switched to Sonnet cost about $0.049, 18 times as much, because Sonnet must write its own copy of the cache. Only 6 of the 36 runs switched, but they made 78% of the Haiku-first cost.

      Without the lever, Haiku did those two hard invoices correctly, at $0.0086 and $0.0088 each. On these invoices, the switch to Sonnet bought nothing. With harder disputes it might. The more disputes in your mix, the closer the Haiku-first cost moves to the Sonnet cost.

      The biggest single saving is the model. The unchanged raw-table loop cost 95% less on Haiku than on Sonnet, with every voucher right on both.

      The rate card used, in US dollars per million tokens:

      ModelInputOutputCache writeCache read
      Claude Sonnet 5.52.0010.002.500.10
      Claude Haiku 5.50.100.500.1250.01

      Bonus architectural lever
      #

      The one-at-a-time runs point to a simpler design: give the agent one narrow query, cache the manual, and run it all on Haiku, with no policy tool and no switch to Sonnet. The model does the arithmetic itself. The agent needs only three turns: fetch, write the voucher, summarise.

      The simplest design against the full lever, on Haiku 5.5

      36 runs each, on the same 12 invoices. "Checked by code" means the voucher carries the policy tool's figures.

      It was the cheapest design I measured for this archetype: $2.40 per 1,000 invoices cold and $1.45 warm, with all 36 vouchers right. That is 77% less than the full lever on Haiku from a cold start.

      The cost is the code check. Nothing outside the model checks the sums. The side run above shows that a model can get one digit wrong. So you have a choice:

      • If a person or a later system checks every payment, the simple design may be enough.
      • If the voucher pays money with no other check, keep the policy tool. The invoices that stayed on Haiku with the full lever cost $2.72 per 1,000 cold. Most of the extra cost came from the switch to Sonnet, not from the check.

      Cost Estimator
      #

      Use this calculator for your own agent. It starts with Haiku 5.5 and the token counts measured in the lab. Change the prices to the rates of the model that you use.

      Agent loop cost estimator

      Prices, $ per million tokens
      Without: raw data, no cache
      With: narrow query, cache, step budget
      Your workload

      A switched task runs its second half on the larger model, at the Sonnet 5.5 rates, and writes its own cache.

      Defaults come from the lab's Haiku 5.5 runs: without the lever, 8,828 input tokens in the first turn plus about 5,600 more each turn; with it, an 8,693-token cached prefix, 215 uncached tokens in the first turn plus about 1,060 more each turn. 17% is the lab's switch rate (6 of 36 runs). The estimate assumes every turn adds the same amount, so treat it as a guide, not a quote. With these defaults it gives $9.45 per 1,000 tasks with the lever; the lab measured $10.42, because the switched runs wrote longer answers on Sonnet.