# GPT-Live

> For the complete documentation index, see [llms.txt](/llms.txt). Markdown versions of documentation pages are available by appending `.md` to the page URL.

## 6. Built-in delegation with Decisions



In this lesson, we’ll look at another built-in integration with the [Decisions API](https://developers.openai.com/api/docs/guides/decisions).

Decisions gives you real-time results for questions with predefined answers. It accepts three types of input:

And it supports three types of questions:

You can ask multiple questions about the same input.

Let’s look at how GPT-Live can delegate to Decisions to update an app by voice. In this example, we’ll use an apartment search app.

Let’s walk through how this works.



When we create the session, we configure Decisions with four questions about the renter’s search. In the GPT-Live prompt, we specify when to delegate to Decisions: in this case, whenever the renter gives or changes a preference.







Our server sends the session request to OpenAI. This sets up GPT-Live with our prompt and Decisions with the questions we defined.







As before, GPT-Live keeps track of the conversation so it can pass that context along when it delegates.







When GPT-Live delegates, it sends the conversation so far to Decisions.







The browser receives a trace event for that delegation, including an ID it can use to follow the related events.







Decisions returns its answers with the same delegation ID.







The browser can apply the choice answers directly to the area and bedroom filters. For a predicate, we choose a threshold to turn its probability into an on-or-off setting. Here, we enable a filter when the probability is at least 0.85.







Once the filters are applied, the browser lets GPT-Live know the update is complete.







GPT-Live can then confirm the update aloud. This can continue as the renter changes their search. We can also change the Decisions questions during the session with `session.update` and wait for `session.updated` before using the new questions.



As we discussed earlier, you can also attach a [sideband WebSocket](https://developers.openai.com/api/docs/guides/voice-server-controls?api=live#attach-to-the-existing-session) if you want your server to receive the session events.

### Decisions triggers

We’ve seen how GPT-Live can choose to delegate to Responses or Decisions. We can also set up a **Decisions trigger** to monitor the user’s or GPT-Live’s transcript without waiting for GPT-Live to delegate. Triggers can run alongside a delegation configuration, such as Responses or client delegation.

For example, we can use a trigger to change an avatar’s expression as the user speaks.

Let’s see how to set that up.



When we create the session, we add a Decisions trigger on the input transcript and define a choice question for the avatar’s expression. For other applications, we can monitor the output transcript instead, or set up multiple triggers.







Our server sends the session request to OpenAI, setting up GPT-Live and the Decisions trigger.







As the user speaks, GPT-Live transcribes the audio. Decisions evaluates the transcript as it comes through and sends the result to the browser, which can update the avatar’s expression.







Decisions continues monitoring throughout the conversation, so the expression can change as the user keeps talking. We can also update the triggers during the session with `session.update`.



#### Using a trigger as a guardrail

Suppose GPT-Live tells a caller, “Your order has been canceled.” A Decisions trigger can watch the output transcript and flag a claim that a cancellation succeeded. Your server receives the result over its sideband connection and checks the order record. If the order has already shipped, the server can send `session.instructions.append` to ask GPT-Live to correct its reply.

For applications that need to review speech before the caller hears it, see [Check speech before playback](https://developers.openai.com/api/docs/guides/voice-server-controls?api=live#check-speech-before-playback).

#### Using a trigger to start a delegation

We’ve seen how GPT-Live decides when to delegate to a backend. We can also use a Decisions trigger to predict when a delegation should occur. If GPT-Live hasn’t already delegated, our application can force a delegation.



When we create the session, we set up a Decisions trigger on the user’s input transcript with a predicate question. The instructions for when to delegate depend on the application. For the shopping assistant from Lesson 5, we ask whether the user has given enough information to start a product search.







Our server creates the session with GPT-Live, the Decisions trigger, and the Responses backend.







Decisions returns a probability from 0 to 1, so we need a threshold to decide when a delegation should occur. Let’s say we use 0.75 here. Decisions returns 0.93, which is above that threshold.







Our application then checks whether GPT-Live has already delegated this request. If it hasn’t, it sends `response.create` to start a delegation.







As before, the browser receives a delegation notice, followed by the Responses events with the same delegation ID. We can use that ID to follow the task through to the answer.



### Try it yourself

Use the prompts below to build the demos yourself and see how each application responds as you talk to GPT-Live.



**Build the apartment search:**

```text
[@OpenAI Developers](plugin://openai-developers@openai-curated), build and run a voice apartment search with GPT-Live and built-in Decisions delegation. Let me describe what I’m looking for and change my preferences as I browse. Show the actual events alongside the listings so I can follow the handoff to Decisions and see how its answers change the search filters.

Lesson 6: https://developers.openai.com/api/training/gpt-live/6-built-in-delegation-with-decisions.md
```



**Build the expressive assistant:**

```text
[@OpenAI Developers](plugin://openai-developers@openai-curated), build and run a GPT-Live assistant with an avatar that reacts to what I say. Use a Decisions trigger to choose an expression as I speak. Show the actual trigger results beside the avatar so I can see which event changed its expression while the conversation continues.

Lesson 6: https://developers.openai.com/api/training/gpt-live/6-built-in-delegation-with-decisions.md
```
