Skip to content

Interview question · Optimizing & Tuning Agents

What does an agent task cost? Show where the tokens, the seconds and the money go in one run, and what you would cut first.

The entry question for the optimisation topic. The strong answer chains the cost of one run from steps and context, shows that re-read input dominates, puts latency on the same chain, and works down the ladder of cuts from steps to context to tools before touching the model.

easyNewUpdated Nov 2026

TL;DR: Cost per task is steps times what each step reads and writes. Input tokens dominate, because every step re-reads the whole transcript, so a run's input bill grows with the square of its length; output tokens are few but priced several times higher per token, and thinking tokens are output. Latency follows the same chain: steps times the time per model call plus tool time. So the first cut is steps the task does not need, the second is context the model re-reads every turn, the third is tools that cause retries, then caching the stable prefix, then a cheaper model for easy steps. Changing the model is the last rung, not the first.

How to approach it

Build the chain on the board with illustrative numbers and show where the total comes from. Then put latency beside it. Then give the order of cuts and say why that order: cheapest to try and to undo first, each measured on the same tasks. Interviewers ask this to see whether you reach for the model switch before you have looked at a trace.

A strong answer

One run, illustrative, with relative prices so the shape is the point (Optimise an Agent in the Right Order):

steps                          24 model calls
stable prefix                  5,000 tokens   (instructions + 30 tool definitions)
transcript growth              1,800 tokens per step (call + result)
output per step                150 tokens; 400 on the 6 steps that reason

input tokens on step n         5,000 + 1,800 n
input over the run             24 * 5,000 + 1,800 * (1 + 2 + ... + 24)
                               = 120,000 + 1,800 * 300 = 660,000
output over the run            18 * 150 + 6 * 400 = 5,100

price (illustrative)           input 1 unit per 1,000 tokens
                               output 5 units per 1,000 tokens
                               cached input 0.1 unit per 1,000 tokens

cost, no cache                 660 + 25.5 = 685.5 units
cost, prefix cached            prefix: 24 * 5,000 = 120,000 -> 12 units
                               rest:   540,000 -> 540 units
                               total:  552 + 25.5 = 577.5 units

Two things stand out. Input is 96 percent of the bill, and most of it is the transcript being re-read: the triangular sum, 1,800 times 300, is 540,000 of the 660,000 input tokens. The prefix cache saves a sixth; it cannot touch the transcript because the transcript changes every step. Output, including reasoning tokens, is small in count but five times the price, which is why "set reasoning effort high everywhere" shows up on the bill out of proportion to its token count.

Latency follows the same structure:

per step    model call 2.5 s + tool 0.8 s (average)   = 3.3 s
run         24 * 3.3                                   = 79 s

Steps multiply everything. A run that needs 12 steps instead of 24 roughly halves both the time and the bill, and because the triangular sum shrinks faster than linearly, the input cost falls by more than half.

So the order of cuts is the order of effect per unit of risk:

RungCutWhy firstHow to see it in the trace
1Steps the task does not needEvery step carries the whole transcriptRepeated reads, a tool call then a second to confirm it, planning steps that change nothing
2Context re-read every turnThe triangular sumAn 8,000-token tool result left in place for 20 steps
3Tools that cause retriesEach retry is a stepSchema errors, vague descriptions, results the model cannot parse
4Cache the stable prefixFree once the prefix is stableCached-token count near zero on steps after the first
5Route easy steps to a cheaper modelMost steps are routineFile picks and formatting running on the largest model
6Optimise prompts against a metricChanges behaviour, needs an eval setOnly after the set exists
7Fine-tune or trainExpensive, slow to undo, needs a stable task and graderWhen the rungs above are exhausted and the task is stable

Each rung is cheaper to try and to undo than the one below it, and each is measured the same way: the same task set, repeated runs, cost and pass rate side by side, before and after. Cutting steps that lowered the pass rate is not an optimisation.

Authority line: the harness owns the budget. The model does not know what a step costs or how many it has used; the harness counts tokens and time against the task's budget and ends the run, and that budget is where the optimisation target is written down.

What interviewers probe next

"The model is 60 percent of the cost. Why not switch to a cheaper one first?" Because the cheaper model inside the same wasteful loop re-reads the same bloated transcript and may need more steps to finish, and you cannot measure that until the steps and context are fixed. Fix the loop, then test the switch on the same tasks.

"The prefix cache rate is low. Why?" Something near the front of the prompt changes per step or per run: a timestamp, a user name in the system prompt, tool definitions in a different order. Make the prefix byte-stable and watch the cached-token count on step two.

"How do you cut latency without cutting steps?" Run independent read calls in parallel in one step, stream the model's output so the user sees progress, and move slow tools to a cheaper check-then-fetch. Steps are still the biggest lever.

How it's scored

Weak: Proposes a cheaper model or a shorter prompt with no chain showing where the cost is.

Hire: Chains cost from steps and context, shows input dominates through the triangular sum, puts latency on the same chain, and cuts steps and context before the model.

Strong Hire: Also prices output and reasoning tokens separately, reads the cache rate as a diagnostic, measures every rung on the same tasks with pass rate beside cost, and keeps the budget with the harness.

Common mistakes

  • Switching models before reading a trace.
  • Counting tokens per call instead of per run, and missing the triangular growth.
  • Leaving large tool results in the transcript.
  • A system prompt with a timestamp, so the cache never hits.
  • Optimising cost without checking that the pass rate held.
You just read a free answer. Every topic opens its first 5 answers to anyone. Sign in and the count per topic goes to 6, and the site remembers where you stopped in each one.Google sign-in · free · no payment details
HOW DID IT GO?
0
READING SIGNED OUT

Signing in raises your free answers from 5 to 6 per topic, adds an applied lesson in every topic and easy practice tests, and the site starts remembering you: mastery per topic, bookmarks, and a next-focus recommendation. Free, no card.

Sign in free
UP NEXT ON YOUR JOURNEY
DISCUSSION · 0

Nobody has commented. Post a correction or another way to answer.