faint-arm-51818
11/10/2025, 8:03 PMtall-airline-16756
11/10/2025, 8:03 PMtall-airline-16756
11/10/2025, 8:04 PMapi.AccessToken, you’ll want to include an agent dispatch configuration in the access token through the roomConfig field. Let me walk you through the steps:
1. Define the Agent Name: First, make sure your agent worker is set up to listen for dispatch requests using a specific agentName. This is something you configure when initializing the agent worker.
2. Create an AccessToken with Room Configuration: Next, use the LiveKit server SDK to create an AccessToken and add a RoomConfiguration that includes a RoomAgentDispatch specifying the agent to dispatch. Here’s a handy example in Node.js: import { AccessToken } from 'livekit-server-sdk';
import { RoomAgentDispatch, RoomConfiguration } from '@livekit/protocol';
const roomName = 'my-room';
const agentName = 'test-agent';
async function createTokenWithAgentDispatch() {
const at = new AccessToken(API_KEY, API_SECRET, {
identity: 'my-participant',
ttl: '15m',
});
at.addGrant({
roomJoin: true,
room: roomName,
});
at.roomConfig = new RoomConfiguration({
agents: [
new RoomAgentDispatch({
agentName: agentName,
metadata: '{"mydata": "myvalue"}', // Optional metadata
}),
],
});
return await at.toJwt();
}
3. Ensure Agent Is Running: Lastly, please double-check that your agent is deployed and running with the matching agentName in its WorkerOptions. If the agent isn’t active, the dispatch won’t work as expected.
If you’d like, I’m more than happy to share details and examples for other SDKs like Python or Rust—just let me know!
Sources: Authentication | LiveKit Docs | Agent dispatch | LiveKit Docs | examples/agent_dispatch/README.md | examples/agent-dispatch/index.ts | examples/agent_dispatch.pyfaint-arm-51818
11/10/2025, 8:07 PMtall-airline-16756
11/10/2025, 8:08 PMapi.AccessToken in Python. Here's a simple example for you:
from livekit_server_sdk import AccessToken, VideoGrant, RoomConfiguration, RoomAgentDispatch
API_KEY = "your_api_key"
API_SECRET = "your_api_secret"
room_name = "my-room"
agent_name = "test-agent"
# Create an access token with agent dispatch
access_token = AccessToken(API_KEY, API_SECRET)
access_token.identity = "my-participant"
# Add room join grant
video_grant = VideoGrant(room_join=True, room=room_name)
access_token.add_grant(video_grant)
# Configure agent dispatch in room configuration
room_config = RoomConfiguration(
agents=[
RoomAgentDispatch(
agent_name=agent_name,
metadata="{\"mydata\": \"myvalue\"}" # Optional metadata
)
]
)
access_token.room_config = room_config
# Generate the token
jwt_token = access_token.to_jwt()
print("Generated JWT Token:", jwt_token)
Just replace your_api_key and your_api_secret with your LiveKit API credentials. This will create a JWT token that includes the agent dispatch setup. If you have any questions or need a hand with anything else, please feel free to ask—I’m here to help!faint-arm-51818
11/10/2025, 8:11 PMtall-airline-16756
11/10/2025, 8:12 PMjwt_token, you’re all set to connect your custom agent to the room. Here’s a simple way to do it:
1. Start Your Agent: Make sure your custom agent is up and running, and it’s set to listen for dispatch requests with the same agentName you included in the token.
2. Use the Token to Join the Room: The jwt_token lets the participant join the room. When they do, LiveKit will automatically dispatch the agent specified in the token to that room.
3. Optional: Explicit Dispatch: If you’d like to dispatch the agent without waiting for a participant to join, you can use the LiveKit API or AgentDispatchClient directly. Here’s an example in Python: from livekit_server_sdk import AgentDispatchClient
LIVEKIT_URL = "your_livekit_url"
client = AgentDispatchClient(LIVEKIT_URL, API_KEY, API_SECRET)
response = client.create_dispatch(
room_name="my-room",
agent_name="test-agent",
metadata="{\"mydata\": \"myvalue\"}"
)
print("Dispatch Response:", response)
If any part of this feels unclear or you’d like a hand with these steps, please don’t hesitate to reach out—I’m here to help!faint-arm-51818
11/10/2025, 8:13 PMtall-airline-16756
11/10/2025, 8:14 PM