billions-zoo-2710
03/22/2026, 7:09 AMasync def create_token_with_agent_dispatch() -> str:
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()
)
return tokentall-airline-16756
03/22/2026, 7:10 AMtall-airline-16756
03/22/2026, 7:10 AMJobContext):
1) Wait for participants to join (async iterator)
@server.rtc_session(agent_name="my-agent")
async def my_agent(ctx: JobContext):
async for participant in ctx.room.remote_participants:
# participant.identity will be "my_participant"
print(f"Remote participant identity: {participant.identity}")
break
2) Read the current remote participants mapping (if someone already joined)
@server.rtc_session(agent_name="my-agent")
async def my_agent(ctx: JobContext):
# get first remote participant
remote = next(iter(ctx.room.remote_participants.values()))
print(f"Remote participant identity: {remote.identity}") # "my_participant"
Notes:
• The identity on the token is the remote user’s identity (not the agent’s identity). Use participant.identity on a RemoteParticipant to read it.
• Use the async iterator if you need to wait for a participant to join; use the .values() mapping if participants are already present.
If you want, tell me whether your agent needs to:
• Read the identity for the first participant only, or for every participant, and
• React immediately when someone joins or just check current room members.
I can then provide a tailored snippet showing event handling, logging, or access-control usage.
Sources: Server options | LiveKit Documentation | Job lifecycle | LiveKit Documentation, with interactive elements