Skip to content

Writing effective tools for agents — with agents

optionalcorefundamentalblogrubric 10/122025 · Anthropic Engineering blog · ~25 min

Ken Aizawa

Status

TL;DR. A tool is a contract between deterministic software and a non-deterministic agent, so it should be designed for the agent, not copied from an API. The essay gives a process (prototype the tools, generate realistic multi-call evaluation tasks, run agents in simple loops, read transcripts and metrics, often with an agent’s help, then refine and check on held-out tasks) and the principles that process tends to produce: choose a few consolidated tools, namespace them, return meaningful context, keep responses token-efficient, write error messages that steer, and write descriptions as you would for a new hire.

Why it matters now. For a search agent, the retriever is a tool, and how it is exposed (how many results, what fields, how long the snippets, what happens on a bad query) shapes what the agent can do as much as the retriever’s quality does. RL-trained search agents learn against a fixed tool interface, so a badly designed interface caps what training can achieve. The essay is also a practical recipe for evaluation-driven tool design that carries over directly to building search tools for BrowseComp-Plus-style agents.

Writing tools for agents: an evaluation-driven loop, and the design rules it tends to produce Left: a loop of five steps. Build a quick prototype of the tools, for example as a local MCP server. Generate realistic evaluation tasks that need several tool calls, each with a verifiable answer. Run each task in a simple while-loop agent that writes reasoning and feedback before acting, and record accuracy, runtime, number of calls, tokens and errors. Read transcripts and metrics, possibly by pasting transcripts into a coding agent. Refine tool names, descriptions and responses, then repeat; check final gains on a held-out task set. Right: the design rules the essay reports. Prefer a few consolidated tools such as search contacts over list contacts. Namespace related tools by service or resource. Return meaningful fields and names rather than opaque identifiers. Keep responses token-efficient with pagination, filtering and truncation and a concise or detailed response format, where the concise Slack example used 72 tokens versus 206. Write errors that tell the agent what to do next, and write descriptions as if for a new hire, with unambiguous parameter names such as user id. Tools are a contract with a non-deterministic user: evaluate, then refine 1 Prototype wrap in a local MCP server; try them 2 Realistic tasks multi-call, with verifiable answers 3 Run in while-loops agent writes reasoning + feedback; log accuracy, calls, tokens, errors 4 Read transcripts and metrics or paste them into a coding agent 5 Refine names, descriptions, outputs confirm gains on a held-out task set repeat until performance on real tasks is strong What the loop tends to produce • few consolidated tools: search_contacts, (not list_contacts); search_logs • namespaces by service or resource (asana_search, jira_search) • meaningful fields: names, not UUIDs • token-efficient: paginate, filter, cut; response_format concise (72 tokens) vs detailed (206 tokens) in a Slack example • errors that say what to do next • describe tools as for a new hire; user_id, not user • annotate open-world or destructive tools Claude Code caps tool output at 25k tokens by default
Original sketch. The evaluation loop on the left and the design principles it produced on the right. Token counts are the essay's Slack example.

Problem. Agents can call a tool, answer from memory or ask a clarifying question, and they sometimes misuse tools or hallucinate arguments. Tools designed for deterministic programs (many fine-grained endpoints, opaque IDs, unlimited output) often waste the agent’s limited context and invite errors. How do you design tools that agents use well, and know that you did?

The process.

  1. Prototype. Write the tools quickly (Claude Code can help, given the library docs), wrap them in a local MCP server or desktop extension, and try them yourself.
  2. Generate evaluation tasks grounded in real use. Strong tasks need several tool calls on realistic data (for example: find all log entries for a customer charged three times and check whether other customers were affected). Weak tasks are one-call lookups with the answer spelled out (search the logs for a given event and customer id). Pair each task with a verifiable answer; avoid verifiers so strict that they reject correct answers over formatting; don’t over-specify which tools must be called.
  3. Run each task in a simple while-loop of LLM and tool calls. Ask the agent to write reasoning and feedback blocks before tool calls. Record accuracy plus runtime, number of calls, tokens and tool errors.
  4. Analyse. Read reasoning, feedback and raw transcripts. Many redundant calls suggest pagination or limits need adjusting; many invalid-parameter errors suggest unclear descriptions. You can paste the concatenated transcripts into Claude Code and let it refactor the tools.
  5. Refine and hold out. Check improvements on a held-out task set so you do not overfit the tools to the evaluation tasks.

The principles.

  • Choose the right tools. More tools are not better. Build a few tools for high-impact workflows: search_contacts instead of list_contacts; schedule_event instead of separate tools for listing users, listing events and creating events; search_logs instead of read_logs; get_customer_context instead of three lookups.
  • Namespace related tools by service and resource (asana_search, jira_search). Choosing prefix or suffix naming had non-trivial effects in their evaluations, and the effect varies by model.
  • Return meaningful context. Prefer name, image_url, file_type over uuid, 256px_image_url, mime_type. Resolving opaque UUIDs to meaningful names, or even a 0-indexed ID scheme, significantly improved Claude’s precision in retrieval tasks by reducing hallucinations. A response_format parameter lets the agent pick concise or detailed output; detailed includes the IDs needed for follow-up calls.
  • Be token-efficient. Use pagination, range selection, filtering and truncation with sensible defaults. Claude Code limits tool responses to 25,000 tokens by default. When truncating, say so and encourage more targeted calls.
  • Write errors that steer. An input-validation error should say specifically what was wrong and how to fix it, ideally with an example, rather than returning an opaque code.
  • Prompt-engineer descriptions. Describe the tool as for a new hire: make implicit context (query formats, terms, relationships) explicit, and name parameters unambiguously (user_id, not user). The essay credits precise description refinements for Claude Sonnet 3.5’s state-of-the-art SWE-bench Verified result.
  • Annotate MCP tools that need open-world access or make destructive changes.

Worked example (illustrative arithmetic on the essay’s numbers). The essay’s Slack example returns 206 tokens in detailed mode and 72 in concise mode. Over 40 calls:

40×206=8,240vs.40×72=2,880.40 \times 206 = 8{,}240 \quad\text{vs.}\quad 40 \times 72 = 2{,}880 .

If only a quarter of calls need IDs, 10×206+30×72=4,22010 \times 206 + 30 \times 72 = 4{,}220 tokens. A list_contacts tool returning 2,000 contacts at about 30 tokens each would need 60,000 tokens, more than twice Claude Code’s default cap, while a search_contacts tool returning five hits needs about 150.

An example of analysis paying off. When launching Claude’s web search tool, the team saw Claude needlessly appending 2025 to search queries, which biased results and hurt performance. Improving the tool description fixed it. For an IR reader, this is a query-formulation bias introduced by the agent, found only by reading the queries it actually issued.

Before (API-shaped tools)Agent-shaped tools
GranularityOne tool per endpointA few consolidated, workflow-level tools
OutputEverything, with technical IDsRelevant fields, names, concise or detailed on request
SizeUnlimitedPaginated, filtered, truncated with guidance
ErrorsCodes and tracebacksSpecific, actionable messages
What did not changeThe model; the backend functionality
EvidenceInternal held-out Slack and Asana evaluations (charts only); the web-search query fix; SWE-bench Verified

All results are vendor-reported on internal evaluations.

  • Held-out Slack and Asana tools: tools refined with Claude’s help performed better on held-out tasks than “expert” implementations written by researchers or generated by Claude (shown as charts without exact numbers).
  • Response format: in the Slack example, concise responses used 72 tokens against 206 for detailed, about a third.
  • Web search tool: the needless 2025 suffix on queries was removed by improving the description.
  • SWE-bench Verified: Claude Sonnet 3.5 reached state-of-the-art after precise refinements to tool descriptions.
  • Evidence is internal and mostly qualitative. The held-out results are charts without task counts or variance, and the description changes behind the SWE-bench result are not isolated by an ablation.
  • Tuned to one model. Tools refined by Claude on Claude transcripts may encode Claude’s preferences; the essay itself says naming effects vary by model.
  • Consolidation vs. composition. The essay favours workflow-level tools. Code-as-action approaches let the agent compose fine-grained tools itself, which moves the design choice elsewhere rather than settling it.
  • MCP standardises connection, not quality or safety. A tool exposed over MCP can still be badly designed or unsafe; annotations only declare open-world or destructive behaviour.
  • Open question for RL. If the tool interface changes after an agent is trained with RL, how much of the learned policy transfers? Should tool design and policy be optimised jointly?
  • SWE-agent: an academic study of the agent-computer interface, with a windowed file viewer, a linted edit command and summarised search, and ablations at a fixed model.
  • CodeAct: executable Python as the action space, so the agent composes tools itself with loops and variables, and interpreter errors become observations.
  • Toolformer: models learning when to call simple APIs, the opposite end from hand-designed agent tools.
  • Building effective agents: the essay that introduced the ACI and poka-yoke advice this one expands.
  • Effective context engineering: why token-efficient tool responses matter.
  • Search API comparisons: how the search tool behind an agent changes results.

Questions to think through

These questions have no single right answer. Write or say your answer before you open the hints. Mark a question once you could defend your answer in a reading group.

  1. Derive / compute

    Use the essay's Slack example: a detailed response costs 206 tokens and a concise one 72. An agent makes 40 such calls in a task. Compute the total tool-output tokens if every call is detailed, if every call is concise, and if a quarter of the calls need the detailed format because the next call needs IDs. Then compare a list_contacts tool returning 2,000 contacts at about 30 tokens each with a search_contacts tool returning the top 5, against Claude Code's default 25,000-token cap on tool responses.

    What a strong answer covers
    • All detailed: 40 × 206 = 8,240 tokens. All concise: 40 × 72 = 2,880, about 35% of the detailed cost (the essay's "about a third").
    • Mixed: 10 × 206 + 30 × 72 = 2,060 + 2,160 = 4,220 tokens, so letting the agent choose the format saves about half.
    • list_contacts: 2,000 × 30 = 60,000 tokens, more than twice the 25,000 cap, so it would be truncated and the target may be cut off.
    • search_contacts top-5: about 150 tokens, a 400× reduction, because the filtering happens in the tool instead of in the model's context.
    • A truncated response should say it was truncated and suggest a narrower query or a filter, so the agent can recover.
  2. Mechanism

    The essay argues that tools which simply wrap existing API endpoints are often a poor fit for agents, using the address-book example. Explain the mechanism: what differs between a program's and an agent's affordances, why consolidated tools like schedule_event or get_customer_context help, and how this connects to the context-efficiency argument.

    What a strong answer covers
    • Programs can iterate over a long list cheaply in memory; an agent must read every returned token in its limited context, which is like reading an address book page by page.
    • A search tool lets the agent skip to the relevant entry, as a human would, instead of brute-force reading.
    • Consolidated tools perform several API calls internally (find availability and create an event; gather a customer's recent records), so intermediate results never enter the context.
    • Fewer, distinct tools also reduce ambiguity in tool choice, which wastes calls and context when several tools overlap.
    • The trade-off is flexibility: a consolidated tool hard-codes a workflow, so it should target high-impact workflows that match the evaluation tasks.
  3. Critique

    The essay reports that tools refined by Claude, using transcripts from Claude-driven evaluations, beat "expert" human-written tools on held-out Slack and Asana tasks, and that small description refinements helped Claude Sonnet 3.5 reach state-of-the-art on SWE-bench Verified. Critique this evidence: what could the held-out sets fail to protect against, and what would you need to see before generalising the gains to other models?

    What a strong answer covers
    • The held-out tasks come from the same internal workflows and task generator, so they protect against overfitting to specific tasks but not to the task distribution.
    • Tools tuned by Claude on Claude transcripts may be tuned to Claude's quirks; the essay itself notes that prefix versus suffix namespacing effects vary by model.
    • The results are shown as internal charts without task counts, variance or significance, so effect sizes are hard to judge.
    • SWE-bench state-of-the-art bundles model, scaffold and tools; the description refinements are not isolated in a reported ablation.
    • Generalising needs evaluation with other model families on public tasks, at fixed prompts, with several runs per task.
  4. What if…

    The essay claims that resolving opaque UUIDs to meaningful names, or even to a 0-indexed ID scheme, significantly improves Claude's precision in retrieval tasks by reducing hallucinations. Design an ablation that tests this for a search agent that must cite documents, and say what you would measure to separate hallucinated IDs from wrong-but-real IDs.

    What a strong answer covers
    • Arms: raw UUID document ids, short integer ids (0-indexed per result list), stable short ids across the session, and titles plus ids, with identical content otherwise.
    • Measure the rate of cited ids that do not exist (hallucinated), ids that exist but are not relevant (wrong), and correct citations.
    • Also measure follow-up call errors (for example, get_document with an invalid id) and tokens per task.
    • Per-list 0-indexed ids can collide across searches; test whether ambiguity between lists creates a new error type.
    • Run several trials per task and compare with paired tests, since the expected differences per task are small.
  5. Design

    Design the tool set for an agent that answers BrowseComp-Plus questions over its fixed corpus. Specify the tools, their parameters and defaults, what each returns in concise and detailed modes, how truncation and errors steer the agent, and how you would evaluate the tool set following the essay's loop.

    What a strong answer covers
    • A search tool with query, k (small default, such as 5–10) and response_format: concise returns titles and short snippets with short document ids; detailed adds scores and full metadata.
    • A get_document tool with document id and an optional range or a query to return only matching passages, so long documents do not flood the context.
    • Truncation messages state what was cut and suggest a narrower query or a page range; errors for invalid ids list how to obtain a valid one.
    • Descriptions written for a new hire: what the corpus contains, what query styles work (short keyword queries), unambiguous parameter names such as document_id.
    • Evaluate with realistic multi-hop tasks, log calls, tokens and errors, read transcripts, refine, and confirm on held-out questions using answer accuracy and evidence recall.
  6. Connect

    Compare the essay's advice with two academic takes on the agent-computer interface: SWE-agent's purpose-built shell commands (a windowed file viewer, an edit command with a linter, summarised search) and CodeAct's use of executable Python as the action space. Where do they agree with the essay, and where does CodeAct suggest a different answer to the consolidation question?

    What a strong answer covers
    • SWE-agent agrees closely: small, LM-oriented commands, compact and informative outputs, and guardrails that reject bad edits are the essay's token-efficiency, error-message and poka-yoke ideas.
    • SWE-agent's ablations change the interface with the model fixed, the kind of controlled evidence the essay mostly lacks.
    • CodeAct lets the agent compose many tools in one action with loops and variables, so the agent, not the tool designer, does the consolidation.
    • This shifts design effort from writing workflow-specific tools to exposing clean, well-documented primitives plus an interpreter whose errors are informative.
    • Both still need token-efficient outputs: a code action that prints a large result has the same context cost as a large tool response.

Done with this page?

Status