Hello, I've following Scanerio where I need multi...
# ask-ai
m
Hello, I've following Scanerio where I need multiple agents, and I'm using self hosted livekit setup on k8s, How can i manage traffic between each agent? Right now I can manage one with following: Inbound Rule:
Copy code
{
  "trunk": {
    "name": "Accounts Inbound Trunk",
    "numbers": [
      "10004"
    ],
    "allowed_addresses": [
      "0.0.0.0/0"
    ]
  }
}
Dispatch Rule:
Copy code
{
  "dispatch_rule": {
    "rule": {
      "dispatchRuleIndividual": {
        "roomPrefix": "accounts"
      }
    },
    "name": "Accounts Dispatch Rule",
    "roomConfig": {
      "agents": [
        {
          "agentName": "accounts-agent",
          "metadata": "Accounts Dispatch Rule"
        }
      ]
    }
  },
  "trunk_ids": [
    "ST_an2rsLVYkJiP"
  ]
}
How can I manage SIP Endpoints for multiple departments: Like 1. 10001@public-ip:5060 For accounts 2. 10002@public-ip:5060 For support 3. 10003@public-ip:5060 For claims Each with there own agent.
t
Thanks for reaching out, Muhammad. I'm an AI assistant and I'm here to help. Give me a moment while I research this topic.
Could you help me understand how you'd like to manage traffic between multiple agents? For example, are you hoping to spread traffic evenly, route it based on certain criteria, or maybe something different? Also, are there any particular challenges you're running into with your current setup? I'm here to help!
m
How can I manage SIP Endpoints for multiple departments: Like 1. 10001@<public-ip>:5060 For accounts 2. 10002@<public-ip>:5060 For support 3. 10003@<public-ip>:5060 For claims Each with there own agent. (edited)
t
Managing SIP endpoints for different departments in your self-hosted LiveKit setup can feel a bit tricky, but I’m here to help you through it! You can set up routing logic that sends calls to the right agents or external numbers depending on the department. Here’s a friendly guide on how to get started: 1. Configure SIP Trunk and Dispatch Rules First, set up a SIP trunk with your provider and create dispatch rules to direct calls to specific rooms. For example:
Copy code
{
  "dispatch_rule": {
    "rule": {
      "dispatchRuleIndividual": {
        "roomPrefix": "call-"
      }
    },
    "roomConfig": {
      "agents": [
        {
          "agentName": "phone-assistant",
          "metadata": "inbound call handler"
        }
      ]
    }
  }
}
This way, every incoming call will connect to a specific agent in a new room—pretty neat, right? 2. Implement Department Routing Logic Next, use a centralized phone assistant agent to handle incoming calls and route them based on what the caller chooses (like pressing numbers on their keypad). For example: • Press 1 for Accounts • Press 2 for Support • Press 3 for Claims From there, the agent can transfer the call to the right department’s SIP endpoint using SIP REFER transfers. 3. Example Routing Logic You can define department-specific numbers in your environment variables like this:
Copy code
BILLING_PHONE_NUMBER=+12345678901
TECH_SUPPORT_PHONE_NUMBER=+12345678902
CUSTOMER_SERVICE_PHONE_NUMBER=+12345678903
Then, map the caller’s input (DTMF tones) to these departments and transfer the call accordingly. 4. Recommendations If each department has its own phone number (like 10001@<public-ip>:5060 for Accounts), you can set up dispatch rules that route calls directly to the right agents or rooms based on the number dialed. It keeps things nice and organized! If you want, I’m happy to dive into more details or help with any specific setup questions you have—just let me know! Sources: agent.py | README.md | Agent dispatch | LiveKit Docs | Company directory phone assistant | LiveKit Docs | Inbound calls with Twilio Voice | LiveKit Docs
m
I'm using livekit sip
t
Managing SIP endpoints for different departments with LiveKit SIP is totally doable, and I’m here to help you get it set up smoothly! Here’s a friendly step-by-step guide to route calls to the right agents or external numbers based on the department: 1. Set Up SIP Inbound Trunk First, you'll want to configure an inbound SIP trunk in LiveKit so it can receive incoming calls. You can use the LiveKit SIP API to manage your trunks and make sure your SIP trunk is connected to your phone number provider (like Twilio). 2. Deploy an AI Agent with DTMF Handling Next, set up a LiveKit AI agent to greet your callers and ask them to pick a department. For example: • Press 1 for Accounts • Press 2 for Support • Press 3 for Claims The agent will listen for those DTMF tones and route the call where it needs to go. 3. Map DTMF Inputs to Departments Here’s a simple way to connect those button presses to the right departments:
Copy code
{
  "1": {
    "number": "+12345678901",
    "name": "Accounts"
  },
  "2": {
    "number": "+12345678902",
    "name": "Support"
  },
  "3": {
    "number": "+12345678903",
    "name": "Claims"
  }
}
4. Transfer Calls Using SIP REFER Once the agent catches the DTMF input, use the LiveKit SIP API to transfer the call to the correct department’s SIP endpoint. Something like this:
Copy code
await livekitApi.sip.transfer_sip_participant({
  participant_identity: "caller-id",
  room_name: "current-room",
  transfer_to: "tel:+12345678901"
});
5. Customize and Scale Feel free to add more departments by expanding your DTMF mapping, and tweak the agent’s behavior to fit exactly what you need. If you want to get fancy, you can even integrate AI-powered logic with OpenAI or similar tools for a smarter experience. For more details, check out the LiveKit Phone Assistant Repository and the Company Directory Recipe. If you have any questions or want help with specific setups, just let me know—I’m happy to assist! Sources: Company directory phone assistant | LiveKit Docs | README.md | README.md | SIP APIs | LiveKit Docs | lib/livekit/sip_service_client.rb
m
Can't I define Different SIP entrypoints using livekit sip ? and differnet dispatch rles each?
t
Absolutely! You can set up different SIP entry points and dispatch rules in LiveKit SIP to handle calls for multiple departments. Let me walk you through how to do this: 1. Define Inbound Trunks as Entry Points Think of inbound trunks as doorways for incoming SIP calls. You can create separate trunks for each department, each with its own phone number. For example:
Copy code
{
  "name": "Billing Trunk",
  "numbers": [
    "+1234567890"
  ]
}
Copy code
{
  "name": "Support Trunk",
  "numbers": [
    "+0987654321"
  ]
}
Each trunk acts as a unique entry point for calls headed to a specific department. 2. Configure Dispatch Rules for Call Routing Dispatch rules help decide where calls go once they come in through a trunk. You can set up different rules for each department like this: • Direct Routing: Use
dispatchRuleDirect
to send calls straight to a specific room (like "billing-room"). • Individual Routing: Use
dispatchRuleIndividual
to create a new room for each caller (for example, "support-call-"). Here’s an example dispatch rule for the Billing department:
Copy code
{
  "dispatch_rule": {
    "rule": {
      "dispatchRuleDirect": {
        "roomName": "billing"
      }
    },
    "trunk_ids": [
      "billing_trunk_id"
    ],
    "name": "Billing Department"
  }
}
3. Use a Single Trunk with Department-Specific Rules (Optional) If you prefer to use one main phone number, you can route calls based on the number dialed or a PIN. For example:
Copy code
{
  "dispatch_rule": {
    "rule": {
      "dispatchRuleDirect": {
        "roomName": "billing"
      }
    },
    "trunk_ids": [
      "main_trunk_id"
    ],
    "inbound_numbers": [
      "+1234567890"
    ],
    "name": "Billing Department",
    "pin": "123"
  }
}
This way, you can have clear entry points and routing tailored to each department’s needs. If you want, I’m here to help with any part of the setup—just let me know! Sources: README.md | livekit-protocol/livekit/protocol/sip.py | SIP dispatch rule | LiveKit Docs | sip/sip.go | SIP APIs | LiveKit Docs
m
I need dispatchRuleIndividual rule agianst each department how my sip uri will look like?
t
I don't have the answer you're looking for. You could also try asking your question: • in one of the other Slack channels or • to https://deepwiki.com/livekit/livekit_composite which is trained on all LiveKit source code If you find the answer, please post it here to help others!