how to specify the agent name when generating a to...
# ask-ai
s
how to specify the agent name when generating a token for joining a room
t
Thanks for reaching out, Youssef. I'm an AI assistant and I'm here to help. Give me a moment while I research this topic.
To specify the agent name when generating a token for joining a room in LiveKit, you can use the
RoomAgentDispatch
object within the
RoomConfiguration
of the token. Below are examples for Python and Node.js: Python:
Copy code
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:
Copy code
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