> ## Documentation Index
> Fetch the complete documentation index at: https://docs.roark.ai/llms.txt
> Use this file to discover all available pages before exploring further.

# Tools

> Define an agent tool as config: the tools an agent built on Roark calls, and how Roark grades and mocks tool calls in simulations

A `tool` describes a function your agent can call: its name, the parameters it takes, when it should be invoked, and what a successful result looks like. Scope a tool to one agent with `agent`, or omit it for a project-wide tool.

A tool does one of two jobs, depending on the agent it belongs to:

* **Grading and mocking, for a connected agent.** Your agent runs on another platform (for example `provider: vapi`) or your own stack (`provider: custom`) and calls its own tools. Roark uses the tool's description to **grade and mock** tool calls in simulations: it checks the agent reached for the right tool at the right moment with sensible arguments, and it stands in a mock result so the conversation can carry on.
* **A tool the agent runs, for an agent built on Roark.** A tool scoped with `agent:` to an agent with [`provider: roark`](https://docs.roark.ai/documentation/config-as-code/agents#agents-built-on-roark), with a `handler`, is a tool that agent actually calls mid-call. See [Tools for an agent built on Roark](#tools-for-an-agent-built-on-roark).

```typescript TypeScript theme={"theme":{"light":"everforest-light","dark":"everforest-dark"}}
import { defineTool } from '@roarkanalytics/sdk/lib/config';

const bookAppointment = defineTool({
  name: 'book-appointment',
  description: 'Book a slot in the scheduling system',
  agent: 'frontdesk', // scope to one agent by name; omit for a project-wide tool
  parameters: {
    date: 'string',
    time: 'string',
    partySize: 'number',
  },
  invocationCriteria: 'Call once the caller has confirmed a specific date and time.',
  expectedResult: 'A confirmation id and the booked time.',
  handler: {
    type: 'http',
    url: 'https://api.example.com/appointments',
    method: 'POST',
  },
});
```

```yaml YAML theme={"theme":{"light":"everforest-light","dark":"everforest-dark"}}
# yaml-language-server: $schema=https://roark.ai/roark-config.schema.json
kind: tool
name: book-appointment
description: Book a slot in the scheduling system
agent: frontdesk            # scope to one agent by name; omit for a project-wide tool
parameters:
  date: string
  time: string
  partySize: number
invocationCriteria: Call once the caller has confirmed a specific date and time.
expectedResult: A confirmation id and the booked time.
handler:
  type: http
  url: https://api.example.com/appointments
  method: POST
```

| Field | Default | Notes |
| :- | :- | :- |
| `name` | | The local key (`^[a-z0-9][a-z0-9-_.]*$`) and, with the kind, the config identity |
| `description` | | What the tool does, in plain language. Used to judge whether the agent reached for the right tool |
| `parameters` | | A flat map of parameter name to its type: `string`, `number`, or `boolean` |
| `invocationCriteria` | | When the tool should fire. Roark grades the call against this |
| `expectedResult` | | What a successful result looks like. Shapes the mock Roark returns to the agent |
| `agent` | project-wide | The `name` of a [`kind: agent`](https://docs.roark.ai/documentation/config-as-code/agents) to scope the tool to. Omit for a tool every agent in the project can use |
| `handler` | | How the tool executes (see [Handler](#handler)). An agent built on Roark runs it. Optional; a tool with no handler is grading and mock metadata only |
| `changesData` | | `true` for a tool that books, cancels, or sends something. An agent built on Roark does not abandon the call when the caller talks over it, and sends an `Idempotency-Key` |
| `responseFields` | all of it | Dot paths into the handler's JSON response that an agent built on Roark is given, for example `[patient.name, patient.nextAppointment]` |
| `messages` | | What an agent built on Roark says around the call: `before` (as it goes out), `slow` (once, if it is slow), and `failure` (when it fails) |

> [!NOTE]
>
> For a **connected agent**, a tool definition is grading and mock metadata, not an integration. In a simulation Roark scores whether your agent called the tool correctly and returns a mock result so the call can continue; it does not call your backend, and defining the tool changes nothing about how your live agent runs. For an **agent built on Roark**, the tool's `handler` runs: Roark calls your HTTP endpoint, or the connected calendar, when the agent uses the tool.

## Parameters

`parameters` is a flat map of parameter name to its type, one of `string`, `number`, or `boolean`. It describes the arguments the agent is expected to pass, so Roark can check the call carried the right ones:

```typescript TypeScript theme={"theme":{"light":"everforest-light","dark":"everforest-dark"}}
parameters: {
  date: 'string',
  time: 'string',
  partySize: 'number',
  waitlist: 'boolean',
}
```

```yaml YAML theme={"theme":{"light":"everforest-light","dark":"everforest-dark"}}
parameters:
  date: string
  time: string
  partySize: number
  waitlist: boolean
```

## Handler

`handler` says **how** the tool executes. For an [agent built on Roark](#tools-for-an-agent-built-on-roark), Roark runs it when the agent calls the tool. For a connected agent, Roark stores it with the tool but does not call it.

It is optional, and there are two types: `http` and `calendar`.

### HTTP handler

A public endpoint the agent's runtime calls, mid-call, with the tool's arguments:

```typescript TypeScript theme={"theme":{"light":"everforest-light","dark":"everforest-dark"}}
handler: {
  type: 'http',
  url: 'https://api.example.com/appointments',
  method: 'POST', // optional; GET | POST | PUT | PATCH | DELETE
}
```

```yaml YAML theme={"theme":{"light":"everforest-light","dark":"everforest-dark"}}
handler:
  type: http
  url: https://api.example.com/appointments
  method: POST   # optional; GET | POST | PUT | PATCH | DELETE
```

| Field | Default | Notes |
| :- | :- | :- |
| `type` | | `http` |
| `url` | | A public `http(s)` endpoint |
| `method` | | `GET`, `POST`, `PUT`, `PATCH`, or `DELETE` |
| `headers` | | A map of header name to value |
| `body` | | The request body, as a template |
| `timeoutMs` | `10000` | How long the agent waits for a response, `1000` to `30000` |

`url`, header values, and `body` are templates over `{{args.<parameter>}}` and `{{session.id}}`. With no `body`, a `POST`, `PUT`, or `PATCH` sends the arguments as the body, and a `GET` or `DELETE` sends them as query parameters.

### Calendar handler

One action on a calendar an agent built on Roark books against. Unlike `http`, Roark executes this one itself, against a calendar it holds the credential for. Each calendar tool is one action, so a front desk that checks availability, books, and cancels is three `kind: tool` resources naming the same connection.

```yaml theme={"theme":{"light":"everforest-light","dark":"everforest-dark"}}
kind: tool
name: check-availability
agent: frontdesk
description: Check open appointment slots
handler:
  type: calendar
  calendarConnection: 3f2a9c1e-8b4d-4e6f-9a7b-1c2d3e4f5a6b
  operation: CHECK_AVAILABILITY
  appointmentTypes:
    - name: checkup
      whenToUse: A routine cleaning or checkup
      eventTypeId: 123456
```

| Field | Notes |
| :- | :- |
| `type` | `calendar` |
| `calendarConnection` | The id of a calendar connection. Connect the calendar through the app, the API, or `roark connections calendar create` first; the credential never goes in your config |
| `operation` | `CHECK_AVAILABILITY`, `BOOK`, `LOOKUP_BOOKING`, `RESCHEDULE`, `CANCEL`, or `LIST_BOOKINGS`. An operation the calendar provider does not support is refused at apply — Calendly, for one, has no reschedule |
| `appointmentTypes` | 1 to 24 kinds of appointment this tool may reach: `{ name, whenToUse?, durationMinutes? }` plus the field that names what it books (see below). They also scope the tool, so it cannot reach other appointments on the account |
| `simulate` | `true` sends every call on this tool to a simulated calendar instead of yours, so test runs do not fill a live calendar |

Which field names the bookable thing depends on the provider the connection is on:

| Provider | Field | Example |
| :- | :- | :- |
| Cal.com | `eventTypeId` | `123456` |
| Calendly | `eventTypeUri` | `https://api.calendly.com/event_types/AAAAAAAAAAAAAAAA` |
| GoHighLevel | `goHighLevelCalendar` | `ocQHyuzHvysMo5N5VsXc` |
| Google Calendar | `calendarTarget` | The `name` of a [bookable target](https://docs.roark.ai/documentation/integrations/calendars/google-calendar.md#the-booking-policy) on the connection, which carries the duration, buffers, notice, horizon and weekly hours |

`durationMinutes` applies only where the bookable thing offers a choice of lengths (Cal.com event types and GoHighLevel calendars). Calendly settles the length when the slot is taken, and a Google target carries its own.

A calendar tool takes the arguments Roark defines for its operation, so it does not declare `parameters`, `changesData`, or `responseFields`. It keeps `messages`.

See [Calendars](https://docs.roark.ai/documentation/integrations/calendars/overview.md) for what each provider supports, how an account is connected, and the contract each of the six tools gives the agent.

## Tools for an agent built on Roark

Scope a tool to an agent with [`provider: roark`](https://docs.roark.ai/documentation/config-as-code/agents#agents-built-on-roark) with `agent:` and give it a `handler`, and it becomes a tool that agent calls:

```yaml theme={"theme":{"light":"everforest-light","dark":"everforest-dark"}}
# roark/tools/lookup-patient.yaml
kind: tool
name: lookup-patient
agent: frontdesk
description: Find the caller's patient record by phone number
parameters: { phone: string }
handler:
  type: http
  url: https://clinic.example.com/api/patients/lookup
  method: POST
responseFields: [patient.name, patient.nextAppointment]
messages:
  before: Let me pull up your record.
```

* **A tool edit publishes a new agent version.** `roark config diff` shows an edited tool as an update to its agent, and apply publishes a version that runs the edited tool.
* **Tools added in Roark stay on the agent.** Config removes a tool from the agent only when the bundle scopes it to another agent, or when a pruning bundle drops it.
* **Project-wide tools are not attached by config.** A tool without `agent:` is not added to the agent's version. Attaching project-wide tools is not configurable yet.

> [!NOTE]
>
> For the full field reference of every kind, see the [Config DSL reference](https://roark.ai/roark-config.schema.json) schema.


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.