# Tool use

> Give the model tools your code runs — look something up, save a draft — and send it the results.

Source: https://docs.strokes.ink/guides/tool-use

Describe a tool in `tools`, and the model can ask your code to run it. Tools work as in Anthropic's Messages API.

## Define a tool

```json
{
  "model": "swim-1.0",
  "tools": [
    {
      "name": "get_brand_voice",
      "description": "Returns the brand's voice guidelines.",
      "input_schema": {
        "type": "object",
        "properties": { "brand": { "type": "string" } },
        "required": ["brand"]
      }
    }
  ],
  "messages": [
    {
      "role": "user",
      "content": "Write a tagline for Northtrail in its brand voice."
    }
  ]
}
```

`input_schema` is a JSON Schema for the tool's input. A clear `description` is how the model knows when to use it.

## The model calls it

The reply ends with `stop_reason: "tool_use"`, and `content` holds a `tool_use` block — sometimes after some text:

```json
{
  "content": [
    {
      "type": "tool_use",
      "id": "toolu_5Gk1mQ8xLp3TzW7cB2nR9vYd",
      "name": "get_brand_voice",
      "input": { "brand": "Northtrail" }
    }
  ],
  "stop_reason": "tool_use"
}
```

## Send the result

Run the tool, then send the conversation again with the same `tools`: the model's reply as an `assistant` message, unchanged, and a `user` message with a `tool_result` for each call, matched by `tool_use_id`:

```json
{
  "model": "swim-1.0",
  "tools": [
    {
      "name": "get_brand_voice",
      "description": "Returns the brand's voice guidelines.",
      "input_schema": {
        "type": "object",
        "properties": { "brand": { "type": "string" } },
        "required": ["brand"]
      }
    }
  ],
  "messages": [
    {
      "role": "user",
      "content": "Write a tagline for Northtrail in its brand voice."
    },
    {
      "role": "assistant",
      "content": [
        {
          "type": "tool_use",
          "id": "toolu_5Gk1mQ8xLp3TzW7cB2nR9vYd",
          "name": "get_brand_voice",
          "input": { "brand": "Northtrail" }
        }
      ]
    },
    {
      "role": "user",
      "content": [
        {
          "type": "tool_result",
          "tool_use_id": "toolu_5Gk1mQ8xLp3TzW7cB2nR9vYd",
          "content": "Calm, plain-spoken, outdoors. No exclamation marks."
        }
      ]
    }
  ]
}
```

`content` is a string or a list of text blocks. If the tool failed, say so in `content` and add `"is_error": true`. The model goes on — with its answer, or with another call.

## Several calls at once

The model can call several tools in one reply. Answer every `tool_use` in the next `user` message, one `tool_result` each. To get at most one call per reply, set `"tool_choice": { "type": "auto", "disable_parallel_tool_use": true }`.

## Tool choice

| `tool_choice` | |
| --- | --- |
| `{ "type": "auto" }` | The model decides. The default |
| `{ "type": "any" }` | The model must call one of the tools |
| `{ "type": "tool", "name": "get_brand_voice" }` | The model must call this tool |
| `{ "type": "none" }` | The model must not call a tool |

## Streaming

A streamed tool call is a block of its own: `content_block_start` with the call's `id`, `name` and an empty `input`, then `input_json_delta` pieces to join, then `content_block_stop`. Several calls arrive one after another, each complete. The SDKs assemble them for you — `stream.finalMessage()` in TypeScript, `stream.get_final_message()` in Python. See [Streaming events](/api/streaming-events).

## Web search

Web search isn't a tool you declare: `swim-1.0` searches on its own, the API runs the searches, and the reply carries them. Send `"web_search": false` to turn it off. See [Web search](/guides/web-search).
