colossal-lock-10836
08/18/2025, 6:19 AMtall-airline-16756
08/18/2025, 6:20 AMtall-airline-16756
08/18/2025, 6:20 AMlk sip outbound create outbound-trunk.json
2. Create the Agent: Next, use the LiveKit CLI to create the "upsell_agent" specifically for outbound calls. Here's how:
lk app create --template=outbound-caller-python
Just make sure the agent is linked with the outbound trunk ID you set up. 3. Dispatch the Agent for Outbound Calls: Finally, assign the "upsell_agent" to the outbound call using this command (swap out +15105550100
with the phone number you want to dial):
lk dispatch create \
--new-room \
--agent-name upsell_agent \
--metadata '+15105550100'
This will create a new room, connect "upsell_agent" to the call, and dial the number. Once the person answers, your agent will jump right in and handle the conversation. If you have any questions or need a hand with anything else, just let me know—I’m here to help! """ Sources: Making calls using SIP | LiveKit Docs | Making calls using SIP | LiveKit Docs | agent.pycolossal-lock-10836
08/18/2025, 6:30 AMtall-airline-16756
08/18/2025, 6:30 AMCreateSIPParticipant
API to kick off the outbound call. Just include the room name where you want the agent to join, the SIP trunk ID, and the phone number you’re calling. Here’s an example:
request = CreateSIPParticipantRequest(
room_name="room_name_here",
sip_trunk_id="ST_yxT8oGHqoaAL",
sip_call_to="221223",
participant_identity="sip-test",
participant_name="Test Caller",
krisp_enabled=True,
wait_until_answered=True,
)
2. Wait for the Participant to Join: After you create the SIP participant, wait for them to actually join the room:
participant = await ctx.wait_for_participant(identity="sip-test")
3. Start the Agent Session: Once the participant is in, you can start the agent session with the room and participant. Like this:
session_started = asyncio.create_task(
session.start(
agent=upsell_agent,
room=ctx.room,
room_input_options=RoomInputOptions(
noise_cancellation=noise_cancellation.BVCTelephony(),
),
)
)
4. Ensure Agent Interaction: The agent will automatically jump in and interact with the participant once the session starts. Just double-check that the agent is set up to handle the call flow, including any greetings or other interactions needed. If you have any questions or want me to walk you through any part of this, just let me know—I’m here to help! Sources: Agents telephony integration | LiveKit Docs | agent.pycolossal-lock-10836
08/18/2025, 6:31 AMtall-airline-16756
08/18/2025, 6:32 AM--new-room
flag when you dispatch the call. Here’s a quick guide to help you out: 1. Use the Dispatch Command: Run this command to set up a new room for every outbound call:
lk dispatch create --new-room --agent-name upsell_agent --metadata '+15105550100'
Just swap out +15105550100
with the phone number you want to call. 2. Make Sure Each Room is Unique: Every time you run this command, a fresh room is created, so each call has its own private space. If you have any questions or need a hand with anything else, feel free to ask! """colossal-lock-10836
08/18/2025, 6:32 AMtall-airline-16756
08/18/2025, 6:33 AMpython import os import asyncio from livekit import api async def create_outbound_call(phone_number, agent_name="upsell_agent"): # Initialize LiveKit API lkapi = api.LiveKitAPI() try: # Create a unique room name room_name = f"outbound-call-{int(asyncio.get_event_loop().time())}" # Dispatch the agent to the new room dispatch = await lkapi.agent_dispatch.create_dispatch( api.CreateAgentDispatchRequest( agent_name=agent_name, room=room_name, metadata=phone_number # Add metadata if needed ) ) print(f"Created dispatch: {dispatch}") # Create SIP participant for the outbound call sip_participant = await lkapi.sip.create_sip_participant( api.CreateSIPParticipantRequest( room_name=room_name, sip_trunk_id="ST_yxT8oGHqoaAL", # Replace with your SIP trunk ID sip_call_to=phone_number, participant_identity="outbound-agent", ) ) print(f"Created SIP participant: {sip_participant}") except Exception as e: print(f"Oops, something went wrong: {e}") finally: await lkapi.aclose() # Example usage async def main(): await create_outbound_call("+1234567890") # Replace with the target phone number if __name__ == "__main__": asyncio.run(main())
### Key Steps: 1. Room Creation: We generate a unique room name for each call to keep things organized. 2. Agent Dispatch: The agent (like "upsell_agent") is sent over to the new room. 3. SIP Participant: This part sets up a SIP participant to kick off the outbound call. Just swap out ST_yxT8oGHqoaAL
with your actual SIP trunk ID and +1234567890
with the phone number you want to call. If you hit any bumps or have questions, feel free to ask—I’m here to help!colossal-lock-10836
08/18/2025, 6:54 AMtall-airline-16756
08/18/2025, 6:55 AMcreate_sip_participant
method. No worries though, here’s a simple way to fix it: 1. Double-check Argument Types: Make sure every argument you pass to create_sip_participant
is exactly the type it expects. For instance: - sip_trunk_id
should be a string that starts with "ST_". - sip_call_to
should be a valid phone number in string format. 2. Verify Your SIP Trunk ID: Take a moment to confirm that your SIP_TRUNK_ID
is formatted correctly and starts with "ST_". You can easily check this with the LiveKit CLI by running:
lk sip outbound list
3. Update Your Code: Make sure your code follows the right pattern. Here’s an example:
sip_participant = await lkapi.sip.create_sip_participant(
api.CreateSIPParticipantRequest(
room_name=room_name,
sip_trunk_id=SIP_TRUNK_ID, # This should be a valid string
sip_call_to=phone_number, # This should be a valid phone number string
participant_identity="callee",
participant_name="Outbound Callee",
)
)
4. Catch Exceptions with Care: It’s helpful to add some detailed exception handling to catch any specific errors:
except api.TwirpError as e:
print(f"Error creating SIP participant: {e.message}, "
f"SIP status: {e.metadata.get('sip_status_code')} "
f"{e.metadata.get('sip_status')}")
If you’re still running into trouble or want me to walk through anything else, just let me know—I’m here to help!