# Building Tools

> Define tools for agents using the fluent builder API.

**URL:** https://inference.sh/docs/api/agent/tools
**Last updated:** 2026-10-31

---

Define tools for agents using the fluent builder API.

---

## Tool Types

Agents can use several types of tools:

| Type | Description |
|------|-------------|
| **Client** | Executed by your code (with handler) |
| **App** | Runs an inference shell app |
| **Agent** | Delegates to a sub-agent |
| **Webhook** | POST to an external URL (unsigned or HMAC-signed) |
| **HTTP / Call** | Authenticated REST calls with runtime credential injection |
| **Internal** | Built-in: plan, memory, widgets, finish |

---

## Quick Example

<div data-type="codegroup">

```python Python
from inferencesh import tool, string

greet = (
    tool("greet")
    .describe("Greet a user")
    .param("name", string("User's name"))
    .handler(lambda args: f"Hello, {args['name']}!")
    .build()
)
```

```typescript JavaScript
import { tool, string } from '@inferencesh/sdk';

const greet = tool('greet')
  .describe('Greet a user')
  .param('name', string('User name'))
  .handler(args => `Hello, ${args.name}!`)
  .build();
```

</div>

---

## Parameter Types

All tool builders share these parameter types:

<div data-type="codegroup">

```python Python
from inferencesh import string, number, integer, boolean, enum_of, array, obj, optional

# Basic types
string("Description")      # Text input
number("Description")      # Decimal number
integer("Description")     # Whole number
boolean("Description")     # True/false

# Complex types
enum_of(["a", "b"], "desc")    # Choice from list
array(string(), "desc")        # List of items
obj({"key": string()}, "desc") # Nested object
optional(string())             # Optional parameter
```

```typescript JavaScript
import { string, number, integer, boolean, enumOf, array, obj, optional } from '@inferencesh/sdk';

// Basic types
string('Description')      // Text input
number('Description')      // Decimal number
integer('Description')     // Whole number
boolean('Description')     // True/false

// Complex types
enumOf(['a', 'b'], 'desc')     // Choice from list
array(string(), 'desc')        // List of items
obj({ key: string() }, 'desc') // Nested object
optional(string())             // Optional parameter
```

</div>

---

## Tool Definition Format

Every builder's `.build()` returns the same shape, which is also what the REST API accepts and returns. Write it by hand when you are not using an SDK:

```json
{
  "name": "search",
  "display_name": "Search Files",
  "description": "Search for files matching a pattern",
  "type": "client",
  "require_approval": false,
  "client": {
    "input_schema": {
      "type": "object",
      "properties": {
        "pattern": { "type": "string", "description": "Glob pattern to match" },
        "recursive": { "type": "boolean", "description": "Search subdirectories" }
      },
      "required": ["pattern"]
    }
  }
}
```

`name`, `description` and `type` are required; `display_name` is what the UI shows, and `require_approval` pauses the call for a human. Optional `approval_timeout` (seconds) refuses a call nobody approves in time; omit it or set `0` to wait until answered (see [Approval timeout](/docs/api/agent/approval#approval-timeout)). The tool builders have no method for it; set it on the built object. The parameters are JSON Schema.

### Action labels

When an agent runs, the platform adds a required string parameter `_action` to every tool the model can call except `finish`. The model writes in it what the call does, for the user, in a few words that usually open with a verb (`Fetch unread emails from alice@x.com`).

- The runtime collapses whitespace, drops a trailing period, cuts the label to 120 characters, and stores it on the invocation as `action` (`ToolInvocationDTO.action`: **@inferencesh/sdk ≥ v0.34.0**, **inferencesh ≥ v0.36.0**).
- `_action` is removed from the arguments before the tool runs. Handlers, apps, MCP servers and webhooks get only the tool's own inputs.
- When the model omits it, `action` is empty; show `display_name` or the tool name instead.
- `_action` is reserved: a tool that declares it has it replaced.

→ [Tool invocation fields](/docs/api/rest/agents#tool-invocation-fields)

Each type carries its configuration under a key of its own, and `type` says which key is read:

| `type` | Config key | Documented in |
|--------|-----------|---------------|
| `client` | `client` | [Client Tools](/docs/api/agent/client-tools) |
| `app` | `app` | [App Tools](/docs/api/agent/app-tools) |
| `agent` | `agent` | [Agent Tools](/docs/api/agent/agent-tools) |
| `call` | `call` | [Call Tools](/docs/api/agent/call-tools) |
| `http` | `http` | [Call Tools](/docs/api/agent/call-tools) — `call` is preferred |
| `hook` | `hook` | [Webhook Tools](/docs/api/agent/webhook-tools) |
| `mcp` | `mcp` | [Connector Tools](/docs/api/agent/connector-tools) |
| `internal` | none | [Internal Tools](/docs/api/agent/internal-tools) |

---

## Learn More

- [Client Tools](/docs/api/agent/client-tools) — Handler-based tools
- [App Tools](/docs/api/agent/app-tools) — Run inference shell apps
- [Agent Tools](/docs/api/agent/agent-tools) — Delegate to sub-agents
- [Call Tools](/docs/api/agent/call-tools) — Authenticated HTTP API calls (YAML and SDK)
- [Webhook Tools](/docs/api/agent/webhook-tools) — Unsigned or signed POST webhooks
- [Internal Tools](/docs/api/agent/internal-tools) — Plan, memory, widgets, remotes
- [Approval Settings](/docs/api/agent/approval) — Human-in-the-loop
