victorious-potato-16814
07/31/2025, 6:32 PMtall-airline-16756
07/31/2025, 6:32 PMtall-airline-16756
07/31/2025, 6:33 PMvictorious-potato-16814
07/31/2025, 6:34 PMtall-airline-16756
07/31/2025, 6:35 PMvictorious-potato-16814
07/31/2025, 6:40 PMtall-airline-16756
07/31/2025, 6:41 PMuse tokio::try_join;
#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
let url = env::var("LIVEKIT_URL").expect("LIVEKIT_URL is not set");
let api_key = env::var("LIVEKIT_API_KEY").expect("LIVEKIT_API_KEY is not set");
let api_secret = env::var("LIVEKIT_API_SECRET").expect("LIVEKIT_API_SECRET is not set");
let room_name = "test-room";
let agent1 = connect_participant("agent1", &room_name, &url, &api_key, &api_secret);
let agent2 = connect_participant("agent2", &room_name, &url, &api_key, &api_secret);
let agent3 = connect_participant("agent3", &room_name, &url, &api_key, &api_secret);
try_join!(agent1, agent2, agent3).await?;
Ok(())
}
async fn connect_participant(
identity: &str,
room_name: &str,
url: &str,
api_key: &str,
api_secret: &str,
) -> Result<(), Box<dyn std::error::Error>> {
Ok(())
}
TypeScript Example
import { AccessToken, RoomAgentDispatch, RoomConfiguration } from '@livekit/protocol';
import { AgentDispatchClient } from 'livekit-server-sdk';
async function createTokenWithMultipleAgents() {
const at = new AccessToken();
at.identity = 'my-participant';
at.addGrant({ roomJoin: true, room: 'my-room' });
at.roomConfig = new RoomConfiguration({
agents: [
new RoomAgentDispatch({
agentName: 'agent1',
metadata: '{"role": "moderator"}',
}),
new RoomAgentDispatch({
agentName: 'agent2',
metadata: '{"role": "helper"}',
}),
],
});
return await at.toJwt();
}
async function dispatchAgents() {
const dispatchClient = new AgentDispatchClient(process.env.LIVEKIT_URL);
await dispatchClient.createDispatch('my-room', 'agent1');
await dispatchClient.createDispatch('my-room', 'agent2');
}
createTokenWithMultipleAgents().then(token => {
console.log('Token created:', token);
dispatchAgents();
});
If you have any questions or want me to walk you through any part of this, just let me know—I’m happy to help!