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

# Tools and knowledge

> Run Dialog-RSN-1's tool loop, choose when a tool speaks with `poly_speech` and `poly_spoken`, return search results as `poly_knowledge` with citations, and read `poly_out_of_domain`.

Dialog-RSN-1 calls your tools the way an OpenAI Realtime model does. Arguments stream in, you run the tool and add its result, and the model carries on. When a tool looks like it will take a while, such as an API lookup, it says a short line to the caller as it calls it, which covers the wait. It does no retrieval of its own: your harness runs the search and hands back the passages, and the reply tells you which ones it answered from.

Every field on this page is in the [API reference](https://docs.poly.ai/api-reference/dialog-rsn-1/reference.md). For the `instructions` side, such as confirming before an irreversible action, see [Prompting tool use](https://docs.poly.ai/dialog-rsn-1/prompting/tools.md).

## The tool loop

Declare tools in `session.tools`. When the model calls one, its arguments stream as `response.function_call_arguments.delta`, and `response.function_call_arguments.done` carries the `name`, the full `arguments` and a `call_id`. Answer it with a `function_call_output` item that echoes the `call_id`, then send a fresh `response.create`. Adding the result doesn't start a response by itself.

```json a tool call and its result theme={"theme":{"light":"github-light","dark":"github-dark"}}
// Dialog-RSN-1 calls the tool
{ "type": "response.function_call_arguments.done",
  "name": "get_weather", "arguments": "{\"location\": \"Tokyo\"}",
  "call_id": "call_f02ca25a548c4a6ea8c5d8f8e89d25d6" }

// you add the result, then send response.create
{ "type": "conversation.item.create",
  "item": { "type": "function_call_output",
            "call_id": "call_f02ca25a548c4a6ea8c5d8f8e89d25d6",
            "output": "{\"location\": \"Tokyo\", \"temperature_f\": 68, \"condition\": \"partly cloudy\"}" } }
```

The reply that follows is "It's 68 degrees and partly cloudy in Tokyo."

Dialog-RSN-1 calls tools one at a time. To use several, it calls the next one in the response after each result, so repeat the loop until a response ends with a reply to the caller. Echo the `call_id` exactly: a result with a different `call_id` is kept as an item but left out of what the model sees, with no error.

## Speaking while a tool runs

Dialog-RSN-1 decides on each call whether to say something. When a tool looks like it will take a while, such as a booking lookup or another API call, it says a short line to the caller as it calls the tool, like "let me pull that up for you". The line covers the wait and keeps the response time short. For quick or behind-the-scenes tools, such as logging a detail or moving to the next step of a flow, it calls the tool without saying anything. You don't need to declare anything for this.

The line arrives as the response's message, next to the `function_call` item. On a text session it streams as `response.output_text.delta` like any reply, so your text-to-speech speaks it with no extra code. When Dialog-RSN-1 speaks its own replies, it speaks the line. Either way, run the tool when `response.function_call_arguments.done` arrives, so the lookup happens while the caller hears the line.

## Choosing when a tool speaks

You can override this per tool with `poly_speech`. `"required"` asks for a line on every call, and `"none"` keeps the tool quiet. Leave it out and the model decides.

To guarantee a line on every call, or to tell the model what kind of line to say, give the tool a string argument marked `"poly_spoken": true` and list it in `required`:

```json a tool schema with a spoken argument theme={"theme":{"light":"github-light","dark":"github-dark"}}
{
  "type": "function",
  "name": "look_up_booking",
  "description": "Look up a booking by reference number.",
  "parameters": {
    "type": "object",
    "properties": {
      "reference": { "type": "string" },
      "utterance": {
        "type": "string",
        "description": "A short line to say to the caller while this runs, for example 'let me pull that up for you'.",
        "poly_spoken": true
      }
    },
    "required": ["reference", "utterance"]
  }
}
```

`poly_spoken` must be `true`, on a `string` property, and on one property per tool at most, and a tool can't use it alongside `poly_speech`. Otherwise the `session.update` is refused. If the caller talks over the line, the conversation history keeps only the part they heard.

The answer starts once the line has been said. If the model speaks on a tool you know is fast, set `"poly_speech": "none"` on it. On a tool that ends the call, put the goodbye in a spoken argument, for example a `closing_message` the prompt tells the model to use. Then hang up on `response.done` with status `completed`, which waits for the line to finish.

## Reading what the caller said mid-loop

The caller's transcript arrives during the reply or tool call, often after it starts, so it may not exist yet when your code wants it. See [Run a turn](https://docs.poly.ai/api-reference/dialog-rsn-1/reference.md#run-a-turn) for the event order. To get a number, a name or a spelling, declare it as a tool parameter and let the model fill it in from what it heard. It's available as soon as the arguments stream, already in the shape your schema asks for, and spelled the way your prompt spells it (see [Promptable speech understanding](https://docs.poly.ai/dialog-rsn-1/prompting/speech-understanding.md)).

## Searching and getting citations back

Search is a tool like any other. Declare it the same way you'd declare any other function:

```json declaring a search tool theme={"theme":{"light":"github-light","dark":"github-dark"}}
{
  "type": "function",
  "name": "search_knowledge_base",
  "description": "Search the knowledge base for passages relevant to the caller's question.",
  "parameters": {
    "type": "object",
    "properties": { "query": { "type": "string" } },
    "required": ["query"]
  }
}
```

When the model calls it, your harness runs the search and attaches what it found as `poly_knowledge` on the `function_call_output`, a list of `{name, content}` topics, alongside whatever `output` you'd normally return:

```json answering the search with retrieved topics theme={"theme":{"light":"github-light","dark":"github-dark"}}
{
  "type": "conversation.item.create",
  "item": {
    "type": "function_call_output",
    "call_id": "call_abc123",
    "output": "Found 2 relevant topics.",
    "poly_knowledge": [
      { "name": "refund_policy", "content": "Refunds are issued within 5 business days of approval." },
      { "name": "return_window", "content": "Items can be returned within 30 days of delivery." }
    ]
  }
}
```

A topic can also carry `actions`, an optional string. Send it as a string, not a list: a list fails validation with `invalid_request_error` and the whole item is refused. Validate the shape in your harness before you send it, because a refused result still uses up the call. A corrected resend with the same `call_id` is accepted but left out of the model's input, with no error.

Send a fresh `response.create` after that, same as any other tool result. The reply's `response.done` carries `poly_cited_topics`, the names of the topics it answered from. The field is absent when it cited none.

For knowledge every call needs, set `poly_knowledge` on the session instead. It's then a fixed brief, present from the first turn, and the model cites it the same way. Keep it short, because it goes into every prompt. See [Fitting the context window](https://docs.poly.ai/dialog-rsn-1/prompting/basics.md#fitting-the-context-window).

To say when the model should search, and what to do when nothing relevant comes back, see [Deciding when to search](https://docs.poly.ai/dialog-rsn-1/prompting/tools.md#deciding-when-to-search).

## Spotting out-of-scope requests

Every `response.done` carries `poly_out_of_domain`, `true` or `false` for whether Dialog-RSN-1 judged the request outside what your instructions cover. It's reported on every turn the model judges, tool calls included. Use it to log or escalate calls your agent wasn't built for. A response that only calls a search tool can report `true` before it has the passages, so read the flag on the response that answers the caller.

## Next steps

> [card] [Prompting tool use](https://docs.poly.ai/dialog-rsn-1/prompting/tools.md)
>
> `instructions` text for confirmations, tool errors and when to search.

> [card] [API reference](https://docs.poly.ai/api-reference/dialog-rsn-1/reference.md#polyai-extensions)
>
> Every `poly_` field, with its validation rules.
