for explicit dispatch with agent name in sandbox o...
# ask-ai
b
for explicit dispatch with agent name in sandbox options, I get "Agent did not join the room" error.
t
Thanks for reaching out, Suba. I'm an AI assistant and I'm here to help. Give me a moment while I research this topic.
I'd love to help you get this sorted out! Could you share a bit more about your setup? Specifically: • Are you working with a particular SDK or API for this? • What steps have you taken so far to configure explicit dispatch with the agent name in sandbox options? • Have you noticed any other error messages or logs? Knowing these details will really help me understand the situation better and assist you more effectively.
b
using python SDK for agent and using the sandbox in lk. have named agent using worker options.
t
Hi there! The "Agent did not join the room" error usually pops up when using named agents with explicit dispatch, since automatic dispatch is turned off. Don’t worry—we can fix this by explicitly dispatching the agent to a room. Here are two friendly ways to do that: 1. Dispatch via API: You can use the
AgentDispatchService
to create a dispatch request for your agent to join a specific room. Here’s a simple example:
Copy code
import asyncio
from livekit import api

async def create_explicit_dispatch():
    lkapi = api.LiveKitAPI()
    dispatch = await lkapi.agent_dispatch.create_dispatch(
        api.CreateAgentDispatchRequest(
            agent_name="test-agent",  # Make sure this matches agent_name in WorkerOptions
            room="my-room",           # The room you want the agent to join
            metadata="my_metadata"
        )
    )
    print("created dispatch", dispatch)
    await lkapi.aclose()

asyncio.run(create_explicit_dispatch())
1. Dispatch via Participant Token: Another way is to include the agent dispatch in the room configuration when you generate the participant's access token. Here’s how you can do it:
Copy code
token = (
    api.AccessToken()
    .with_identity("my_participant")
    .with_grants(api.VideoGrants(room_join=True, room="my-room"))
    .with_room_config(
        api.RoomConfiguration(
            agents=[
                api.RoomAgentDispatch(
                    agent_name="test-agent", 
                    metadata="my_metadata"
                )
            ],
        ),
    )
    .to_jwt()
)
Just a couple of important things to double-check: • Make sure the
agent_name
in your dispatch request exactly matches what you have set in
WorkerOptions
. • Verify that your LiveKit server URL, API key, and secret are all correctly configured. Also, it’s a good idea to confirm the agent’s registration and worker status by: • Looking at the WebSocket connection logs for messages like "starting worker". • Using the worker’s health check endpoint to see if it’s registered properly. • Ensuring the worker process is running smoothly without any errors. If you’d like, I’m here to help you review your setup or take a look at any logs. Just let me know! Sources: Dispatching agents | LiveKit Docs | examples/agent_dispatch.py | Agent dispatch | LiveKit Docs | SIP troubleshooting guide | LiveKit Docs | livekit-agents/livekit/agents/worker.py
b
how can I do these code changes in the LiveKit given sandbox?
t
Thanks for reaching out! I want to share that the LiveKit sandbox environment is mainly meant for testing and doesn't support direct code modifications. To make the changes you need, the best approach is to set up a local or hosted environment where you can run the Python SDK and update your code comfortably. Here’s a simple way to get started: 1. Set Up a Local Environment: Begin by installing the LiveKit Python SDK and configuring your environment with your API credentials (LIVEKIT_URL, LIVEKIT_API_KEY, LIVEKIT_API_SECRET). 2. Implement the Code: Use the examples we provide to set up explicit dispatch and test how the agent behaves right on your local machine. 3. Test with Sandbox: Once everything is running smoothly locally, you can connect your setup to the LiveKit sandbox by updating your environment variables to point to the sandbox server URL and credentials. If you'd like, I’m here to help you step-by-step with setting up your local environment or linking it to the sandbox. Just let me know!
b
where can I find the sandbox id
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!