In case I have different agents in scope of 1 proj...
# ask-ai
b
In case I have different agents in scope of 1 project, how can I specify what agent to create?
t
Thanks for reaching out, Dmytro. I'm an AI assistant and I'm here to help. Give me a moment while I research this topic.
I'm happy to help you specify which agent to create or dispatch when you have multiple agents in scope for a project. Here are some friendly ways you can do this: • CLI Management: You can use the
--id
flag to specify the agent ID during creation or deployment. For example:
lk agent create --id AG_xxxxxxxxxxxxx
. This way, you’re telling the system exactly which agent you want to work with. • Configuration File: Another approach is to use a
livekit.toml
file where you define the agent configuration, including its ID. It’s a neat way to keep things organized. • Application-Level Dispatch: Within your application code, you can specify the agent by using the
room_config
parameter. For example, include
agents: [{ agent_name: 'desired_agent_name' }]
in your configuration. This helps you control agent assignment right where your app logic lives. • Token-Based Dispatch: You can configure a participant's token to include specific agents in the
RoomConfiguration
. This gives you flexibility at the participant level. • API Dispatch: If you prefer programmatic control, the Agent Dispatch API allows you to explicitly assign agents to rooms. It’s perfect for dynamic scenarios. If you’d like, I’m here to provide more details or examples for any of these methods—just let me know! Sources: Agent dispatch | LiveKit Docs | examples/agent_dispatch.py | packages/livekit-server-sdk/src/AgentDispatchClient.ts | Agent deployment CLI reference | LiveKit Docs | CLI Tools & Token Management | livekit/livekit_composite | DeepWiki
b
How can I dispatch new room using specific worker from the codebase?
t
I'd be happy to help you dispatch a new room using a specific worker programmatically! You can use the Agent Dispatch API for this. Here’s a simple example in Node.js to get you started:
Copy code
const agentDispatchClient = new AgentDispatchClient(process.env.LIVEKIT_URL);

const dispatch = await agentDispatchClient.createDispatch(
  'my-room',
  'test-agent',
  {
    metadata: '{"mydata": "myvalue"}',
  }
);
console.log('created dispatch', dispatch);
Another friendly tip: you can also dispatch an agent automatically when a participant joins a room by including the agent in the participant's access token configuration. Here’s how you might do that in Python:
Copy code
token = (
    api.AccessToken()
    .with_identity("my_participant")
    .with_grants(api.VideoGrants(room_join=True, room=room_name))
    .with_room_config(
        api.RoomConfiguration(
            agents=[api.RoomAgentDispatch(agent_name="test-agent", metadata="my_metadata")],
        ),
    )
    .to_jwt()
)
If you'd like, I’m here to provide more details or examples in any other programming language you prefer. Just let me know! Sources: examples/agent_dispatch/README.md | Agent dispatch | LiveKit Docs | Job lifecycle | LiveKit Docs | packages/livekit-server-sdk/src/AgentDispatchClient.ts | examples/agent_dispatch.py