This page requires Python familiarity. It covers the return interface for functions written in Python. Return a string or dictionary from your function to control the agent’s next action, including what to say, whether to transfer the call, or how to configure listening behavior.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.
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:
conv.call_handoff(), which supports dynamic destination, reason, and utterance parameters. Use the dictionary return for fine-grained SIP control; use conv.call_handoff() for simpler routing.
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. Use this to route 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:
Related pages
Start tool
Return values supported in the start function.
Delay control
Add filler phrases while long-running functions execute.
Transition functions
Return values in the context of flow step routing.

