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

# Asynchronous tool calls

> With higgs-realtime-1.5 the conversation keeps going while tools run: the model answers each result as it lands, says when a call is taking long, and can cancel a call the user no longer wants.

`higgs-realtime-1.5` calls tools asynchronously. A tool call does not pause the conversation: while it runs, the user can keep talking and the model keeps answering. When the result arrives, the model works it into the conversation.

Your existing [function tool](https://docs.boson.ai/models/higgs-realtime/guides/tool-calling.md#function-tools) code works unchanged. This page covers what the model does on its own, and what you can add:

| Feature | What the model does | What you add |
| - | - | - |
| [A reply per result](#return-each-result-as-it-arrives) | Can answer one call's result while the response's other calls are still running. | Return each result when it is ready, and send `response.create` after each one. |
| [Status updates](#status-updates) | Can tell the user it is still working on it once a call has run for 10 seconds. | Nothing. You can show the status in your UI. |
| [Timeouts](#timeouts) | Tells the user when a call ran out of time, and may try again. | `timeout_sec` on the tool. |
| [Cancellation](#cancellation) | Stops a running call when the user withdraws or corrects the request. | `cancellable: true` on the tool, and a handler for `response.function_call.cancel`. |

> [!NOTE]
>
> Asynchronous tool calls need `higgs-realtime-1.5`. `higgs-realtime` accepts `timeout_sec` and `cancellable` on a tool and ignores them: it sends no status items and never cancels a call.

## How a call runs

1. **The model calls the tool.** It may say a short line first ("Let me check that for you."). The response ends with [`response.done`](https://docs.boson.ai/api-reference/realtime/server-events#response-done) carrying the `function_call` item, as for any tool call.
2. **Your client starts the work.** The conversation stays open meanwhile: the user can ask something else, and the model answers it.
3. **Your client returns the result** with [`conversation.item.create`](https://docs.boson.ai/api-reference/realtime/client-events#conversation-item-create) (`function_call_output`) and sends [`response.create`](https://docs.boson.ai/api-reference/realtime/client-events#response-create). The model speaks the answer.

Two cases need no handling on your side:

* **The model is still speaking.** A `response.create` that follows a tool result never cuts the model off: the reply starts when it finishes.
* **The user is speaking.** The `response.create` is rejected with an `error` (`code: "user_speech_in_progress"`). Don't retry it: the result is already in the conversation, and the reply to what the user is saying takes it into account.

## Return each result as it arrives

The server does not continue by itself after your function tool's result: as with any function tool, the model replies when you send `response.create`. What changes with `higgs-realtime-1.5` is that you don't have to collect all of a response's results first.

When a response makes several calls, return each result as soon as you have it and send `response.create` after each one. The model answers the fast call first and the slow one when it lands.

Who starts the model's reply depends on what arrived:

| What arrives | Who starts the reply |
| - | - |
| The result of your function tool | You: send `response.create` after the `function_call_output`. |
| The result of a server-side tool, such as [`web_search`](https://docs.boson.ai/models/higgs-realtime/guides/tool-calling#web-search) | The server. |
| A [`function_call_status`](#status-updates) item | The server. |
| A [cancellation](#cancellation) | The server. |

Run each call as its own task, so your receive loop keeps reading events while tools work:

```python theme={null}
import asyncio
import json

running: dict[str, asyncio.Task] = {}  # call_id -> the task running that call


async def run_call(ws, call):
    result = await run_my_function(call["name"], json.loads(call["arguments"]))
    await ws.send(json.dumps({
        "type": "conversation.item.create",
        "item": {
            "type": "function_call_output",
            "call_id": call["call_id"],
            "output": json.dumps(result),
        },
    }))
    await ws.send(json.dumps({"type": "response.create"}))  # One per result.


async def handle_event(ws, event):
    if event["type"] == "response.done":
        for item in event["response"]["output"]:
            if item.get("type") == "function_call" and item.get("executor") == "client":
                call_id = item["call_id"]
                task = asyncio.create_task(run_call(ws, item))
                running[call_id] = task
                task.add_done_callback(lambda _, call_id=call_id: running.pop(call_id, None))

    elif event["type"] == "response.function_call.cancel":
        # The model cancelled this call: stop the work (see Cancellation).
        task = running.get(event["call_id"])
        if task:
            task.cancel()
```

## Status updates

When a call has run for 10 seconds without a result, the server adds a `function_call_status` item to the conversation. The model can then tell the user that it is still working on it.

```json theme={null}
{
  "type": "conversation.item.added",
  "previous_item_id": "...",
  "item": {
    "id": "...",
    "object": "realtime.item",
    "type": "function_call_status",
    "call_id": "call_...",
    "call_status": "in_progress",
    "status": "completed"
  }
}
```

| `call_status` | Meaning |
| - | - |
| `in_progress` | The call `call_id` has run for 10 seconds and has not returned. |
| `timed_out` | The call `call_id` passed its [timeout](#timeouts). |

* **It arrives like any item:** [`conversation.item.added`](https://docs.boson.ai/api-reference/realtime/server-events#conversation-item-added), then [`conversation.item.done`](https://docs.boson.ai/api-reference/realtime/server-events#conversation-item-done), in the `previous_item_id` chain.
* **You don't need to act on it.** The server starts the model's reply by itself, so don't send `response.create` for a status. If the model is speaking or the user is talking, the status waits until that turn ends.
* **It is not the tool's output.** Keep the call running, and return its result when you have it.
* **`status` is not the call's state.** It is the item's own lifecycle, as on every item, and is always `completed`. The call's state is `call_status`.
* **Server-side tools get them too.** A [`web_search`](https://docs.boson.ai/models/higgs-realtime/guides/tool-calling#web-search) that runs long produces the same `in_progress` item.
* **Only the server creates them.** A `conversation.item.create` with a `function_call_status` item is rejected with an `error`.

## Timeouts

A function tool call never times out by default. Set `timeout_sec` on the tool to give its calls a limit:

```json theme={null}
{
  "type": "function",
  "name": "search_flights",
  "description": "Search flights between two cities on a date",
  "parameters": {
    "type": "object",
    "properties": {
      "origin": { "type": "string" },
      "destination": { "type": "string" },
      "date": { "type": "string" }
    },
    "required": ["origin", "destination", "date"]
  },
  "timeout_sec": 30
}
```

* **Value:** a number of seconds greater than `0`.
* **When a call passes it,** the server adds a `function_call_status` item with `call_status: "timed_out"`, and the model reacts: typically it tells the user, and it may call the tool again. A retry is a new call with its own `call_id`.
* **A late result is still accepted.** If your client returns the `function_call_output` after the timeout, it is added to the conversation as usual.
* **The model never sees the field.** You don't need to describe the limit in the tool's description.

## Cancellation

Mark a tool `cancellable` to let the model stop a call of it that is still running:

```json theme={null}
{
  "type": "function",
  "name": "search_flights",
  "description": "Search flights between two cities on a date",
  "parameters": {
    "type": "object",
    "properties": {
      "origin": { "type": "string" },
      "destination": { "type": "string" },
      "date": { "type": "string" }
    },
    "required": ["origin", "destination", "date"]
  },
  "timeout_sec": 30,
  "cancellable": true
}
```

The model cancels a call when its result is no longer wanted: the user withdrew the request, or corrected it in a way that makes the call's arguments wrong ("Actually, make that Friday"). It does not cancel a call only because the user interrupted. When it cancels one of your calls, the server sends `response.function_call.cancel`:

```json theme={null}
{
  "event_id": "...",
  "type": "response.function_call.cancel",
  "call_id": "call_..."
}
```

Stop the work for that `call_id`. You don't need to return a result or send `response.create`: the model goes on with the conversation by itself, for example by calling the tool again with the corrected arguments.

* **Mark only tools that are safe to stop.** A lookup is. A write that can't be undone is not: leave `cancellable` off (the default), and the model lets the call finish.
* **A result that still arrives is accepted.** If your client could not stop in time and returns the `function_call_output`, it is added to the conversation.
* **Don't describe cancellation yourself.** While any tool is `cancellable`, the server adds a sentence to each tool's description that tells the model whether it can be cancelled.
* **What you see on the wire:** the model cancels through a server-side tool named `cancel_task`. It appears as a `function_call` item with `executor: "server"` and its `function_call_output`, which need no action. Its arguments name the call by the model's own short id (such as `c3`), not by your `call_id`. Take the `call_id` from `response.function_call.cancel`.
* **`cancel_task` is a reserved name.** With `higgs-realtime-1.5`, a `session.update` that declares a function tool named `cancel_task` fails.
* **Function tools only.** `web_search` cannot be marked `cancellable`.

## Session acknowledgements

`session.created` and `session.updated` echo your tools without `timeout_sec` and `cancellable`. Keep your own tool definitions and send those in later `session.update` events, not the echoed ones.

## Related

> [card] [Tool use](https://docs.boson.ai/models/higgs-realtime/guides/tool-calling.md)
>
> Declaring function tools and web search, and returning results.

> [card] [Server events](https://docs.boson.ai/api-reference/realtime/server-events.md#response-function_call-cancel)
>
> `response.function_call.cancel` and the `function_call_status` item.


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