square-flag-66304
10/15/2025, 10:05 AMtall-airline-16756
10/15/2025, 10:05 AMtall-airline-16756
10/15/2025, 10:06 AMsquare-flag-66304
10/15/2025, 10:07 AMtall-airline-16756
10/15/2025, 10:08 AMupdate_dispatch_rule() method to replace the entire rule with your new configuration.
Here’s an example to guide you:
from livekit.api import LiveKitAPI
from livekit.protocol.room import RoomConfiguration, AgentDispatch
# Initialize the API client
lk_api = LiveKitAPI(
url="your_livekit_url",
api_key="your_api_key",
api_secret="your_api_secret"
)
# Create a new room configuration with the updated agent name
room_config = RoomConfiguration(
agent_dispatch=AgentDispatch(
agent_names=["new_agent_name"] # Update with the new agent name
)
)
# Update the entire dispatch rule with the new configuration
updated_rule = await lk_api.sip.update_dispatch_rule(
rule_id="your_rule_id",
rule=SIPDispatchRuleInfo(
rule=SIPDispatchRule(
dispatch_rule_individual=SIPDispatchRuleIndividual(room_prefix="call") # Include your rule configuration
),
trunk_ids=["your_trunk_id"],
room_config=room_config,
name="Your Rule Name"
)
)
Just a quick reminder to make sure the agent name you use matches what’s in your worker code, and that the agent is properly set up to handle calls. If you'd like, I’m here to help you retrieve the current dispatch rule configuration or assist further with the room configuration format. Just let me know!
Sources: SIP troubleshooting guide | LiveKit Docssquare-flag-66304
10/15/2025, 12:53 PMtall-airline-16756
10/15/2025, 12:53 PMAgentDispatch isn’t designed to be imported directly from livekit.protocol.room. Instead, the best way is to use the public API that the LiveKit Python SDK offers.
For setting up room configuration with agent dispatch, you can use RoomAgentDispatch from livekit.api like this:
from livekit.api import RoomAgentDispatch
room_config = RoomAgentDispatch(
agent_name="new_agent_name",
metadata="optional_metadata"
)
If you’re handling agent dispatches programmatically, the SDK provides AgentDispatchService, which has handy methods such as create_dispatch, delete_dispatch, and list_dispatch.
Just a heads-up: it’s best to avoid importing directly from livekit.protocol modules since those are internal protocol buffer files and not meant for direct use. If you have any questions or want me to walk you through this, I’m here to help!
Sources: Agent dispatch | LiveKit Docs | livekit-protocol/livekit/protocol/__init__.py | Server-Side SDKs & Authentication | livekit/livekit_composite | DeepWikisquare-flag-66304
10/15/2025, 12:55 PMtall-airline-16756
10/15/2025, 12:57 PMroom_config field of the dispatch rule. Here’s a simple way to approach it:
• First, retrieve the existing dispatch rule configuration using list_dispatch_rule.
• Next, update the room_config with the new agent name you want to set.
• Finally, use update_dispatch_rule to replace the entire rule with your updated configuration.
Here’s an example to guide you through the process:
from livekit.api import LiveKitAPI
from livekit.protocol.sip import SIPDispatchRuleInfo
from livekit.protocol.models import RoomConfiguration, AgentDispatch
async def update_agent_in_dispatch_rule():
lk_api = LiveKitAPI(
url="your-livekit-url",
api_key="your-api-key",
api_secret="your-api-secret",
)
# Retrieve the existing dispatch rule
existing_rules = await lk_api.sip.list_dispatch_rule()
rule_to_update = next(rule for rule in existing_rules.items if rule.sip_dispatch_rule_id == "your-dispatch-rule-id")
# Update the room_config with the new agent name
updated_room_config = RoomConfiguration(
agent_dispatch=AgentDispatch(
agent_names=["your-new-agent-name"] # Update agent name here
)
)
# Create updated rule info
updated_rule = SIPDispatchRuleInfo(
sip_dispatch_rule_id=rule_to_update.sip_dispatch_rule_id,
rule=rule_to_update.rule,
trunk_ids=rule_to_update.trunk_ids,
hide_phone_number=rule_to_update.hide_phone_number,
inbound_numbers=rule_to_update.inbound_numbers,
name=rule_to_update.name,
metadata=rule_to_update.metadata,
attributes=rule_to_update.attributes,
room_preset=rule_to_update.room_preset,
room_config=updated_room_config, # Updated room config
)
# Replace the entire dispatch rule
await lk_api.sip.update_dispatch_rule(
rule_id="your-dispatch-rule-id",
rule=updated_rule,
)
If you have any questions or want me to walk you through any part of this, please don’t hesitate to ask. I’m here to help!
Sources: SIP dispatch rule | LiveKit Docs | livekit-protocol/livekit/protocol/sip.pyi | Agents telephony integration | LiveKit Docs | SIP troubleshooting guide | LiveKit Docssquare-flag-66304
10/15/2025, 12:59 PMtall-airline-16756
10/15/2025, 1:00 PMRoomAgentDispatch class isn’t directly available in the livekit.api module. Instead, you’ll want to use the RoomConfiguration and AgentDispatch classes from the protocol module.
• Updating Dispatch Rule: The update_dispatch_rule method doesn’t accept a room_config parameter on its own. You’ll need to update the entire dispatch rule configuration, including the room_config, as part of the SIPDispatchRuleInfo object.
Here’s an updated version of your code that should work better:
from livekit.api import LiveKitAPI
from livekit.protocol.sip import SIPDispatchRuleInfo
from livekit.protocol.models import RoomConfiguration, AgentDispatch
async def update_agent_in_dispatch_rule():
lk_api = LiveKitAPI(
url="your-livekit-url",
api_key="your-api-key",
api_secret="your-api-secret",
)
# Retrieve the existing dispatch rule
existing_rules = await lk_api.sip.list_dispatch_rule()
rule_to_update = next(rule for rule in existing_rules.items if rule.sip_dispatch_rule_id == "your-dispatch-rule-id")
# Update the room_config with the new agent name
updated_room_config = RoomConfiguration(
agent_dispatch=AgentDispatch(
agent_names=["Yojanamitra"] # Update agent name here
)
)
# Create updated rule info
updated_rule = SIPDispatchRuleInfo(
sip_dispatch_rule_id=rule_to_update.sip_dispatch_rule_id,
rule=rule_to_update.rule,
trunk_ids=rule_to_update.trunk_ids,
hide_phone_number=rule_to_update.hide_phone_number,
inbound_numbers=rule_to_update.inbound_numbers,
name=rule_to_update.name,
metadata=rule_to_update.metadata,
attributes=rule_to_update.attributes,
room_preset=rule_to_update.room_preset,
room_config=updated_room_config, # Updated room config
)
# Replace the entire dispatch rule
await lk_api.sip.update_dispatch_rule(
rule_id="your-dispatch-rule-id",
rule=updated_rule,
)
Also, just to make sure everything runs smoothly, please double-check that you have the correct versions of the livekit-api and livekit-protocol packages installed. You can easily verify this by running:
pip show livekit-api livekit-protocol
If you have any questions or need a hand with anything else, feel free to reach out. I’m here to help!
Sources: livekit-protocol/livekit/protocol/__init__.py | Server-Side SDKs & Authentication | livekit/livekit_composite | DeepWikisquare-flag-66304
10/16/2025, 4:23 AMtall-airline-16756
10/16/2025, 4:24 AMImportError for RoomConfiguration is happening because the livekit.protocol.models module belongs to the livekit-protocol package, which might not be installed on your system or could be a bit outdated. No worries—let’s walk through some simple steps to get this sorted out:
• First, check if the package is installed: You can run this command to see if livekit-protocol is already there:
pip list | grep livekit
• If you don’t see livekit-protocol listed, go ahead and install it with this command:
pip install livekit-protocol
• If it’s installed but might be outdated, updating it can help: Try this to get the latest version:
pip install --upgrade --force-reinstall livekit-protocol
• Make sure your import statement is correct: It should look like this:
from livekit.protocol.models import RoomConfiguration
• Double-check your Python environment: Sometimes the package is installed in one environment but not the one you’re currently using. Ensuring you’re in the right environment can save some headaches.
Give these steps a try, and then run your code again. If you’re still running into trouble or have any questions along the way, just let me know—I’m here to help!
Sources: Core Platform Architecture & Authentication | livekit/livekit_composite | D... | livekit-rtc/livekit/rtc/_proto/__init__.py | Server-Side SDKs & Authentication | livekit/livekit_composite | DeepWikisquare-flag-66304
10/16/2025, 4:26 AMtall-airline-16756
10/16/2025, 4:27 AM