salmon-lighter-12882
07/06/2025, 2:29 PMtall-airline-16756
07/06/2025, 2:29 PMtall-airline-16756
07/06/2025, 2:29 PMRoomAgentDispatch
object within the RoomConfiguration
of the token. Below are examples for Python and Node.js:
Python:
from livekit.api import (
AccessToken,
RoomAgentDispatch,
RoomConfiguration,
VideoGrants,
)
room_name = "my-room"
agent_name = "test-agent"
def create_token_with_agent_dispatch() -> str:
token = (
AccessToken()
.with_identity("my_participant")
.with_grants(VideoGrants(room_join=True, room=room_name))
.with_room_config(
RoomConfiguration(
agents=[
RoomAgentDispatch(agent_name="test-agent", metadata="my_metadata")
],
),
)
.to_jwt()
)
return token
Node.js:
at.roomConfig = new RoomConfiguration (
agents: [
new RoomAgentDispatch({
agentName: "test-agent",
metadata: "test-metadata"
})
]
);
You can also include metadata with the agent dispatch, which will be passed to the agent as part of the job context.
Sources: Agent dispatch | LiveKit Docs | Authentication | LiveKit Docs