Skip to main content
Most agents only need handoff reasons and destinations, set up without code. Use this page when the handoff needs logic.

Handing off from function code

Functions can send a caller to a destination by name:
Use a function instead of a reason when:
  • 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.
The destination must match the name of a destination on the Handoffs page.

Handoff reason and utterance

The built-in handoff template and the conv.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.
When using SIP REFER, the utterance may not play before the transfer completes because the REFER fires at the same time as function execution. If you need the utterance to be spoken reliably before transfer, use SIP INVITE instead.
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 handoff object for BI dashboards or CRM routing.
Benefits
  • 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_id linking the PolyAI conversation to a record in your CRM
  • Verification status – successfully_identified, auth_method, verification_attempts so 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)
Choose one channel as the source of truth and keep the others consistent with it. SIP headers must be set explicitly on each handoff destination or via conv.call_handoff(sip_headers={...}); the Handoff API draws on the conv.state fields configured for your project, so keep those two in sync if you use both.

Writing context from a function

The 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: the chat/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:
  1. 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.
  2. 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’s reason field 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 two methods can’t be combined in one step — transfer_call overrides any UI-configured Call Handoff. If you use it, keep destination mappings in sync manually; UI changes don’t propagate to function-based transfers.
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

Use Call Handoff if:
  • You want a quick setup through Dialog Studio with minimal code.
  • Your routing needs are straightforward and based on static values.
Use 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
Detection uses barge-in on the first turn, since voicemail systems and IVRs do not wait for the agent to finish speaking. This is a project-level configuration – contact your PolyAI representative to set it up. See Outbound calling for more on outbound call configuration.

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.
If you need voicemail detection as part of your inbound handoff workflow, contact your PolyAI representative to discuss what’s possible for your specific setup.
Last modified on December 3, 2026