Topic 3 of 6 · 5 min read
Compact, high-signal tool outputs
Goal: Redesign a tool response that floods the context so it returns only the fields the agent needs, with a way to get more.
Return the smallest response that lets the agent take its next step, and give it a way to ask for more. Every token a tool returns stays in the context window for the rest of the run, and the model has to read all of it.
Check yourself · 1 of 3
A tool returns 20 of 312 matching tickets and says nothing about the rest. What is the likely result?
Why it matters
Agents do not skim. A tool that dumps a 400-field API record forces the model to find the three fields that matter, costs money on every later turn, and pushes earlier instructions and results further from the model's attention. Long contexts also make models more likely to miss details. A tool built for a program (every field, every id) is not built for an agent.
How to do it
- Pick the fields the task needs. Drop internal flags, audit timestamps and nested objects nobody asked for.
- Prefer names to opaque ids. Return
"assignee": "Dana Reyes"rather than"assignee_id": "u_8f3c2a"when the agent needs to reason about people. Keep the id too when a follow-up call needs it. - Paginate and filter. Default to a modest page size, accept a filter, and return a cursor. Say how many results exist in total.
- Truncate with a hint. When you cut output, say so and say how to get the rest: "Showing 20 of 312. Narrow with
statusor passcursor: abc." - Offer a response mode. A
detailparameter withconcise(default) andfulllets the agent pay for detail only when it needs it. - Set a hard cap on response size so one bad query cannot fill the window.
Before and after
{ "id": "t_91", "created_by": "u_8f3c2a", "created_at": 1741954000, "updated_at": 1741957310,
"workflow_state_id": 4, "labels": [12, 40], "metadata": { "...": "60 more lines" } }
An agent asking "which tickets are open?" must decode ids and ignore the rest. Concise form:
{ "total": 312, "showing": 20, "next_cursor": "c_20",
"tickets": [ { "id": "t_91", "title": "Login fails on Safari", "status": "open", "assignee": "Dana Reyes" } ] }
What goes wrong
- Silent truncation. Cutting at 10 results without saying so makes the agent believe there are only 10.
- Pagination with no total. The agent cannot decide whether to keep paging.
- Everything is a mode. Five
detaillevels is a new decision the model has to make each call. Two is enough.
Examples
Truncation that tells the truth
Showing 20 of 312 matches for "timeout". Results are sorted by newest.
To narrow, add `status` or `service`. To continue, call again with cursor "c_20".
The agent knows the list is partial, how large the full set is and two ways to proceed. Without that line it would treat 20 as the full answer.
A response-format parameter
"detail": { "type": "string", "enum": ["concise", "full"], "default": "concise",
"description": "concise: id, title, status. full: adds body, comments and history." }
The agent triages with concise and calls full for the one ticket it must read closely.
Key points
- Tool output stays in context for the rest of the run, so size is a cost on every later turn.
- Return the fields the next step needs and drop the rest of the raw API record.
- Replace opaque ids with readable names where the agent must reason, and keep ids for follow-up calls.
- Paginate with a sensible default, report the total and tell the agent how to fetch more.
- A
concise/fullresponse mode lets the agent pay for detail only when it needs it.
Common mistakes
- Returning the raw API response because it was easy, with dozens of fields the agent never uses.
- Truncating or paginating without saying so, so the agent treats a partial list as complete.
- Returning only opaque ids and forcing the agent to make extra calls to learn what they mean.
- Setting no size cap, so one broad query returns tens of thousands of tokens.
Check yourself · 2 of 3
Which response is better for an agent deciding which ticket to open?
Check yourself · 3 of 3
What does a detail parameter with concise and full values give the agent?
Practice items, not counted towards your mastery.
Start here
- Writing effective tools for AI agents (Anthropic) (opens in a new tab)ArticleFree
Naming, namespacing, response design and evaluation loops for agent tools, from a team that builds them.
- Introducing advanced tool use (Anthropic) (opens in a new tab)ArticleFree
Tool search, programmatic calling and tool use examples for large toolsets.
- Define tools (Claude API docs) (opens in a new tab)DocsFree
How a tool definition is structured: name, description, input schema and examples.