Call Transfer Agent
Explore the Implementation
git clone https://github.com/vobiz-ai/Vobiz-Livekit-Call-Transfer-Example.git
cd Vobiz-Livekit-Call-Transfer-ExampleThis example demonstrates how to perform a SIP cold-transfer (SIP REFER) using LiveKit Agents mapped over a Vobiz SIP trunk. By injecting explicit E.164 boundary formats alongside unified alias tables (like "sales" and "support"), the LLM natively resolves physical dial operations natively via the api.TransferSIPParticipantRequest framework natively discarding the agent thread safely to mitigate compute costs.
How It Works
The SIP REFER architecture securely isolates AI computation execution boundaries by definitively removing the agent once an intent triggers an explicit geographic network location transfer structurally bridging the caller independently identically to PBX servers.
- The Conversational Loop: The LiveKit agent inherently answers strictly evaluating the
ctx.job.metadata.phone_numberto differentiate inbound behavior hooks versus an outbound dial response configuration actively leveraging OpenAI and Deepgram arrays. - LLM Tool Invocation: Based on the system prompt instructions, if the user asks to speak to "billing", the LLM triggers the
transfer_call(destination="billing")function attached natively to theTransferToolstool context class. - SIP URI Transformation: Deeply intertwined formatting string logic filters explicit aliases seamlessly out of localized dictionaries, reconstructing absolute endpoints mapping perfectly to the explicitly defined
sip:+15550002222@vobiz_environment_domaintargeting parameter required by LiveKit arrays natively. - Vobiz Network Execution: LiveKit pushes the structurally-valid SIP REFER message directly upstream bypassing the AI runtime container implicitly terminating the LiveKit session lifecycle. Vobiz fundamentally detects the SIP Refer packet explicitly, initiates an out-of-band external PSTN connection, directly joining the external carrier endpoints absolutely organically.
Implementation Code
When the active LiveKit Session participant triggers an explicit SIP traversal routine natively tied against the Vobiz trunk, a standard REFER event gracefully kills the active context instance asynchronously forwarding the bridge logic universally.
from livekit.agents import llm
class CallingTools(llm.ToolContext):
@llm.function_tool(description="Transfer the caller to an E.164 phone number directly")
async def cold_transfer(self, target_phone: str):
"""Directly references the Active Vobiz trunk binding routing external requests via sip:"""
transfer_uri = f"sip:{target_phone}@vobiz.ai"
# Emits a standard SIP REFER payload securely bypassing LiveKit architectures
await self.local_participant.perform_sip_refer(transfer_to=transfer_uri)
return "Transfer executing immediately. Terminating stream."