Skip to the page
Tecyfy

Agents interview question · hard

How would you estimate and cut the cost of an agent run?

The short answerEstimate it by turns: each turn resends the whole conversation as input, so input tokens grow with every step, and they dominate the bill.

The full answer

Estimate it by turns: each turn resends the whole conversation as input, so input tokens grow with every step, and they dominate the bill. Cost is roughly the sum over turns of (input tokens × input price + output tokens × output price). Cut it by caching the part that repeats, keeping the context small, using fewer turns and sending easy steps to a cheaper model.

Estimating

Take a run of 20 turns. The system prompt and tool definitions are 8,000 tokens, each turn adds about 1,500 tokens of tool results, and each reply is about 300 tokens.

  • Turn 1 sends about 8,000 input tokens. Turn 20 sends about 8,000 + 19 × 1,800 ≈ 42,000.
  • In total that is about 500,000 input tokens and 6,000 output tokens. Input is over 98% of the tokens, which is why "the model is cheap per token" can still mean an expensive agent.

Anthropic measured that agents use about 4 times the tokens of a chat, and multi-agent systems about 15 times. Measure your own: the Claude Agent SDK's result message reports total cost and usage per run. Then multiply by runs per day. The Tecyfy agent cost simulator at /prices/agent-cost does this sum with current prices.

Cutting it, biggest wins first

  1. Prompt caching. The system prompt and tools are the same on every turn. Mark them for caching. On the Claude API a cache read costs 0.1 times the normal input price on most models, while writing costs 1.25 times (5-minute lifetime) or 2 times (1 hour). Over 20 turns, the repeated prefix costs a fraction of the uncached price. Keep the cached part stable: a timestamp at the top of the prompt breaks the cache on every call.
  2. Smaller context. Return compact tool results, clear old ones (context editing), summarise long histories, and hand big searches to a subagent that returns only its findings.
  3. Fewer turns. Use tools that do a whole task in one call, allow parallel read-only calls, and give a clear definition of done.
  4. The right model for each step. Use a small, cheap model for routing, classifying and extracting, and the large model only where reasoning is hard. Lower the effort or thinking budget for routine steps.
  5. Limits. Set a per-run budget (max_budget_usd in the Agent SDK) so one bad run cannot cost 100 normal ones.
  6. Batch what can wait. Batch APIs cost less for work that need not finish in seconds.

What to say about trade-offs

Cheaper models and smaller contexts can lower the success rate, and a failed run that must be redone costs twice. Compare cost per successful task, not cost per run, on the same set of test tasks.

Last updated 16 October 2026