Agents, Tool Use & MCP·Question 18 of 90Intermediate

How do you make tool outputs token-efficient, and why does it matter so much for agents?

Type it the way you would explain it to an interviewer. A few sentences is enough; you can't break anything.

Model answer: the part to lead with

It matters because a tool result isn't paid for once - it sits in the context and is re-sent as input tokens on every subsequent loop iteration until compaction. A 20k-token JSON dump on iteration 2 of a 20-iteration trajectory costs ~360k cumulative input tokens, plus it actively degrades reasoning by burying signal (long-context "rot"). Result design is simultaneously cost, latency, and quality engineering.

Full worked answer

It matters because a tool result isn't paid for once - it sits in the context and is re-sent as input tokens on every subsequent loop iteration until compaction. A 20k-token JSON dump on iteration 2 of a 20-iteration trajectory costs ~360k cumulative input tokens, plus it actively degrades reasoning by burying signal (long-context "rot"). Result design is simultaneously cost, latency, and quality engineering.

Techniques:

  • Return what the model needs, not what the API returned. Strip metadata, deduplicate, flatten. Raw SaaS API responses are typically 10× larger than their useful content - filter fields in the tool, not in the model's head.
  • Semantic identifiers over opaque ones. "channel": "#eng-alerts" beats a UUID both in tokens and in downstream usability; models mistranscribe long opaque IDs.
  • Pagination and limits with signposts. Return the first N items plus "showing 20 of 4,312 - refine your query or pass page=2". The signpost matters: the model must know the result is truncated or it will reason over incomplete data as if complete.
  • A response_format parameter (concise | detailed) so the same tool serves quick checks and deep dives without two tools.
  • Offload large artifacts. Write the full result to a file or store and return a path/handle plus a short summary; provide read/grep tools for on-demand access. This is how code agents handle big files and how sub-agent results are typically integrated.
  • Hard caps in the harness. Truncate any result above a threshold (Claude Code, for instance, caps MCP tool output with a configurable limit, ~25k tokens by default) so one misbehaving tool can't blow the context.

Anti-pattern to name: teams optimise prompts for weeks while their search tool returns raw HTML. Reading a few production trajectories usually finds a 5× token saving in one afternoon of result-shaping.

What a good answer covers

  • It matters because a tool result isn't paid for once - it sits in the context and is re-sent as input…
  • A 20k-token JSON dump on iteration 2 of a 20-iteration trajectory costs ~360k cumulative input tokens,…
  • Result design is simultaneously cost, latency, and quality engineering
  • Return what the model needs, not what the API returned
  • Semantic identifiers over opaque ones

Key terms: Semantic identifiers over opaque ones · Pagination and limits with signposts · A response_format parameter · Offload large artifacts · Hard caps in the harness

Interviewer follow-ups to expect

  1. How does prompt caching change the cost math for bloated results?

  2. When is truncation actively dangerous?

Worked answer from AI-Engineer-Interview-Questions by Om (MIT), reformatted for LLM Prep · answer text last updated 6 November 2026 · scoring and review schedule by LLM Prep