Delve · Field guide

Designing tools that AI agents can actually use

A practical field guide to schemas, context budgets, recoverable side effects, and trace-based evaluation.

Delve Editorial · AI Agents · 9 min

#tool-use #tool-calling #context-engineering #reliability #tracing

The short answer

Design agent tools as narrow, typed, text-described contracts whose boundaries and failure modes are explicit, then protect irreversible actions with idempotency and approval gates. The model can only select and operate what the catalog makes inferable, so names, schemas, outputs, and errors are part of the interface. Measure the resulting loop on traces, not on endpoint uptime.

The durable test is behavioral: can a trace show the model choosing the right tool among near-duplicates, filling valid arguments, recovering from a structured error, and stopping before an unrecoverable side effect? A tool that passes unit tests but fails that loop is not agent-ready.

01 · The contract

A tool is a typed contract the model must infer from text

An agent never sees your code; it sees a name, a description, a parameter schema, and whatever the call returns. Treat that bundle as the real API contract. The name should encode the verb and object (create_refund, not refund), and the description should say when to use it, when not to, what units and limits apply, and what the result means. Parameters belong in a typed schema with enums, formats, required fields, and explicit ranges; a free-text data object forces the model to guess.

The failure mode is not theoretical. In large, domain-specific tool inventories, ambiguous descriptions and under-specified schemas drive tool mis-selection and wrong slot values; jointly optimizing instructions and per-tool schema wording improved overall success by 5–20% relative over strong baselines . MCP-style registries make this concrete: each tool is registered with a name, description, and input/output schema . Hidden conventions that a human teammate would learn from code review are invisible to the model.

Design the return value as part of the contract, too. A compact object with stable field names and a clear status beats a verbose HTML or log dump. For a refund tool, return eligible, amount_cents, currency, and reason_code, not a paragraph the model must parse. The trade-off is description length: too little context creates ambiguity, while a 500-word preamble consumes attention and can bury the constraint that matters.

The model cannot infer what the schema does not say.

Schema wording is not a substitute for server-side validation.

02 · The catalog

Design for attention scarcity, not an unlimited API surface

Tool selection is an attention problem before it is an API problem. Every tool name, description, and parameter consumes context; long catalogs also increase latency and cost and make similar tools compete for the same intent. The model must compare candidates under uncertainty, so a 60-tool global namespace with get_user, fetch_user, lookup_customer, and find_account invites mis-selection. Namespacing by domain—billing.get_invoice, support.get_ticket—adds a cheap disambiguation cue.

Progressive disclosure beats a giant catalog. Expose a small set of high-level discovery tools, then load detailed schemas only for the namespace the agent selects. MCP-style servers already separate tools, resources, and prompt templates, which lets you keep static reference material out of the tool list . Paginate list results and return continuation tokens instead of dumping thousands of rows. Budgets for model turns, executed calls, and tokens make the cost of a sprawling catalog visible during a run .

The boundary condition: meta-tools add indirection. A search-then-invoke loop costs an extra model turn and can fail if the search tool is weak. For a stable five-tool workflow, direct tools are simpler and more reliable. There is no universal tool-count threshold; the practical test is whether a trace shows the model choosing among near-duplicates or exhausting context. The finding that performance degrades as inventories grow large and domain-specific supports the direction, not a specific cutoff .

A catalog is a UI for the model; every entry competes for attention.

No universal tool-count threshold is established; measure selection on your own traces.

03 · The side effects

Make failure legible and side effects reversible

Failure handling is where most agent tools break. An unstructured 500 error tells the model nothing; a structured error should say code, message, retryable, the offending field, and a suggested next action. Separate validation failures (fix the argument), permission failures (do not retry), transient failures (retry with backoff), and indeterminate outcomes (a write may have happened). The last category is the dangerous one.

Idempotency makes retries safe. Give every write a stable key derived from the run and validated call, or let the caller supply a business key such as an order number. once-gate sits between the agent and MCP tools, claims each action, returns the stored result for a repeat, and refuses with INDETERMINATE when a call started but never finished, forcing human review . agent-runloop similarly pauses write tools for approval, checks authorization from trusted run context, and exposes a stable call id for idempotency .

Preview modes and approval gates reduce irreversible mistakes. A preview_refund call can show eligibility and exact amount before submit_refund; a threshold can require human approval above a set value. The trade-off is approval fatigue: gate too many low-risk reads and humans start rubber-stamping. Approval must be exact-content, not a generic “allow all.” The caveat is that idempotency keys only work if the server honors them consistently; a proxy can deduplicate, but the underlying system still needs a correct uniqueness constraint.

A retry is only safe when the system can recognize the same action.

Approval is not a substitute for authorization; check permissions from trusted context before asking a human.

04 · The evidence

Measure tool usability through traces, not endpoint uptime

Endpoint uptime says almost nothing about tool usability. The unit of quality is the model-tool loop: did the agent choose the right tool, fill valid arguments, execute without error, recover when it failed, and finish the task without unnecessary calls? A tool can be 99.9% available and still be unusable if its description collides with three neighbors.

Trace every model call and tool call, then label failures by cause. pyagenteval records each step and reports right-tool rate, valid-argument rate, execution success, retries, latency, and cost, with failure labels for tool errors, timeouts, rate limits, and truncated answers . That separation matters: “68% correct” and “100% correct, 32% blocked by rate limits” are different engineering problems. agent-runloop’s audit rows and per-execution version hashes support the same discipline: you can attribute a regression to a tool-schema change or a model change .

Build a held-out evaluation set from real traces, including near-duplicate tools, ambiguous requests, malformed arguments, and adversarial tool outputs. Replay it after every description or schema edit. The trade-off is overfitting: optimizing descriptions against a small benchmark can improve that benchmark while making the catalog brittle. Keep a fresh slice and inspect traces, not just aggregate scores. The strongest caveat is that no public benchmark establishes a universal target for tool-selection accuracy; your threshold should come from task risk and human review capacity.

Tool quality is a property of the loop, not the endpoint.

Aggregate pass rates hide whether the agent selected the right tool for the right reason.

05 · The reference

Apply the model to a refund agent and mark its limits

Consider a refund agent. Its read tools should be narrow and safe: get_order, get_customer, and list_refunds, each returning only the fields needed for eligibility. The write surface should be one explicit tool, create_refund, with order_id, amount_cents bounded by the order total, a reason_code enum, and a required idempotency_key. Add preview_refund to show the exact effect before commitment. Route amounts below a threshold automatically; pause above it for exact-content human approval. Store the approval and the resulting refund id in an audit row . If a submission times out, return an indeterminate state and require a human release rather than retrying blindly .

This design works because it separates inference from authority. The model can read, propose, and explain; the system enforces permissions, bounds, idempotency, and approval from trusted context . Tool output should be delimited and labelled as data, with the original task restated, because a refund reason or customer note can contain prompt injection .

The limits matter. Atomic tools are the wrong abstraction when a task has a hard invariant spanning several calls—for example, “refund and restock only if the item is received.” A deterministic workflow or a higher-level tool with a transactional boundary is safer than hoping the model sequences primitives correctly. MCP servers improve discovery and reuse, but they are not a security boundary by themselves. And tool sprawl returns through the back door: every new convenience tool adds selection cost.

Separate what the model may infer from what the system will allow.

The reference design is a pattern, not a compliance blueprint; refund rules vary by jurisdiction and payment processor.

Naive endpoint wrapper vs agent-ready tool

The same underlying API can be exposed in ways that either help or defeat an agent’s selection and recovery loop.

DimensionNaive wrapperAgent-ready toolBoundary condition
DescriptionFunction name and autogenerated docsVerb-object name, use/avoid guidance, units, examplesLong prose still crowds context
ParametersFree-form object or untyped fieldsTyped schema with enums, ranges, required fieldsServer must validate anyway
ErrorsRaw stack trace or generic 500Structured code, retryability, field, next actionIndeterminate writes need human review
Side effectsDirect write on every callIdempotency key, preview, approval gateLow-risk reads may skip approval
EvaluationEndpoint uptime and latencyTrace-based selection, argument, recovery metricsSmall benchmarks can overfit

Common misconceptions

  • More tools give the agent more capability. Beyond a point, each tool adds selection ambiguity and context cost; a smaller, well-namespaced catalog or progressive disclosure often performs better.
  • A good description is just documentation. For an agent, description and schema are control surface; ambiguous wording changes which tool is called and which arguments are filled.
  • Retries make writes reliable. Blind retries duplicate side effects; idempotency keys and indeterminate-outcome handling make retries safe.
  • Human approval solves safety. Approval fatigue and prompt injection can defeat it; approvals must be exact-content and backed by trusted authorization.

Ship a trace-tested tool, not a wrapper

Treat the model-facing contract and the safety boundary as one design problem.

Write the contract in model-facing text

Draft the name, description, schema, and return shape before implementation. Include when to use the tool, when not to, units, ranges, and one realistic example.

Cut and namespace the catalog

Remove near-duplicate tools, group the rest by domain, and test whether the model can choose correctly among the remaining candidates.

Make writes idempotent and previewable

Require a stable idempotency key for every side-effecting call and add a preview path that shows the exact effect before commitment.

Gate irreversible actions

Place exact-content approval before high-value writes, check authorization from trusted context, and return an indeterminate state on ambiguous timeouts.

Evaluate on recorded traces

Collect real tool-call logs, label failures by cause, and replay a held-out set after every schema or description change.

What would change my mind: A controlled study showing that large flat catalogs with verbose descriptions match small curated catalogs on selection accuracy, recovery, and task completion would weaken the attention-scarcity argument.

Recall check

An agent with 40 tools keeps calling `fetch_customer` when it needs billing history. Descriptions are one line each. What is the most likely design defect?

  1. The model lacks a system prompt
  2. The tool schemas use JSON Schema
  3. Similar tool names and thin descriptions do not encode use boundaries
  4. The API lacks a rate limit

The catalog is forcing the model to infer distinctions that the names and descriptions do not state; selection ambiguity is a contract problem before it is a model problem.

A `charge_card` call times out after the request was sent. The tool returns a generic timeout. What should the agent-facing response do?

  1. Tell the model to retry immediately
  2. Return an indeterminate outcome and require human review or idempotent lookup
  3. Hide the error and return success
  4. Switch to a different payment tool

A timeout after dispatch means the side effect may have happened. The safe response is to mark the outcome indeterminate and resolve it with idempotent lookup or human review.

Which metric best captures whether an agent can use a tool catalog?

  1. Endpoint uptime
  2. Average response latency
  3. Number of tools exposed
  4. Right-tool selection plus valid arguments and task completion on held-out traces

Uptime and latency measure the endpoint, not the model-tool loop. Selection, argument validity, recovery, and completion are properties of the interaction.

Open questions

  • What tool-count and description-length thresholds generalize across models and domains? Teams need practical limits for catalog design, but current evidence is practitioner experience rather than controlled measurement.
  • How should approval interfaces present exact content without causing fatigue? Approval gates only work if humans actually inspect them, and the wrong interface can turn safety into a rubber stamp.
  • Can agents reliably resolve indeterminate writes without human review? Autonomous recovery would unlock more automation, but mistaken resolution can duplicate or lose money.

Sources

Browse all public guides