hey i just launched an agent on the clound for out...
# ask-ai
b
hey i just launched an agent on the clound for outbound call what is the easiest to make different call at the same time, where there is one room between the caller and an agent, and repeat this to have several induviduals on the phone
t
Thanks for reaching out, timothe. I'm an AI assistant and I'm here to help. Give me a moment while I research this topic.
Hi there! Just to make sure I understand your needs correctly, are you using SIP telephony for these outbound calls, or are you aiming to manage general room connections programmatically? Knowing this will really help me guide you to the best solution for your setup. I'm here to help! Sources: SIP dispatch rule | LiveKit Docs | Inbound calls with Twilio Voice | LiveKit Docs | Tests/LiveKitTestSupport/Room.swift | examples/multiple_connections.py | sample-app-common/src/main/java/io/livekit/android/sample/CallViewModel.kt
b
i am using sip telephony
t
I'm glad you're looking to manage multiple simultaneous calls with SIP telephony! A great way to do this is by using SIP Dispatch Rules, which help automatically create individual rooms for each caller. Let me walk you through how you can set this up: 1. Using the LiveKit Cloud Dashboard: 1. First, sign in to the LiveKit Cloud dashboard. 2. Navigate to Telephony → Configuration. 3. Click on Create new and then select Dispatch rule. 4. In the JSON editor, you can use this configuration to create individual rooms:
Copy code
{
  "dispatch_rule": {
    "rule": {
      "dispatch_rule_individual": {
        "room_prefix": "call-"
      }
    }
  }
}
5. Finally, click Create to save your rule. 2. Programmatically via SDK: If you prefer, you can also set up dispatch rules using the Node.js or Python SDKs. Here's an example in Node.js:
Copy code
const dispatchRule = await sipClient.createSipDispatchRule(
  {
    type: 'individual',
    roomPrefix: 'call-',
  },
  {
    name: 'inbound-dispatch-rule',
    trunkIds: [trunk.sipTrunkId],
  }
);
If you'd like, I’m here to help with any part of this process or provide more details on using a specific SDK. Just let me know! Sources: SIP dispatch rule | LiveKit Docs | sip/sip.go | src/setup-livekit.ts | Community & Support | livekit/livekit_composite | DeepWiki
b
i did that but now i need to add a different agent with a different agent name into the room every time no?
t
I'd be happy to help you set up adding a different agent with a unique name into each room automatically! You can do this by configuring the SIP Dispatch Rule to include agent dispatch settings. Let me walk you through the steps: 1. Update the Dispatch Rule: When you create the dispatch rule, make sure to include a room configuration that specifies the agent to be dispatched. Here’s an example using Node.js:
Copy code
const roomConfig = new RoomConfiguration({
  agents: [
    new RoomAgentDispatch({
      agentName: 'unique-agent-name',
      metadata: JSON.stringify({ type: 'sip-handler' })
    })
  ]
});

const dispatchRule = await sipClient.createSipDispatchRule(
  {
    type: 'individual',
    roomPrefix: 'call-',
  },
  {
    name: 'Individual Agent Dispatch',
    roomConfig: roomConfig
  }
);
2. Start the Agent Worker: Next, ensure your agent is running with the specified name. Here’s how you might do this in Python:
Copy code
from livekit.agents import WorkerOptions, Worker

worker = Worker(
    options=WorkerOptions(
        agent_name="unique-agent-name"
    )
)

@worker.on("agent_dispatch")
async def on_agent_dispatch(ctx):
    # Handle the SIP call in the individual room
    pass

await worker.run()
With this setup, each time a SIP call comes in, a new room will be created, and the specified agent will automatically join to handle the call. If you'd like, I’m here to help you further with the setup or guide you through using a specific SDK. Just let me know! Sources: SIP dispatch rule | LiveKit Docs | livekit/livekit_sip.pb.go | examples/agent-dispatch/index.ts | Agent dispatch | LiveKit Docs | livekit-protocol/src/livekit.rs
b
its outbound call here so can we do that we dispatch an agent to a specified room with a specified agent name?
t
Hi there! To help you dispatch a specific agent to a particular room for an outbound SIP call, you can use the Agent Dispatch API along with the SIP Participant API. Let me walk you through the steps: 1. Dispatch the Agent: First, use the Agent Dispatch API to assign the agent to the room. Here's a quick example in Python:
Copy code
dispatch = await lkapi.agent_dispatch.create_dispatch(
    api.CreateAgentDispatchRequest(
        agent_name="your-agent-name", 
        room="your-room-name", 
        metadata=json.dumps({"phone_number": "+1234567890"})
    )
)
2. Create the SIP Participant: Next, initiate the outbound call by creating a SIP participant in the same room. Here's how you can do it:
Copy code
sip_participant = await lkapi.sip.create_sip_participant(
    api.CreateSIPParticipantRequest(
        room_name="your-room-name",
        sip_trunk_id="your-outbound-trunk-id",
        sip_call_to="+1234567890",
        participant_identity="phone_user",
    )
)
Important Notes: • Make sure the room name is the same in both steps so the agent and SIP participant connect properly. • The agent should be registered with the agent name you specify. • You can also pass metadata, like a phone number or other custom info, to give the agent some helpful context. If you'd like, I’m here to help you implement this in a specific SDK or environment—just let me know! Sources: Agents telephony integration | LiveKit Docs | livekit-api/livekit/api/agent_dispatch_service.py | Agent dispatch | LiveKit Docs | packages/sip--make-a-call/README.md | telephony/survey_caller/make_survey_calls.py
I'm glad you're looking to enhance the quality and latency of your SIP-based AI agent for outbound calls! Here are some key parameters and strategies you might find helpful to fine-tune: 1. End-of-Utterance (EOU) Detection: • min_silence_duration: You can adjust the silence duration needed to recognize when speech has ended. • min_endpointing_delay: This sets the minimum wait time before confirming the end of speech (default: 0.5s). • max_endpointing_delay: And this is the maximum wait time before ending the turn (default: 3.0s). 2. Interruption Behavior: • allow_interruptions: You can choose to enable or disable user interruptions (default: True). • min_interruption_duration: Defines the minimum speech length to count as an interruption (default: 0.5s). • false_interruption_timeout: Sets the timeout for invalid interruptions (default: 2.0s). 3. Turn Detection Modes: • There are several options like
vad
,
stt
,
realtime_llm
, or
manual
to detect when the user has finished speaking. Using
realtime_llm
can really help reduce latency. 4. Preemptive Speech Generation: • Enabling
preemptive_generation
lets the system start LLM and TTS processing as soon as partial transcription arrives, which cuts down response time. 5. Network Optimization: • It’s beneficial to deploy agents close to AI service regions to keep network latency low. • Also, aiming for round-trip times (RTT) under 50ms between the agent and AI endpoints can make a big difference. 6. Monitoring and Metrics: • Tracking metrics like Time To First Token (TTFT) and Time To First Byte (TTFB) can help you spot where delays might be happening in LLM, STT, or TTS components. 7. SIP-Specific Best Practices: • Turning on
TelephonyBackgroundVoiceCancellation
can improve audio clarity significantly. • Keeping an eye on agent metrics continuously will help catch any performance issues during SIP call flows early. If you'd like, I’d be happy to walk you through how to implement any of these optimizations or answer any questions you have. Just let me know! Sources: livekit-agents/livekit/agents/voice/agent_session.py | Agent speech and audio | LiveKit Docs | Troubleshooting & Common Issues | livekit/livekit_composite | DeepWiki | .cursor/rules/agent-core.mdc | External data and RAG | LiveKit Docs