wide-dress-57902
08/12/2025, 12:14 AMtall-airline-16756
08/12/2025, 12:14 AMtall-airline-16756
08/12/2025, 12:15 AMagent.say()
method right after the connection is made. Here’s a quick rundown of how to do it:
1. First, set up your agent with explicit dispatch to make sure outbound calls are routed correctly.
2. Next, create a SIP participant to kick off the outbound call to the phone number you want.
3. Then, as soon as the participant connects, use agent.say()
so your agent can start talking.
Here’s a little example to guide you:
async def entrypoint(ctx: JobContext):
# Create the SIP client and dial the phone number
sip_client = SipClient(
LIVEKIT_URL,
LIVEKIT_API_KEY,
LIVEKIT_API_SECRET
)
trunk_id = "your-trunk-id"
phone_number = "+1234567890"
room_name = ctx.room.name
participant_identity = "outbound-call"
# Create the SIP participant to dial the phone number
await sip_client.create_sip_participant(
trunk_id,
phone_number,
room_name,
participant_identity
)
# Wait for the participant to connect
participant = await ctx.wait_for_participant(participant_identity)
# Initialize your agent
agent = VoicePipelineAgent(...)
# Start the agent and have it speak immediately
agent.start(ctx.room, participant)
await agent.say("Hello! How can I assist you today?", blocking=True)
This way, your agent will greet the user right when they pick up the call. If you want to dive deeper or have any questions, just let me know—I’m here to help!wide-dress-57902
08/12/2025, 12:18 AMtall-airline-16756
08/12/2025, 12:18 AMctx.wait_for_participant
method in LiveKit is a handy asynchronous function that waits for someone to join a room. When they do, it gives you back a RemoteParticipant
object representing that participant, so you can easily interact with them.
You can even filter by their identity
and kind
, and if the participant is already there, it’ll return right away. It’s super useful when you want to kick off actions as soon as someone connects.
Sources: examples/voice_agents/realtime_joke_teller.py