Skip to content

Interview question · Agent Runtime & Sandboxes

Your forty-turn agent is slow and expensive. Where do the seconds and dollars go?

Dollars go to input tokens, because every turn rereads everything before it. Seconds go to generation and tool calls, often in series. You find out which by reading the trace, not by guessing.

mediumEssentialNewUpdated Nov 2026

TL;DR: Pull per-turn data from traces and split it four ways: input tokens (cached and uncached), output tokens, tool time and orchestration. Money almost always goes to input, which grows with the square of turn count, so the fixes are trimming tool results, clearing used ones, caching a stable prefix and cutting turns. Time usually goes to generation and to tools called in series, so the fixes are parallel independent calls, shorter outputs on intermediate steps and fewer turns. Rank fixes by measured share, then verify the saving and the quality.

How to approach it

Refuse to guess; describe how you would measure, what the breakdown usually shows for agents, and the fix for each component, ranked.

A strong answer

Measure from the trace. For a sample of runs: per turn, input tokens (cached and uncached), output tokens, model latency (time to first token and total), each tool call's duration, and time between steps. Sum per component across the run.

TURNS = [  # illustrative trace summary per turn
    {"in": 8000 + 2500 * t, "cached": 0.0, "out": 300, "model_s": 6.0,
     "tools_s": [1.2, 0.9, 1.5]}
    for t in range(40)
]

def breakdown(turns, in_price=3.0, out_price=15.0):
    cost_in = sum(t["in"] * (1 - t["cached"]) for t in turns) * in_price / 1e6
    cost_out = sum(t["out"] for t in turns) * out_price / 1e6
    model_s = sum(t["model_s"] for t in turns)
    tools_s = sum(sum(t["tools_s"]) for t in turns)
    return round(cost_in, 2), round(cost_out, 2), round(model_s), round(tools_s)

print(breakdown(TURNS))  # => (6.81, 0.18, 240, 144)

What it shows. Input is about $6.81 of about $7 per run, so output pricing is irrelevant to the bill. Of roughly 384 seconds, model calls take 240 (mostly generating 300 tokens a turn) and tools in series 144.

Fixes for dollars, ranked.

  1. Trim tool results at the source and clear used ones: shrinks the growth term that every later turn pays.
  2. Cache a stable prefix with append-only history: most input becomes cheap reads.
  3. Cut turns: better tool design (one call instead of three), budgets, stopping rules.
  4. Route routine steps to a smaller model, measured per step type.

Fixes for seconds, ranked.

  1. Run independent tool calls in parallel: 144 seconds of serial tool time could become about 60.
  2. Shorter intermediate outputs: the model does not need 300 tokens of narration between tool calls.
  3. Fewer turns: every turn removed saves both.
  4. Caching: lowers time to first token on long contexts.

Verify. Re-run the same tasks after each change and compare cost, time and quality, because trimming results or routing steps can remove information the model needed without any error to show it.

What interviewers probe next

"Would a faster model fix it?" It shortens generation time, a real share here, but leaves tools in series and input cost untouched. Pick it only if the measurement says generation dominates and quality holds.

"Where does orchestration overhead show up?" As gaps between spans in the trace: queueing, serialisation, cold starts. Usually small, occasionally a surprise worth checking.

"How do you keep it from regressing?" Cost and latency per task on the release dashboard and in the eval report, with alerts on step changes.

What if?

What if · interview follow-ups

Hold your answer as the constraints change

Traces show input tokens are 95% of cost and serial tools are a third of wall-clock.

  1. Start here

    What if caching is enabled but the cached share is near zero?

How it's scored

Weak: Suggests a cheaper or faster model.

Hire: Identifies input tokens as the main cost and adds caching and result trimming.

Strong Hire: Measures per-turn components from traces, explains the quadratic input growth, ranks separate fixes for cost and time, includes parallel and merged tools and shorter intermediate outputs, routes by step type, and verifies quality after each change.

Common mistakes

  • Optimising output price for an input-dominated bill.
  • Turning on caching without checking the cached share.
  • Shrinking tool results without re-measuring quality.
  • Treating latency and cost as one problem with one fix.
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.