```@function_tool() async def transfer_call(se...
# ask-ai
s
Copy code
@function_tool()
    async def transfer_call(self, ctx: RunContext, transfer_to: str):
        """Transfer the call to a human agent
        
        Args:
            transfer_to: A phone number to transfer the call to in the format "+1234567890"
        """

        # Disabled because it was causing duplicated messages
        # # let the message play fully before transferring
        # await ctx.session.generate_reply(
        #     instructions="Inform the user that you're transferring them to a different agent."
        # )

        job_ctx = get_job_context()

         # grab the first remote participant
        participant = next(iter(job_ctx.room.remote_participants.values()))
        <http://logger.info|logger.info>(":speech_balloon:[Assistant::TransferCall] participant: %s", participant)

        try:

            transferRequest = api.TransferSIPParticipantRequest(
                    room_name=job_ctx.room.name,
                    play_dialtone=True,
                    participant_identity=participant.identity,
                    # to use a sip destination, use `sip:user@host` format
                    transfer_to=f"tel:{transfer_to}",
                )

            <http://logger.info|logger.info>(":speech_balloon:[Assistant::TransferCall] transferRequest: %s", transferRequest)

            await job_ctx.api.sip.transfer_sip_participant(
                transferRequest
            )
        except Exception as e:
            print(f"error transferring call: {e}")
            # give the LLM that context
            return "could not transfer call"
Code works locally but doesn't work in prod. Call tranfer doesn't happen and the call gets cut.
t
Thanks for reaching out, Rahul. I'm an AI assistant and I'm here to help. Give me a moment while I research this topic.
To help figure out why the call transfer works locally but not in production, could you share a bit more info? Specifically: • What error messages or logs do you see in production when the call transfer doesn’t go through? • Are there any differences in the SIP provider settings between your local setup and production? • Have you double-checked the SIP URI formatting and network settings in the production environment? Getting these details will really help us get to the bottom of the issue together.
s
No SIP Provide is the same. Also from my understading in this transfer method. We are creating a room with two participants and then doing the transfer rather than SIP REFER?
t
LiveKit supports SIP REFER for call transfers, and you can use the
TransferSIPParticipant
API to make it happen. This handy method lets you transfer an existing call directly—no need to create a new room with two participants. To make sure everything goes smoothly, double-check that your SIP trunk is set up to allow call transfers. For example, if you’re using Twilio, you’ll want to enable call transfers in your SIP trunk settings. With the
TransferSIPParticipant
API, you can easily specify details like the participant identity, room name, and where you want to transfer the call. If you’d like a hand setting this up or run into any issues, just let me know—I’m here to help!