How to Transfer SIP Calls to Another Number in voice-pipeline-agent-python?
Hello,
I am currently working on a simple demo using voice-pipeline-agent-python and have successfully configured the SIP settings as required. However, I am looking to implement a feature where, after a user dials a number and enters the logic of the VoicePipelineAgent, they can trigger a signal that redirects the call to another number for manual response.
Here's what I have so far, and I'm wondering how I can proceed to achieve the call transfer functionality:
The user dials a number and is connected to the VoicePipelineAgent.
At some point during the interaction, the user triggers a specific signal. Upon receiving this signal, I want the call to be transferred to another predefined number for human manual handling.
I have reviewed the documentation, but I'm not sure how to implement this feature within the voice-pipeline-agent-python framework. Could someone please guide me on the steps or provide an example of how to achieve this?
Thank you in advance for your help!
I am also being faced same problem plz solve this as soon as possible
Like in the cold transfer docs, you could do the following
# assuming ctx is JobContext, participant is the user (i.e. ctx.wait_for_participant())
livekit_api = api.LiveKitAPI()
transfer_to = '+14155550100'
# Create transfer request
transfer_request = TransferSIPParticipantRequest(
# indicate the participant to transfer out
participant_identity=participant.identity,
# name of the current room
room_name=ctx.room.name,
transfer_to=transfer_to,
)
logger.debug(f"Transfer request: {transfer_request}")
# Transfer caller
await livekit_api.sip.transfer_sip_participant(transfer_request)
Hello,
I am attempting to handle call transfers using LiveKit in a voice assistant. The assistant listens for user responses (yes or no) and initiates a transfer to the billing department when the response is affirmative. Despite following the documentation and implementing the SIP transfer process, the call transfer does not happen.
Previously, I was able to handle call transfers successfully using DTMF handling, where the assistant listens for keypad inputs (e.g., pressing a specific number) and responds accordingly. However, the same process does not seem to work with voice-triggered responses.
Expected Behavior
The call should be transferred to the billing department's phone number provided in the .env.local file as BILLING_PHONE_NUMBER.
Observed Behavior
The assistant verbally confirms the transfer, but the actual SIP transfer does not take place. The call remains in the current room, and no error logs indicate why the transfer failed.
Code Snippets
1. Handling Call Transfer
Below is the code snippet for initiating the SIP call transfer:
async def handle_transfer(room_name: str, participant_identity: str, assistant: VoiceAssistant) -> None:
try:
transfer_number = os.getenv('BILLING_PHONE_NUMBER')
if not transfer_number:
raise ValueError("Billing phone number not configured")
if not transfer_number.startswith('+'):
transfer_number = f"+{transfer_number}"
await assistant.say("Transferring you to our billing department. Please hold.", allow_interruptions=False)
livekit_api = api.LiveKitAPI(
url=os.getenv('LIVEKIT_URL'),
api_key=os.getenv('LIVEKIT_API_KEY'),
api_secret=os.getenv('LIVEKIT_API_SECRET')
)
transfer_uri = f"tel:{transfer_number}"
transfer_request = proto_sip.TransferSIPParticipantRequest(
room_name=room_name,
participant_identity=participant_identity,
transfer_to=transfer_uri,
play_dialtone=False
)
logger.info(f"Initiating transfer for participant {participant_identity} to {transfer_uri}")
await livekit_api.sip.transfer_sip_participant(transfer_request)
await asyncio.sleep(2)
await assistant.cleanup()
logger.info("Transfer completed, exiting process")
os._exit(0)
except Exception as e:
logger.error(f"Transfer failed: {e}", exc_info=True)
await assistant.say("I apologize, but I couldn't transfer your call. Please try again later.", allow_interruptions=True)
2. Handling yes/no Responses
Below is the implementation for handling user responses and deciding whether to transfer the call:
@assistant.on_message
async def handle_message(message: str):
message = message.lower().strip()
if message in ["yes", "yeah", "sure", "okay", "correct", "yep"]:
participants = list(ctx.room.participants.values())
if not participants:
logger.error("No participants found in room")
await assistant.say("I'm sorry, but I cannot process the transfer at this moment.", allow_interruptions=True)
return
participant = participants[0]
logger.info(f"Attempting transfer for participant: {participant.identity}")
await handle_transfer(ctx.room.name, participant.identity, assistant)
elif message in ["no", "nope", "not now", "nah"]:
await assistant.say("Alright, is there something else I can help you with?", allow_interruptions=True)
else:
await assistant.say("Would you like me to transfer you to our billing department? Please say 'yes' or 'no'.", allow_interruptions=True)
What I Tried
- Attempted debugging the
transfer_sip_participantcall, but found no relevant error logs.
Questions
- Is the SIP transfer feature supported for this use case in LiveKit?
- Are there additional configurations or permissions required for SIP transfers to work?
- Could there be a potential issue with the LiveKit SDK or API?
- Why does the transfer work as expected when using DTMF handling (listening for keypad inputs) but fails when using
yes/novoice responses? Are there additional steps or considerations required for voice-based triggers?
Environment
- LiveKit SDK Version: (Please specify)
- Python Version: (e.g., 3.10)
- OS: (e.g., Ubuntu 22.04)
Any insights or guidance would be greatly appreciated! Let me know if you need additional logs or context.
I get a deadline_exceeded error
facing issue in cold transfer timeout error
I will add a variable for same issue. I can see in my logs transfer_sip_participant is at least tried but rejected due to participant_identity mismatch. I have been looking which is the moment participant_identity is know to room and the event to use to ensure identity is the right one. Is there an example more detailed about this use case ??
@function_tool()
async def transfer_call(self, participant_identity: str, room_name: str) -> str:
logger.debug("function_tool: transfer_call invoked")
priority = self.customer_metadata.get("priority")
if priority == 1:
async with api.LiveKitAPI() as livekit_api:
transfer_to = 'tel:+888'
transfer_request = TransferSIPParticipantRequest(
participant_identity=participant_identity,
room_name=room_name,
transfer_to=transfer_to,
play_dialtone=False
)
logger.info(f"Transfer request: {transfer_request}")
await livekit_api.sip.transfer_sip_participant(transfer_request)
logger.debug(f"Successfully transferred participant {participant_identity} to {transfer_to}")
return "Su llamada está siendo transferida a Servicio a Clientes. Por favor, espere en la línea."
else:
logger.debug(f"Transferencia no permitida para cliente prepago ({participant_identity})")
return "Lo sentimos, solamente los clientes postpago pueden ser transferidos a Servicio a Clientes. ¿Hay algo más en lo que pueda ayudarle?"
Error logs showing the situation ..
2025-11-13 18:23:35,101 - DEBUG livekit.agents - http_session(): creating a new httpclient ctx {"pid": 75824, "job_id": "AJ_GGa66ZVBPo9p"}
2025-11-13 18:23:36,205 - DEBUG livekit.agents - using audio io: RoomIO -> AgentSession -> TranscriptSynchronizer -> RoomIO {"pid": 75824, "job_id": "AJ_GGa66ZVBPo9p"}
2025-11-13 18:23:36,205 - DEBUG livekit.agents - using transcript io: AgentSession -> TranscriptSynchronizer -> RoomIO {"pid": 75824, "job_id": "AJ_GGa66ZVBPo9p"}
2025-11-13 18:23:36,214 - DEBUG livekit.agents - start reading stream {"participant": "sip_1500", "source": "SOURCE_MICROPHONE", "pid": 75824, "job_id": "AJ_GGa66ZVBPo9p"}
2025-11-13 18:23:55,271 - DEBUG livekit.plugins.openai - OpenAI Realtime API response done but not complete with status: cancelled {"event_id": "resp_CbVIJZBDh2BZOi3XnPXEr", "event_response_status": "cancelled", "pid": 75824, "job_id": "AJ_GGa66ZVBPo9p"}
2025-11-13 18:24:00,236 - DEBUG livekit.agents - executing tool {"function": "transfer_call", "arguments": "{ \n "room_name": "soporte_técnico", \n *"participant_identity": "usuario*" \n} \n", "speech_id": "speech_9351db72edd7", "pid": 75824, "job_id": "AJ_GGa66ZVBPo9p"}
2025-
The Code for Event that never get triggered altough I can see in logs there is indeed a participant
def on_participant_joined(p):
# En este evento ya está `identity` disponible
participant_identity = getattr(p, "identity", None)
asyncio.create_task(handle_real_join(participant_identity, p))
# Registra el evento para que sólo se ejecute CUANDO el participante SIP real esté disponible
ctx.room.on("ParticipantConnected", on_participant_joined)