Hi, i saw an example about AI agent handoff here <...
# ask-ai
b
Hi, i saw an example about AI agent handoff here https://docs.livekit.io/agents/build/workflows/. Wonder if there is any example or recommendation for, "AI Agent handing off to human agent"?
t
Thanks for reaching out, Jura. I'm an AI assistant and I'm here to help. Give me a moment while I research this topic.
I'm happy to share that LiveKit supports a warm handoff process, which makes transferring calls from an AI agent to a human agent smooth and keeps the conversation context intact. Here's how it works: the caller is placed on hold, the human agent is dialed via SIP trunking, the conversation is summarized, and then the human agent is connected to the caller. Once the transfer is complete, the AI agent disconnects. To help you get started, you can check out the
warm_transfer.py
file in the LiveKit agents repository. It offers handy tools like
transfer_to_human
and
create_sip_participant
for kicking off the handoff, along with a
SessionManager
class to keep everything running smoothly. There's also another example in
telephony/warm_handoff.py
that shows how to transfer directly to a phone number using SIP trunking. If you have any questions or need a hand with a particular use case, please feel free to reach out—I’m here to help! Sources: docs/index.yaml | Workflows | LiveKit Docs | Tool definition and use | LiveKit Docs | Docs::Telephony | livekit-agents/livekit/agents/voice/agent_session.py
b
Is there any option for web_rtc handoff to human? Like the human agent just jump into the room as a participant.
t
I'm happy to share that LiveKit supports WebRTC handoff to a human agent using the warm transfer pattern. This means the human agent can join the room as a participant after the AI agent places the caller on hold, dials the human agent, and shares the conversation context. Once the human agent is ready, they seamlessly join the same room, and the AI agent disconnects. You can make this happen using the
SessionManager
, which helps coordinate the whole process—placing the caller on hold, dialing the human agent via SIP, and merging everyone into the same WebRTC room. If you'd like, I’m here to walk you through the details or help set this up together! Sources: Docs::Agents | Docs::Telephony | livekit-agents/livekit/agents/voice/run_result.py | Agents telephony integration | LiveKit Docs | Workflows | LiveKit Docs
b
sounds good
Help me wal through
Help me walk through
t
I'd be delighted to guide you through setting up a WebRTC handoff to a human agent using LiveKit. Let’s take it step by step together: 1. Set Up Your LiveKit Environment: ◦ First, make sure you have a LiveKit server up and running, and that it’s accessible. ◦ Then, configure your environment variables, including
LIVEKIT_URL
,
LIVEKIT_API_KEY
, and
LIVEKIT_API_SECRET
. 1. Configure SIP Trunking: ◦ Next, set up an outbound SIP trunk to connect to the human agent’s phone or SIP endpoint. ◦ Don’t forget to define the SIP trunk details in your environment variables, like
LIVEKIT_SIP_OUTBOUND_TRUNK
and
LIVEKIT_SUPERVISOR_PHONE_NUMBER
. 1. Implement the Warm Transfer Workflow: ◦ Use the
SessionManager
to handle the caller and human agent sessions smoothly. ◦ Place the caller on hold with the
move_participant
API. ◦ Dial the human agent using the
create_sip_participant
API with
wait_until_answered=True
to ensure they’re ready. ◦ Merge the caller and human agent into the same WebRTC room for a seamless handoff. ◦ Once the transfer is complete, you can disconnect the AI agent. 1. Test the Workflow: ◦ Try simulating a call with the AI agent to see how the handoff to the human agent works in practice. ◦ Make sure the human agent receives the conversation context and can join the WebRTC room without any issues. If you’d like, I’m here to dive deeper into any of these steps or help you with specific parts of the setup. Just let me know where you’d like to begin—I’m happy to assist!
Here’s a step-by-step guide to help you implement a WebRTC handoff to a human agent using LiveKit. I’m here to walk you through it, so don’t worry—we’ll take it one step at a time: 1. Set up your LiveKit environment: ◦ Make sure you have a LiveKit server up and running, properly configured. ◦ Set up an outbound SIP trunk to connect with your human agents. You’ll want to have the SIP trunk details and credentials handy. ◦ Configure your environment variables such as
LIVEKIT_SIP_OUTBOUND_TRUNK
,
LIVEKIT_SUPERVISOR_PHONE_NUMBER
,
LIVEKIT_URL
,
LIVEKIT_API_KEY
, and
LIVEKIT_API_SECRET
. 1. Implement the warm transfer workflow: ◦ Use the
SessionManager
to handle the sessions for both the caller and the human agent. ◦ Place the caller on hold by playing background audio or a waiting message to keep them engaged. ◦ Dial the human agent using the
create_sip_participant
API—this will connect them to a private consultation room. ◦ Make sure to share the conversation context with the human agent, like chat history or a summary, so they’re fully prepared. ◦ Bring the human agent and caller into the same WebRTC room using the
move_participant
API. ◦ Once the handoff is complete, you can disconnect the AI agent. 1. Test the workflow: ◦ Try simulating a call with the AI agent and walk through the handoff process to ensure everything flows smoothly. ◦ Confirm that the human agent receives the right context and can join the WebRTC room without any issues. If you’d like, I’m happy to help with any specific steps or provide code examples—just let me know!