This page requires Python familiarity. It covers the return interface for functions written in Python.
String return
You can return a simple string, which will be used as the system prompt for the virtual agent:Dictionary return
You can return a dictionary to specify more detailed and deterministic instructions. The following fields can be used individually or in combination.content
Equivalent to returning a string, this field specifies the system prompt:
utterance
Specifies the exact phrase the virtual agent will deliver after executing the function (spoken for voice, displayed for webchat):
content and utterance are returned:
- The agent will stream the
utteranceto the user and end the turn. - The
contentrules will apply to the next turn.
handoff
Initiates a call handoff after the function executes. The type and reason fields match your configured handoff destination. The nested object specifies the SIP method.
- SIP REFER (default)
- SIP INVITE
- SIP BYE
Transfers the call and drops PolyAI from it:
hangup
Ends the conversation after the function executes. For voice, this disconnects the call; for webchat, this closes the session:
listen
Configures the agent to listen on the next turn. Must be combined with an utterance for ASR timeout settings to take effect.
listen object supports these configuration keys:
| Key | Type | Description |
|---|---|---|
listen | bool | Whether to listen for input (default True) |
delayed_response | bool | Enable delayed response mode — the client sends an empty input to retrieve the response |
asr | dict | ASR configuration: timeout, keywords, custom_biases, fields, corrections |
dtmf | dict | DTMF configuration: num_digits, first_digit_timeout, inter_digit_timeout, finish_on_key, early_listening, is_pii |
channel | str | Input channel: "SPEECH" (default), "DTMF", or "SPEECH_AND_DTMF" |
barge_in | dict | Barge-in configuration: is_enabled, interruption_window |
smart_vad | dict | Smart VAD configuration: is_enabled, max_extensions, max_extension_duration |
interjection | dict | Interjection configuration: enable, frequency (seconds) |
ASR timeout doesn’t apply to DTMF-only input. If using both channels, make sure you include an
utterance so the ASR settings take effect.variant
Switches the conversation to a different variant. The value must match an existing variant name configured in variant management. This is useful for routing callers to location-specific or segment-specific conversation flows mid-call.
variant with utterance to confirm the switch to the user:
Combining return fields
You can return multiple fields together. Common combinations:utterance + handoff
utterance + handoff
Say something before transferring — the most common handoff pattern:
utterance + hangup
utterance + hangup
Say a closing message before ending the call:
utterance + content
utterance + content
Deliver a specific phrase now and set instructions for the next turn:

