Within the entrypoint function, how do i get acces...
# ask-ai
f
Within the entrypoint function, how do i get access to the participant name? can i access it from ctx(Job Context type)
t
Thanks for reaching out, Mok. I'm an AI assistant and I'm here to help. Give me a moment while I research this topic.
Hey there! Just a quick heads-up: you can’t grab the participant name directly from
ctx
(Job Context) right at the start of the entrypoint function. It only becomes available after you connect to the room and get a
RemoteParticipant
instance. Here’s how you can access the participant name: • First, connect to the room using
ctx.connect()
. • Then, wait for a participant to join with
await ctx.wait_for_participant()
or set up a listener using
ctx.add_participant_entrypoint()
. • Finally, you can grab the name via
RemoteParticipant.name
. If you’d like to have the participant name earlier on, a handy trick is to pass it explicitly through
job.metadata
when dispatching the job, so you can access it right away in the entrypoint function. Sources: Inside a session | LiveKit Docs | Job lifecycle | LiveKit Docs | External data and RAG | LiveKit Docs | examples/primitives/participant_entrypoint.py
f
RemoteParticipant.name
Where do I access this from? is it from job context?? bascially i am fine with getting the name after connecting to the room. Do i need to await ctx.wait_for_participant() if i am doing automatic dispatch of agent based on token with user identity?
t
To get the
RemoteParticipant.name
, you can grab it from the
RemoteParticipant
object right after you connect to the room. Here’s a quick example:
Copy code
await ctx.connect()
participant = await ctx.wait_for_participant()
print(f"Participant name: {participant.name}")
If you’re using automatic dispatch of agents based on tokens with user identity, you don’t absolutely need to use
ctx.wait_for_participant()
, but it’s a good idea. It helps your code wait until at least one human participant has joined the room. Otherwise, the
remote_participants
list might be empty if no one’s joined yet. Another way is to loop through the participants who are already connected like this:
Copy code
for participant in ctx.room.remote_participants.values():
    print(f"Participant name: {participant.name}")
Sources: complex-agents/ivr-agent/agent.py | Rooms, participants, and tracks | LiveKit Docs | Inside a session | LiveKit Docs | Dispatching agents | LiveKit Docs