Skip to content
BENIBIX Learn

tool() Helper

AI🧩 Claude Agent SDKCustom Tools

Also known as @tool decorator, Agent SDK custom tool, Claude Agent SDK tool() Helper

The helper that makes your own tool. You give it a name, a note on what it does, its inputs and the code to run.

Think of it like

It is like a new button with its job written on it.

Example

Mia wants her agent to look up orders. She writes a get_order tool with tool(), with the order ID as its only input.

Why it matters

Built-in tools reach files and the shell. Your own tools reach your own systems.

Definition

tool() is the Agent SDK helper that defines a custom tool. In Python it is the @tool decorator. A tool has four parts. They are a name, a description Claude reads to choose when to call it, an input schema, and a handler that runs when it is called. The handler sends back content, and can set isError to say the call failed.

Example code

typescript
const getTemp = tool(
  "get_temperature",
  "Get the temperature at a place",
  { city: z.string() },
  async ({ city }) => ({ content: [{ type: "text", text: await lookUp(city) }] }),
);
A tool with one input and a handler.
From tool() to a call Claude makes.

Common mistake

Writing a vague description. Claude reads it to decide when to call the tool, so say what it does.

Key takeaways

  1. 1
    Four parts. Name, description, schema, handler.
  2. 2
    Zod or a dict. For the schema.
  3. 3
    isError for failures. Claude reads it.