الانتقال إلى المحتوى
Claude وأدوات الـ AI للبرمجةClaude API و Tool Use· 7 دقائق للقراءة

Designing Tools for Claude: Why Thin API Wrappers Make Weak Agent Tools

One tool per endpoint makes Claude page, chain and juggle IDs. Shape tools around tasks and return only what the next step needs.

ReadIn

مقال كل يوم يفرق معاك

21 نوفمبر 2026
  • كاتب موثّق
  • Claude API
محتويات المقال

A support team connects Claude to the company CRM with a generator that turns the OpenAPI spec into tools, one per endpoint. Coverage looks complete. Then a teammate asks, "Why was Dana Levi charged twice in March?" Claude pages through get_customers looking for Dana, pulls her entire transaction history, then the notes, and after a dozen calls full of UUIDs it reports a refund that belongs to a different customer. Every endpoint worked. The tools still failed.

The common misconception

"Wrapping each existing API endpoint as a tool, with a short description, is good tool design for Claude." It's how we've always integrated systems:

  • A client library mirrors the API it calls, so a tool set that mirrors the API feels just as correct.
  • Generators turn an OpenAPI file into tools in minutes, and full coverage feels thorough.
  • The endpoints are already tested, documented and permissioned, so reusing them seems safest.
  • More tools sound like more capability.

The half-truth: calling your existing API from a tool is fine, and often the right implementation. The mistake is copying the API's shape, one route per tool, into the interface the model sees.

What actually happens

A tool is a contract with a non-deterministic caller

Anthropic's engineering guide on writing tools puts it this way: "Tools are a new kind of software which reflects a contract between deterministic systems and non-deterministic agents." Given "Should I bring an umbrella today?", an agent might call the weather tool, answer from general knowledge or ask where you are. So the guide's advice is to stop writing tools "the way we'd write functions and APIs for other developers or systems" and design them for instead.

Context is the scarce resource

Your API's usual consumers are programs, and for them memory is cheap: looping over thousands of rows is trivial. An agent reads every returned token inside its . The guide's example is an address book: a list_contacts tool forces the agent to read contacts one by one, like reading the address book from the first page. A search_contacts tool lets it jump to the right page. And whatever the tool returns stays in the conversation, re-sent with every later turn.

Shape tools around tasks, not routes

The guide names the mistake directly: "A common error we've observed is tools that merely wrap existing software functionality or API endpoints." Its alternatives consolidate what agents otherwise chain:

  • schedule_event, which finds availability and books, instead of list_users, list_events and create_event.
  • search_logs, which returns relevant lines with some context, instead of read_logs.
  • get_customer_context, which compiles a customer's recent, relevant information, instead of get_customer_by_id, list_transactions and list_notes.

Claude's tool docs say the same: "Fewer, more capable tools reduce selection ambiguity," and when tools span services, prefix them with the service name, such as github_list_prs.

Return what the next step needs

Responses should carry "only high signal information." The guide suggests dropping low-level fields such as uuid, 256px_image_url and mime_type in favor of name, image_url and file_type, and reports that resolving arbitrary UUIDs to meaningful names "significantly improves Claude's precision in retrieval tasks by reducing hallucinations." When a later call needs an ID, a response_format parameter with concise and detailed options lets the agent ask for it. Large results get pagination, filtering or truncation with sensible defaults, and errors should say what to change instead of returning an opaque code or a traceback.

The CRM, before and after

Here's the generated tool set next to one tool built for the question people actually ask:

Python crm_tools.py
# Generated from openapi.yaml: one tool per endpointTOOLS = [    {"name": "get_customers", "description": "GET /customers",     "input_schema": {"type": "object",                      "properties": {"page": {"type": "integer"}}}},    {"name": "get_customer_transactions",     "description": "GET /customers/{id}/transactions",     "input_schema": {"type": "object",                      "properties": {"id": {"type": "string"}},                      "required": ["id"]}},    {"name": "get_customer_notes",     "description": "GET /customers/{id}/notes",     "input_schema": {"type": "object",                      "properties": {"id": {"type": "string"}},                      "required": ["id"]}},    # ...and one more for every other route in the spec]

The implementation still calls the same REST API; the difference is what reaches the model:

Python crm_tools.py
def crm_get_customer_context(customer: str, response_format="concise"):    matches = crm.search_customers(customer, limit=5)  # never the full list    if len(matches) != 1:        found = "; ".join(f"{m.name} <{m.email}>" for m in matches) or "none"        return f"{len(matches)} matches for {customer!r}: {found}. Ask which."    c = matches[0]    lines = [f"{c.name} <{c.email}>, customer since {c.since}"]    lines += [f"{t.date} {t.amount} {t.status}"              for t in crm.list_transactions(c.id, limit=20)]    lines += [f"note: {n.text}" for n in crm.list_notes(c.id, status="open")]    if response_format == "detailed":  # IDs only when a next call needs them        lines.append(f"customer_id: {c.id}")    return "\n".join(lines)print(crm_get_customer_context("Dana Levi"))

One call answers the question that took a dozen. The two March charges sit next to each other under Dana's name, with no UUIDs to mix up, and an ambiguous name produces a short list and an instruction instead of a guess.

Endpoint wrapperTool designed for an agent
Unit of designOne HTTP routeOne task a person would ask for
Finding a recordList and page through everythingSearch with filters and a limit
ResponseEvery field, raw IDsHigh-signal fields and names; IDs on request
Description"GET /customers/{id}/notes"What, when, when not and caveats, as for a new hire
ErrorsStatus code or tracebackA message that says what to change

How to apply it in your project

  1. List tasks, not endpointsCollect the questions people really ask your assistant, from logs or support tickets, and design one tool per frequent workflow.
  2. Merge the chainsIf the agent always calls three tools in a row, make one tool that does all three against your API.
  3. Replace lists with searchGive every collection a search with filters, a small default limit and a hint when results are truncated.
  4. Trim and humanize responsesReturn names and the fields the next step needs, and offer IDs through a response_format parameter.
  5. Write descriptions for a new hireExplain what the tool does, when to use it, what each parameter means and what it won't return, and give parameters unambiguous names such as user_id instead of user.

Key takeaways

  • A tool's caller is a model reading every token of its definitions and responses, not a program with cheap memory.
  • Calling your API inside a tool is fine; mirroring one endpoint per tool is the mistake.
  • Consolidate chained calls into task-shaped tools, and replace list endpoints with search.
  • Return high-signal fields and readable names, with IDs and detail only on request.
  • Describe each tool like you'd brief a new colleague, then improve it against an evaluation.

📚 المصادر

  1. Writing effective tools for AI agents — Anthropic Engineering
  2. Define tools — Claude API Docs

التعليقات (0)