faint-gold-41196
03/19/2026, 4:04 AMtall-airline-16756
03/19/2026, 4:04 AMtall-airline-16756
03/19/2026, 4:04 AMfaint-gold-41196
03/19/2026, 5:59 AMtall-airline-16756
03/19/2026, 5:59 AMfrom livekit_agents import WarmTransferTask, AgentsClient
# Initialize client (fill in with your auth)
client = AgentsClient(api_key="LIVEKIT_API_KEY")
# Variables
room_id = "room-1234" # room with caller and AI agent
caller_participant = "caller-1"
human_phone_number = "+15551234567"
hold_audio_url = "https://example.com/hold-music.mp3"
transfer_metadata = {
"transcript": "... recent transcript ...",
"summary": "Caller needs billing assistance; account #12345",
}
# Create the WarmTransferTask
task = WarmTransferTask(
room_id=room_id,
from_participant="ai-agent", # the AI agent participant
to_sip_number=human_phone_number,
hold_audio_url=hold_audio_url,
metadata=transfer_metadata,
sip_trunk="your-sip-trunk-id" # identifier configured in LiveKit
)
# Run the task (this will dial the human, play hold to caller, and bridge)
result = client.run_task(task)
if result.success:
print("Warm transfer completed; human connected.")
else:
print("Warm transfer failed:", result.error_message)
Notes:
• The exact class/method names and parameters might vary with SDK versions; use the SDK docs for exact signatures.
• sip_trunk represents the outbound trunk configured in LiveKit to reach your SIP provider.
Alternative: Manual implementation without WarmTransferTask If you prefer custom control (or the task isn’t available), implement the same steps manually:
1. Place caller on hold
◦ Mute caller’s microphone track if needed and inject hold music audio into the caller’s subscribed track.
1. Create SIP participant
◦ Call LiveKit’s CreateSIPParticipant API with the destination number and trunk details. Example payload fields:
▪︎ `room`: room_id
▪︎ `display_name`: "Human Agent"
▪︎ `sip`: destination URI (e.g., sip:+15551234567@provider.example.com)
▪︎ `trunk`: trunk identifier for outbound routing
▪︎ `metadata`: conversation summary / context
1. Monitor SIP call state
◦ Listen for events: ringing, answered, failed, busy, no-answer.
◦ When answered, confirm audio connectivity.
1. Bridge audio
◦ Once human answers, connect their audio into the caller’s room. Ensure:
▪︎ Caller hears human and human hears caller.
▪︎ AI agent is either muted/disconnected as desired.
1. Tear down / cleanup
◦ If AI disconnects, ensure the room participant state is updated and resources freed.
◦ Log timestamps and results (transfer start, answer, bridge complete).
Key API points to use
• CreateSIPParticipant: to dial the human via your SIP trunk.
• Participant update events: to track answered/connected state.
• Room media controls: to play hold music and to connect/disconnect participants.
Practical configuration tips
• SIP trunk setup: ensure authentication, codecs (e.g., PCMU/PCMA, Opus if supported), and NAT traversal (SRTP, TLS) are configured with your provider.
• Hold music: short looped MP3 or an RTP stream; ensure format matches room expectations.
• Conversation context delivery: send a webhook or populate a UI with metadata so the human sees prior transcript and summary before they pick up.
• Timeouts: set sensible timeouts for dialing human (e.g., 25–45s) and fallback behavior (voicemail, callback, route to backup agent).
• Retries & fallback: on failure, try alternate agents or escalate to supervisor.
• Monitoring: expose transfer events to your monitoring/analytics for QA.
• Privacy & compliance: ensure you handle PII/transcripts according to regulations (store minimal data in metadata).
Failure modes and recovery
• Human doesn’t answer: unbridge, play message to caller, retry another agent, or fall back to voicemail.
• SIP trunk failure: detect and attempt alternate trunk or notify system.
• Audio mismatch (codec/NAT): ensure supported codecs and ICE/STUN/TURN configuration; monitor for one-way audio and adjust codecs or trunk settings.
What I can provide next
• Exact example API payloads for CreateSIPParticipant if you tell me your SIP provider.
• A full working sample (expanded Python script) wired to your LiveKit API keys and room flow.
• Troubleshooting steps for common issues (one‑way audio, registration, REFER support).
• UI examples for surfacing conversation context to the human agent.
Please tell me:
• Which SIP provider you’re using (Twilio, Telnyx, Plivo, etc.), or if you need provider‑agnostic instructions.
• Whether you want the AI to drop off after the bridge or stay for monitoring.
With that I’ll give you precise API call examples and a complete runnable sample.
, with interactive elements