Decisions

View as Markdown

A Voice Agent session can ask the Decisions API bounded questions about the conversation while it's still in progress. The server makes the Decisions call for you and sends the answers to your client over the same WebSocket.

There are two ways to use it:

UseWhen it runsWhat your client does with the answers
DelegationWhen the agent decides, during a turn, that the user's request needs a decision.Acts on the answers, records the outcome, and asks the agent to reply.
Transcript triggersAfter every final user transcript, after every completed spoken reply, or both.Uses the answers alongside the conversation, for example to track sentiment or resolution. The agent never sees them.

For example, a car assistant can delegate "I feel a little cold" to a question with the choices temperature_up, temperature_down, and none. Your app turns up the heat and the agent replies, "I've turned up the heat for you." Meanwhile, a trigger can ask after every user turn whether the driver is frustrated.

Configure decisions

Add a decisions object to think in your first session.update. It can contain a delegation, a list of triggers, or both:

{
    "type": "session.update",
    "session": {
        "listen": {},
        "think": {
            "instructions": "You are a car assistant. When the driver mentions how the cabin feels, delegate to cabin. Keep replies to one sentence.",
            "decisions": {
                "delegation": {
                    "name": "cabin",
                    "description": "Decide which cabin controls to change for the driver's latest request.",
                    "questions": [
                        {
                            "type": "choice",
                            "name": "cabin_temperature",
                            "instructions": "Choose temperature_up if the driver feels cold, temperature_down if they feel hot, or none if unrelated.",
                            "choices": [{ "value": "temperature_up" }, { "value": "temperature_down" }, { "value": "none" }]
                        },
                        {
                            "type": "choice",
                            "name": "needs_response",
                            "instructions": "Choose yes if any part of the request goes beyond the cabin controls. Otherwise no.",
                            "choices": [{ "value": "yes" }, { "value": "no" }]
                        }
                    ]
                },
                "triggers": [
                    {
                        "id": "frustration",
                        "event_type": "conversation.item.input_audio_transcription.completed",
                        "questions": [
                            {
                                "type": "predicate",
                                "name": "frustrated",
                                "instructions": "Is the customer frustrated?"
                            },
                            {
                                "type": "score",
                                "name": "urgency",
                                "instructions": "How urgent is the customer's problem?",
                                "levels": [{ "label": "Can wait" }, { "label": "Soon" }, { "label": "Right now" }]
                            }
                        ]
                    },
                    {
                        "id": "resolved",
                        "event_type": "response.output_audio_transcript.done",
                        "questions": [
                            {
                                "type": "choice",
                                "name": "resolved",
                                "instructions": "Did the agent resolve the customer's issue?",
                                "choices": [{ "value": "yes" }, { "value": "no" }]
                            }
                        ]
                    }
                ]
            }
        },
        "speak": {}
    }
}

session.updated returns the effective block, including defaults, as session.think.decisions. The decisions block is fixed for the session.

Delegation fields

FieldRequiredDescription
delegation.nameNoThe name the agent knows the delegation by. Refer to it in think.instructions. Defaults to decide. Use 1–64 characters from A-Z, a-z, 0-9, _, and -. It can't match the name of a function in think.tools.
delegation.descriptionNoTogether with think.instructions, tells the agent when to delegate. Defaults to Ask for a decision about the user's latest request.
delegation.questionsYes1 to 10 questions. Each question needs a distinct name.
delegation.typeNoAlways decisions.

A session has at most one delegation.

Trigger fields

FieldRequiredDescription
trigger.event_typeYesconversation.item.input_audio_transcription.completed to run after each final user transcript, or response.output_audio_transcript.done to run after each completed spoken reply.
trigger.questionsYes1 to 10 questions. Each question needs a distinct name.
trigger.idNoReturned as trigger_id with every result. Defaults to trigger_<index>, the trigger's position in the list, such as trigger_0. IDs must be distinct and use the same characters as delegation.name.
trigger.typeNoAlways decisions.

A session can have at most two triggers, one for each event_type. To ask more about the same event, add questions to its trigger instead of adding another trigger.

Questions

Each question has a type, a name, and instructions. Describe the decision in instructions; the conversation is the evidence.

typeAsksExtra fields
choiceWhich of the choices applies?choices: 2 to 255 objects with a distinct string value and an optional description that helps tell similar choices apart.
predicateHow likely is the condition to be true?None.
scoreWhere does it fall on the ordered levels?levels: 2 to 10 objects, ordered lowest to highest, with a label and an optional description.
FieldRules
nameNot empty, up to 256 characters, and distinct within its list.
instructionsNot empty.
choices[].valueA non-empty string. Booleans aren't accepted: for a yes/no question, use the values "yes" and "no", or use a predicate.
levels[].labelNot empty.

The server rejects unknown fields at every level, so a misspelled field fails instead of silently turning a feature off. A decisions block that breaks any rule makes session.update fail with an invalid_request_error:

{
    "type": "error",
    "event_id": "event_abc123",
    "error": {
        "type": "invalid_request_error",
        "message": "<description of the invalid setting>"
    }
}

Delegate a decision

The agent decides whether to delegate based on think.instructions and delegation.description. When it does, the server asks the Decisions API the delegation's questions about the conversation and keeps the turn open until the answers arrive.

  1. The agent may speak a short preamble first, such as "Sure, one moment."
  2. Your client receives session.delegation.created with a delegation_id.
  3. Your client receives the outcome while the turn is still open: decision.completed with the answers, decision.failed, or decision.cancelled. Each carries the same delegation_id.
  4. The turn ends with response.done. The agent doesn't continue on its own.
  5. Your client acts on the answers, records what happened as a conversation item, and sends response.create for the agent's next reply.

Event order

response.created
response.output_item.added      (only if the agent speaks a preamble)
...                             (the preamble's audio and transcript deltas)
session.delegation.created      (can arrive between the preamble's deltas)
...                             (the rest of the preamble's audio)
decision.completed              (or decision.failed or decision.cancelled)
response.output_item.done       (only if there was a preamble)
response.done
{
    "type": "session.delegation.created",
    "event_id": "event_1n8U8pT5AkzqHg8zY0jZBK",
    "delegation_id": "dlg_3ANPBrp6C6fH2OziWnkirt",
    "response_id": "resp_5PiOth4qF9uUPsrszhCb6J"
}
{
    "type": "decision.completed",
    "event_id": "event_1MDIvBHA0JN5bBzDg9xy0x",
    "delegation_id": "dlg_3ANPBrp6C6fH2OziWnkirt",
    "response_id": "resp_5PiOth4qF9uUPsrszhCb6J",
    "item_id": "item_7XoXdHuiCjQitk9JiRQBHt",
    "answers": [
        { "type": "choice", "name": "cabin_temperature", "choice": "temperature_up", "probability": 0.996 },
        { "type": "choice", "name": "needs_response", "choice": "no", "probability": 0.777 }
    ]
}

item_id is the user turn the delegation was about. Only what the agent said appears in response.output and in the conversation; the delegation itself doesn't.

Act on the answers

Run the actions the answers call for. Then add what's now true to the conversation and request the next reply. Wait for response.done before you send response.create.

{
    "type": "conversation.item.create",
    "item": {
        "type": "message",
        "role": "system",
        "content": [{ "type": "input_text", "text": "Cabin temperature set to 22 °C." }]
    }
}
{
    "type": "response.create"
}

The agent also knows the answers to the questions it delegated (the chosen value for a choice, the probability for a predicate, and the score for a score), so its next reply can build on them. In the example, the agent replies, "I've turned up the heat for you."

For requests that need more than the agent can do on its own, add a question such as needs_response and, when it says yes, handle the request in your backend. Return only the short result to the conversation.

When there's no decision

EventWhen
decision.failedThe Decisions request failed, timed out, or returned an unreadable answer. The event includes error with type server_error and code decision_failed.
decision.cancelledThe user interrupted the turn, or your client sent response.cancel, before the answers arrived. The turn's response.done has status cancelled.

Both events carry delegation_id, response_id, and item_id. After a failure, the turn still ends with response.done, so decide in your client how to recover. For example, add a system message that the request couldn't be completed and send response.create.

Run decisions on every turn

Triggers run their questions after conversation events instead of waiting for the agent to ask:

event_typeRuns afterDoesn't run for
conversation.item.input_audio_transcription.completedA user's final transcript is added to the conversation, after its conversation.item.done.A final transcript with no words.
response.output_audio_transcript.doneA spoken reply finishes without interruption, after its response.done.A reply that was interrupted or failed, or a turn that said nothing, such as one that only delegated.

Triggers run separately from the conversation:

  • The agent never waits for trigger results and never sees them.
  • Up to 3 trigger decisions run at once per session. Others wait their turn; none are dropped. Delegations never wait behind triggers.
  • Results arrive as soon as they're ready, so they can arrive after later turns and out of order. Use item_id and response_id to match a result to its turn.
  • Results still outstanding when the session closes are dropped.
  • Triggers don't run in text-only sessions.

Trigger results use the same decision.completed and decision.failed events as delegations, with trigger_id and source_event_type instead of delegation_id. Triggers are never cancelled.

{
    "type": "decision.completed",
    "event_id": "event_6EJcUFRZvyC7RmSVKAkEEb",
    "trigger_id": "frustration",
    "source_event_type": "conversation.item.input_audio_transcription.completed",
    "item_id": "item_7XoXdHuiCjQitk9JiRQBHt",
    "answers": [
        { "type": "predicate", "name": "frustrated", "probability": 0.999 },
        {
            "type": "score",
            "name": "urgency",
            "score": 1.98,
            "probabilities": [
                { "value": 0, "probability": 0.005 },
                { "value": 1, "probability": 0.007 },
                { "value": 2, "probability": 0.988 }
            ]
        }
    ]
}
{
    "type": "decision.completed",
    "event_id": "event_1jj9M6VL7F7UAgRkviBgnP",
    "trigger_id": "resolved",
    "source_event_type": "response.output_audio_transcript.done",
    "item_id": "item_6RXpOWJR9EKsT1cn6sdG9r",
    "response_id": "resp_4ppvRBTLfSR3ayOypkZYQA",
    "answers": [{ "type": "choice", "name": "resolved", "choice": "yes", "probability": 0.998 }]
}

Decision events

FieldOnDescription
delegation_idDelegationsThe ID from session.delegation.created.
trigger_idTriggersThe trigger's id, or trigger_<index>.
source_event_typeTriggersThe trigger's event_type.
item_idAllThe item the decision was about: the user turn for a delegation or an input trigger, or the agent's spoken reply for an output trigger.
response_idDelegations and output triggersThe response that delegated, or that produced the reply.
answersdecision.completedOne answer per question, in question order.
errordecision.failedWhy no decision was made.

Answers

Every answer has a type and a name. Check type before you read the other fields; fields an answer doesn't have are left out.

typeFields
choicechoice, the chosen value, and probability, the probability of that value when available.
predicateprobability that the condition holds, from 0 to 1. There's no true/false verdict, so choose a threshold for acting on it.
scorescore, the probability-weighted level index from 0 to the number of levels minus 1, which can fall between levels. probabilities lists { "value": <level index>, "probability": <number> } for each level. Look up a level's label with levels[value].label.
refusalNo other fields. The Decisions API declined the question, or returned an answer it wasn't asked for, such as a value that isn't in choices. The other answers in the event still stand.

What Decisions sees

Each decision receives the conversation as text, oldest first, one line per message:

  • Included: what the user and the agent said, system messages your client added, earlier delegations and their answers, and your function calls and results.
  • Left out: model reasoning and think.instructions. Questions carry their own instructions.
  • A delegation sees the whole conversation. A trigger sees the most recent eight lines as of the event that fired it.
Conversation so far:
user: I feel a little cold.
assistant delegated to cabin
cabin decided: {"status": "completed", "answers": {"cabin_temperature": "temperature_up", "needs_response": "no"}}
system: Cabin temperature set to 22 °C.