Handing off from function code
Functions can send a caller to a destination by name:- the destination depends on the conversation, for example opening hours or which site the caller is calling about;
- something has to happen before the transfer, such as writing a ticket or setting SIP headers from the conversation;
- the conversation is a chat. Connect your live-chat platform in Messaging, then ask Wren to add the handoff to a function.
destination must match the name of a destination on the Handoffs page.
Handoff reason and utterance
The built-in handoff template and theconv.call_handoff() helper accept two optional, structured fields. When the agent hands off by itself through handoff reasons, the reason’s key is recorded as reason.
Where it shows up
- Flows & KB actions – Selecting builtin-handoff displays Reason and Pre-handoff utterance fields.
- Functions – Call
conv.call_handoff(destination="...", reason="...", utterance="...")to escalate programmatically. - Conversation Review – Both fields appear in the metadata panel for quick troubleshooting.
- Conversations API – Returned inside the
handoffobject for BI dashboards or CRM routing.
- Removes guesswork when diagnosing handoffs – no more relying on LLM summaries alone.
- Enables fine-grained routing rules in telephony or CRM systems.
- Gives QA teams full visibility into the exact wording customers heard.
Handoff context handover
When the agent transfers a caller to a human, the human-side system needs context about what already happened. PolyAI exposes that context through three complementary channels — pick whichever your contact-center platform supports.
The data the agent writes (and the human therefore sees) is whatever you choose to store. Common fields:
For the Handoff API specifically, the fields below must be configured for your project before they’re exposed via
GET /handoff_state — contact your PolyAI representative to set this up. See Before you start.- Identifiers –
customer_id,account_number,shared_idlinking the PolyAI conversation to a record in your CRM - Verification status –
successfully_identified,auth_method,verification_attemptsso the agent doesn’t ask the caller to re-verify - Reason for escalation – machine-readable
reason(e.g.policy_violation,complaint_escalation,customer_refund); see Handoff reason and utterance - Pre-handoff utterance – the exact wording the agent used before transferring, logged for QA
- Caller intent and slots – any entities collected during the AI portion of the call (order ID, refund amount, preferred callback time)
Writing context from a function
destination parameter must match a handoff configured under Integrations > Telephony > Handoffs. The reason and utterance surface in Conversation Review and the Conversations API; the sip_headers are merged with any headers configured on the destination, with values passed here taking precedence.
Webchat and SMS handoffs
Webchat and SMS use the same conceptual model but signal the handoff over the Chat API: thechat/respond response includes a handoff object with destination and reason, and end_conversation is set to true. Your widget or SMS connector then routes the session to your live-chat platform and retrieves the full context via the Handoff API. See Webchat and SMS handoff via the Chat API for the integration steps.
Feedback loops from the human side
Once a human has handled the escalation, you can close the loop in two ways:- Tag the conversation in Conversation Review. Live agents (or QA reviewers) can apply annotations such as Escalated unnecessarily or Wrong topic directly on the PolyAI conversation. Tagged calls surface in QA workflows and in the conversations Wren analyzes.
- Push outcomes back via the Conversations API. If your CRM captures a resolution code on the human-handled portion, attach it back to the conversation by
shared_id. This pairs the agent’sreasonfield with the human’s actual outcome, which is what Wren needs to answer questions like “What share of complaint escalations were resolved on first contact?”.
Comparison: Call Handoff and the transfer_call function
These two methods serve similar purposes – routing the user to another endpoint – but are mutually exclusive and differ in flexibility and implementation.
In the table below, means the feature is supported and – means it is not supported.
The UI-based Call Handoff does not support custom metrics. Use
transfer_call with conv.write_metric() if you need handoff reason codes for analytics.
When to use each method
UseCall Handoff if:
- You want a quick setup through Dialog Studio with minimal code.
- Your routing needs are straightforward and based on static values.
transfer_call if:
- You need to pass dynamic SIP headers (e.g., customer metadata).
- You want to use soft handoffs or log custom handoff metrics.
- You’re integrating with a platform that does not support SIP REFER (e.g. Zendesk).
Voicemail detection
PolyAI can detect voicemail in certain scenarios, but the behavior depends on the call direction and handoff method.Outbound calls
For outbound calls, PolyAI supports project-level voicemail detection. A detection flow at the start of the call classifies what the agent hears before the conversation begins. Common classifications include human, IVR, voicemail, and number not in service – though the exact categories depend on how the project is configured. Based on the classification, the agent typically routes into the appropriate path. For example:- Human – proceed to the greeting and main conversation flow
- IVR – enter an IVR traversal flow (DTMF navigation, hold loops)
- Voicemail – leave a message or hang up, depending on project requirements
- Number not in service – end the call
Inbound SIP handoffs
When PolyAI transfers an inbound call to an agent (via SIP REFER, SIP INVITE, or SIP BYE), voicemail detection on the destination side is not available by default. The behavior depends on the handoff method:- SIP REFER / SIP BYE – PolyAI drops from the call after initiating the transfer, so it has no visibility into whether the destination answers or goes to voicemail.
- SIP INVITE – PolyAI bridges both call legs, which provides more visibility during the transfer. However, automated voicemail detection on the destination side is not a standard feature.

