Skip to content

Interview question · Optimizing & Tuning Agents

An agent task costs too much and takes 90 seconds. How do you cut both systematically?

The tempting answer is a cheaper model. The systematic one starts from the trace, finds where the tokens and seconds actually go, and pulls the cheapest lever first.

mediumNewUpdated Nov 2026

TL;DR: Measure before changing anything: per-step tokens, time and outcome from traces, on a fixed task set. Then work down the ladder: remove steps that never change the outcome, trim what tools return and what history is re-read, fix tool descriptions that cause repeated or wrong calls, cache the stable prefix, parallelise independent calls, and route easy steps to a smaller model with escalation. Accept each change only if success and reliability hold on the same tasks.

How to approach it

Treat it as a performance investigation: profile, find the dominant cost, fix it, re-measure. Say explicitly what you will not do first (change the model or fine-tune) and why.

A strong answer

Profile. From traces of, say, 100 representative tasks: steps per task, input and output tokens per step, time per step split into model, tool and harness, and the outcome. Long-run cost is dominated by input tokens because each step re-reads the history; latency is dominated by sequential model calls and slow tools.

Cut steps. Look for steps whose result never changes the outcome (a "double-check" call, a repeated search) and for fixed sequences the model rediscovers each time. Turn fixed parts into code; stop on a verified result.

Cut context. Trim tool results to the fields the next decision needs, clear stale results, compact long histories, move exploration into a subagent.

Fix tools. Repeated calls usually mean the result was ambiguous or truncated, or the error said nothing actionable. Sharpen descriptions and results; reduce the tools offered per task.

Cache, parallelise, route.

  • Keep the prompt prefix byte-identical so caching applies.
  • Run independent tool calls in parallel; latency becomes the slowest call, not the sum.
  • Route classification and extraction steps to a smaller model behind a check, escalating uncertain cases.
steps = [("plan", 2.1), ("search", 4.0), ("search", 4.2), ("lookup_order", 1.1),
         ("lookup_shipping", 1.3), ("decide", 2.4), ("verify", 2.0), ("reply", 1.6)]
baseline = sum(t for _, t in steps)
deduped = baseline - 4.2                      # the repeated search
parallel = deduped - min(1.1, 1.3)            # two independent lookups at once
dropped = parallel - 2.0                      # verify never changed an outcome
print(round(baseline, 1), round(dropped, 1))
# => 18.7 11.4

Three structural changes cut this trace's time by about 40% with the same model. The same changes cut tokens, because every removed step also removes a history re-read.

Only then the model. If cost is still too high, measure a smaller model or a router on the remaining steps against the same tasks; fine-tuning comes after that, for a stable, narrow step with a trusted grader.

Guard quality. Every change is accepted on success rate, pass^k and a hard slice of important tasks, not on cost alone.

What interviewers probe next

"What if the 90 seconds are mostly one slow tool?" Then the agent is not the problem: cache that tool's results, call it asynchronously, or change what is fetched.

"Would you stream the answer?" Streaming improves perceived latency for the user but not cost or completion time; do it in addition, not instead.

How it's scored

Weak: Switches to a cheaper model or fine-tunes first.

Hire: Profiles with traces, trims context and steps, adds caching.

Strong Hire: Profiles per step, works the ladder in order (steps, context, tools, caching, parallelism, routing, then weights), quantifies each change, protects quality with pass^k and a hard slice, and distinguishes perceived from actual latency.

Common mistakes

  • Optimising without a baseline on fixed tasks.
  • Reporting cost savings without the success rate.
  • Ignoring input tokens re-read every step.
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.