Katkat

Designing Tools an Agent Can Use

By the Katkat team · Updated · 8 min read

Quick overview

Learn how to design tools for LLM agents: naming, schemas, error messages, idempotency and tool granularity, with worked examples for interviews.

Lesson 28 of 88 · AI Engineering Interview Course

After this lesson you will be able to explain why a tool definition is really a prompt, and how naming, schemas, error messages, idempotency and granularity decide whether an agent succeeds or flails. You will be able to critique a tool set in an interview and propose a better one with concrete reasons. The mechanics of the loop itself are in Tool Calling and the Agent Loop; this lesson is about the interface the loop calls.

A tool is a prompt the model reads

The model never sees your code. It sees a name, a natural-language description and a parameter schema (usually JSON Schema), and it decides from that text alone whether to call the tool and with which arguments. Then it reads whatever string you return. Every part of tool design is therefore writing for a reader that is capable but has no context beyond what you give it.

Two consequences follow:

  • Definitions cost tokens on every call. Assume roughly 250 tokens per definition (name, description, schema). With 30 tools that is 30 × 250 = 7,500 tokens per request. In a 10-step loop the model is sent that block 10 times: 75,000 input tokens. With 8 tools it is 8 × 250 × 10 = 20,000. Prompt caching can reduce the price of the repeated block, but not the space it takes in the context window or the confusion from many similar options.
  • Selection accuracy drops as tools multiply, especially when tools overlap. This is the main argument for fewer, clearer tools.

Naming and descriptions

A name should say what the tool does in the vocabulary the model and your domain share. A description should say what it does, when to use it, and when not to.

WeakBetterWhy
processissue_refundThe verb and object are explicit.
get_dataget_order_detailsSays which data.
search and lookup and findsearch_orders and get_order_by_idOverlapping names force a coin flip; distinct names make the boundary clear.
doStuffV2cancel_subscriptionVersion suffixes and internal jargon carry no meaning.

Practical rules:

  • Use one naming convention (for example verb_noun in snake_case) across the whole set.
  • Put the disambiguating guidance in the description: "Use this when you have an order ID. If you only have a customer email, use search_orders first."
  • State side effects plainly: "Sends an email to the customer. Cannot be undone."
  • Keep descriptions to a few sentences. A paragraph per tool multiplies the token cost above.

Schemas: make wrong calls hard to express

The schema is your first line of validation and your best documentation. Prefer structure over free text:

  • Enums over strings for closed sets: "status": {"enum": ["open", "shipped", "cancelled"]}.
  • Describe every parameter, including format and units: "amount_cents: integer, refund amount in cents, e.g. 4000 for $40.00." Ambiguous units (dollars versus cents) are a classic source of silent errors.
  • Mark required fields honestly and give defaults for optional ones, so the model does not invent values.
  • Keep it flat. Deeply nested objects and unions are where models produce malformed arguments most often.
  • Take identifiers the model can actually have. If a parameter is order_id, some earlier tool output or user message must supply it. If the model must guess an ID, it will.

Validate on the server anyway. Models can still emit missing fields, wrong types or out-of-range values, and a schema is a hint, not a guarantee. For more on getting well-formed arguments, see Getting Reliable JSON and Structured Output.

Results and error messages

What you return is the next prompt. Design it deliberately.

Successful results. Return what the model needs for its next decision, not your whole database row. Use readable field names, include the IDs it will need for follow-up calls, cap the size, and paginate with an explicit "3 of 120 results shown; pass cursor for more". A 50,000-token blob wastes context and buries the answer.

Errors. Return errors as normal tool results (flagged as errors) instead of crashing the loop, so the model can recover. A good error says what went wrong, why, and what to try next.

Poor errorActionable error
Error 400Invalid date_range: end_date (2024-03-01) is before start_date (2024-03-15). Swap them or pick a later end_date.
Not foundNo order with id "88412". Order IDs are 6 digits starting with 8, e.g. "884120". Use search_orders if you only have an email.
Full stack tracePayment service is temporarily unavailable. This is retryable; wait and try again once.

Distinguish clearly between errors the model can fix by changing arguments, errors that are transient and retryable, and errors that are permanent and should be reported to the user. Never leak stack traces, internal hostnames or secrets in error text. Retry and timeout policy beyond the tool boundary belongs in the harness; see Making Agents Reliable.

Idempotency: assume every call may happen twice

Agent loops retry. A request times out, the harness resends it, or the model decides to "try again" because it never saw the response. For read-only tools this is harmless. For tools with side effects it is a bug waiting to happen.

Worked example. An agent calls issue_refund(order_id="884120", amount_cents=4000). The payment provider processes it, but the response is lost to a timeout. The harness retries.

  • Without protection: two refunds of $40.00, so $80.00 leaves the account.
  • With an idempotency key: the call includes idempotency_key = "refund:884120:ticket-5512". The server stores the key with the first result. On the retry it sees the key, performs nothing, and returns the original result with "already_processed": true. Total refunded: $40.00.

Design guidance:

  • Derive the key from the business intent (order, ticket, action), not from a random value generated per attempt. A fresh random key on each retry defeats the purpose. Generating the key in the harness rather than asking the model to invent one is usually more reliable.
  • Prefer naturally idempotent operations: "set status to cancelled" instead of "toggle status".
  • For irreversible or high-impact actions, add a confirmation step or human approval; see Agent Safety.
  • Make the tool's response say what happened ("created", "already existed"), so the model does not repeat the action.

Granularity: how big should a tool be?

Too fine and the agent needs many round trips; too coarse and it becomes rigid or dangerous.

StyleExampleStrengthsWeaknesses
Fine-grained (API mirror)get_customer, list_orders, get_order, get_item, ...Flexible, composableMany calls, long chains, large tool count
Task-levelget_order_summary (order, items, shipping status)Few calls, easy to selectLess flexible; you must anticipate tasks
Mega-toolmanage_order(action=..., ...)Few definitionsParameters depend on action; the schema becomes confusing and hard to validate

Worked example. Suppose answering "Where is my order?" needs customer, order and shipment data. Assumptions for illustration: each model round trip takes 1.5 s and each step succeeds 95% of the time.

  • Three fine-grained calls in sequence: 3 × 1.5 s = 4.5 s, and success is 0.95³ ≈ 0.857.
  • One task-level get_order_status call: 1.5 s, success 0.95.

The task-level tool is three times faster and about 9 points more reliable under these assumptions, because the deterministic joining happens in your code instead of in model reasoning. The same logic does not mean "merge everything": a tool that both reads and deletes is dangerous, and a tool with a dozen modes is hard to describe.

A reasonable rule: one tool per meaningful, user-level operation, with reads and writes separated, and a single clear purpose per tool. Do not expose an internal REST API one-to-one. If the set still grows large, group tools by domain and load only the relevant group per task, or route to a specialist. Standard protocols such as MCP make it easy to expose many tools, which is exactly why curation matters.

Testing tool design

Tool design is empirical. Collect realistic tasks, run the agent, and read the transcripts: which tool did it pick, which arguments did it get wrong, where did it misread an error? Fix the description or schema, then re-run. Track tool-selection accuracy, argument validity rate, calls per task and error recovery rate. See Evaluating Agents, and if a tool design causes repeated calls, An Agent Keeps Looping.

How does this come up in interviews?

1. "Design the tools for a customer-support agent that can look up orders and issue refunds." Propose a small set: search_orders, get_order_summary, issue_refund, escalate_to_human. Keep reads and writes separate, use enums and cents-based integer amounts, add an idempotency key and a policy limit (or approval) on refunds. Mention that error messages guide recovery.

2. "The agent issued the same refund twice. How do you prevent it?" Explain that retries and timeouts make duplicate calls inevitable, so the write tool must be idempotent. Use a key derived from the business intent, store it server-side, and return the original result on a repeat. Add monitoring for duplicate keys and approval for large amounts.

3. "A tool returns 50,000 tokens of JSON and the agent gets confused. What do you change?" Return only fields needed for the next decision, with a hard size cap and pagination. Offer a narrower query tool or filters so the model can ask for detail on demand. Mention the context cost and that long outputs dilute the relevant facts.

4. "Should you give the agent 40 fine-grained tools or 8 task-level ones?" Fewer, task-level tools usually reduce latency, token overhead and selection errors, since deterministic composition moves into code. Keep tools fine-grained where flexibility or safety demands it, such as separating read from write. Decide with an eval on realistic tasks, not on taste.

5. "How would you write an error message for an invalid argument?" State what was wrong, the constraint violated, and a concrete next step, for example the valid format or the tool to call first. Label it as fixable, retryable or permanent. Never include stack traces or secrets.

Common mistakes

  • Treating the description as an afterthought; it is the main signal for tool selection.
  • Overlapping tools with vague names (search, lookup, find) and no guidance on which to use.
  • Free-text parameters where an enum or a typed field would prevent errors.
  • Ambiguous units or formats (dollars versus cents, local time versus UTC).
  • Returning raw database rows or huge payloads instead of curated, capped results.
  • Opaque errors ("failed") that give the model nothing to recover with.
  • Side-effecting tools without idempotency keys, or keys regenerated on every retry.
  • Mirroring an internal API one-to-one, or at the other extreme building a mega-tool with an action switch.
  • Trusting the schema as validation instead of validating on the server.
  • Skipping evals: changing tool descriptions without checking tool-selection and argument accuracy on a test set.