How do you set the participants identity?
# ask-ai
h
How do you set the participants identity?
t
Thanks for reaching out, Shawn. I'm an AI assistant and I'm here to help. Give me a moment while I research this topic.
I'm happy to help you with setting a participant's identity in LiveKit! When a participant connects to a room, you get to specify their identity, which is a unique string that helps identify them within that room. Just a heads-up: if two participants join using the same identity, the one who joined most recently will stay connected, and the earlier one will be disconnected. Here’s a simple way to set it up: • When Connecting to a Room: You can use the client SDKs to include the identity as a required parameter during the connection. For instance, in JavaScript, you provide the identity in the
connect()
method. • Server-Side Updates: You can update participant attributes and metadata using the server APIs, but the identity itself can’t be changed once the participant has joined. If you'd like, I’m here to provide more details or examples for any specific SDK you’re working with—just let me know! Sources: livekit-rtc/livekit/rtc/e2ee.py | Rooms, participants, and tracks | LiveKit Docs | Runtime/Scripts/Proto/E2Ee.cs | How to set a fixed participant for agent audio processing | Participant attributes and metadata | LiveKit Docs
h
how can I do that during prewarm or the entrypoint?
t
Hi there! To set a participant's identity during prewarm or entrypoint, you’ll want to define it in the
request_fnc
function using the
identity
parameter inside
req.accept()
. This step happens before the job starts and makes sure the identity is ready as soon as the agent joins the room. Here’s a simple example to guide you:
Copy code
async def request_fnc(req: JobRequest):
    await req.accept(
        name="agent",                # Participant name (display name)
        identity="my-agent-123",     # Participant identity
        attributes={"role": "bot"}   # Custom attributes
    )

opts = WorkerOptions(entrypoint_fnc=entrypoint, request_fnc=request_fnc)
Just a few important notes to keep in mind: • Prewarm Limitation: The
prewarm_fnc
is mainly for preloading models or data, so it can’t be used to set participant identity. • Entrypoint Limitation: Identity needs to be set before the job starts, which means it can’t be assigned inside the
entrypoint
function. • Immutable Identity: Once the identity is set and the participant joins the room, it can’t be changed afterward. If anything is unclear or if you’d like me to walk you through this further, please don’t hesitate to ask—I’m here to help! Sources: Anatomy of an Agent | LiveKit Docs | Anatomy of an Agent | LiveKit Docs | Worker options | LiveKit Docs | Rooms, participants, and tracks | LiveKit Docs
h
how can you set the SIP participants identity
t
Hi there! When you want to set the identity for a SIP participant in LiveKit, a great way to do this is by using the
participant_identity
field while creating the SIP participant through the
CreateSIPParticipant
API. This helps you give a custom identity to the SIP participant in your room, making things clearer and more personalized. Here’s a little example to guide you:
Copy code
response = await livekit_api.sip.create_sip_participant(
    api.CreateSIPParticipantRequest(
        sip_trunk_id="your_trunk_id",
        sip_call_to="+1234567890",
        room_name="my-room",
        participant_identity="custom-sip-identity",  # Set your desired identity here
        participant_name="SIP Caller"
    )
)
A couple of helpful notes to keep in mind: • If you don’t set
participant_identity
, LiveKit will use the phone number as the identity by default—unless
hide_phone_number
is enabled, in which case it will generate a random identity for you. • Make sure the identity is unique within the room because if there’s a duplicate, the older participant will be disconnected. If you have any questions or need more help, please don’t hesitate to ask. I’m here to support you! Sources: livekit-protocol/src/livekit.rs | protobufs/livekit_sip.proto | SIP APIs | LiveKit Docs | SIP Integration | livekit/livekit_composite | DeepWiki | SIP & Telephony Integration | livekit/livekit_composite | DeepWiki
h
How do you set the AI Agents identity
t
To set the identity for an AI Agent in LiveKit, you simply define it within the
request_fnc
function by specifying the
identity
parameter in the
req.accept()
call. This identity links directly to the
Participant.identity
field. Here’s a friendly example to guide you:
Copy code
async def request_fnc(req: JobRequest):
    await req.accept(
        name="agent",  # The agent's name (Participant.name)
        identity="my-agent-identity",  # The agent's identity (Participant.identity)
        attributes={"myagent": "rocks"},  # Optional attributes
    )
A couple of helpful notes: • If you don’t set the identity explicitly, it will default to
agent-<jobid>
. • When working with avatar plugins like Simli, Tavus, or Hedra, you can set the identity using the
avatar_participant_identity
parameter in the
AvatarSession
constructor. If anything feels unclear or if you’d like a hand with this, please don’t hesitate to reach out—I’m here to help! Sources: livekit-plugins/livekit-plugins-hedra/livekit/plugins/hedra/avatar.py | Dispatching agents | LiveKit Docs
h
How do you get all the participants in a room and their identities?
t
Hi there! To help you get all participants in a room along with their identities, here are a couple of friendly ways you can do that: 1. Server-Side: Using the ListParticipants API This approach lets you fetch all participants and their identities from a room quite easily.
Copy code
# Python Example
from livekit import api

async def list_participants(room_name: str):
    lkapi = api.LiveKitAPI()
    participants_response = await lkapi.room.list_participants(
        room=room_name
    )
    return [
        {"identity": p.identity, "name": p.name, "sid": p.sid}
        for p in participants_response.participants
    ]
And don’t worry if you’re using Node.js, Kotlin, or other server SDKs — similar methods are available there too. 2. Client-Side: Using Room Object If you’re working on the client side, you can access participants directly like this: • Swift: Just use the
allParticipants
property on the
Room
object. • JavaScript/React: The
useRemoteParticipants
hook is your friend for grabbing remote participants.
Copy code
// JavaScript Example
import { useRemoteParticipants } from '@livekit/components-react';

const participants = useRemoteParticipants();
participants.forEach(p => console.log(p.identity));
If you’d like me to walk you through more details or provide examples for a specific SDK, just let me know — I’m here to help! Sources: livekit-rtc/livekit/rtc/room.py | packages/livekit-server-sdk/src/RoomServiceClient.ts | src/main/kotlin/io/livekit/server/RoomServiceClient.kt | Tests/LiveKitTests/ParticipantTests.swift | packages/react/src/hooks/useRemoteParticipants.ts
h
How to get them in the entrypoint function
t
I'd love to help you get all participants and their identities in the
entrypoint
function! You can do this by accessing the
room.remote_participants
dictionary from the
JobContext
after you've connected to the room. Each key here represents a participant's identity, and the value is a
RemoteParticipant
object. Here's a little example to guide you:
Copy code
async def entrypoint(ctx: JobContext):
    room = ctx.room

    # Connect to the room
    await ctx.connect(auto_subscribe=AutoSubscribe.AUDIO_ONLY)

    # Iterate through all currently connected remote participants
    for rp in room.remote_participants.values():
        print(rp.identity)  # Print participant identity
This will fetch all participants already in the room when your agent joins. Also, if you want to catch participants who join afterwards, you can set up a listener for the
"participant_connected"
event. Please feel free to reach out if you'd like me to explain anything further or if you need any more help! Sources: Inside a session | LiveKit Docs | Building an Automated IVR Menu Caller | LiveKit Docs | livekit-api/livekit/api/room_service.py
h
How to get the identity of the local participant from the JobContext
t
I'd love to understand a bit more about how you're planning to use the local participant's identity from the
JobContext
. Are you looking to log the identity, use it for routing, or maybe perform a specific action with it? Knowing this will really help me offer the best guidance tailored to your needs.
h
I am trying to start a Participant Egress request
t
Thanks for reaching out! Just to make sure I’m on the right track, are you trying to initiate the Participant Egress request for yourself as the local participant (the agent), or is it for someone else in the room? Also, are you working with a particular SDK or API for this? Knowing this will really help me assist you better.
h
is the AI Agent considered a local or remote participant ?
t
Just to help you understand better, the AI Agent is seen as a local participant from its own point of view. So, when it joins a room, it can find itself using
room.local_participant
. On the other hand, for everyone else in the room, the AI Agent shows up as a remote participant. It's specially marked as a participant of kind
AGENT
, which sets it apart from regular end-users. If you have any questions or need a hand with your Participant Egress request, please don’t hesitate to reach out—I’m here to help! Sources: Inside a session | LiveKit Docs | Inside a session | LiveKit Docs | agents/src/job.ts | packages/react/src/hooks/useVoiceAssistant.ts | Rooms, participants, and tracks | LiveKit Docs
h
How to get the audio track for the ai agent local participant ?
t
Thanks for reaching out! Could you please share a bit more about what you're hoping to do with the audio track—are you looking to process it, play it back, or something else? Also, are you working with a particular SDK or API? Knowing this will really help me guide you in the best way possible.
h
I need to start a egress from the entrypoint function
t
I don't have the answer you're looking for. You could also try asking your question: • in one of the other Slack channels or • to https://deepwiki.com/livekit/livekit_composite which is trained on all LiveKit source code If you find the answer, please post it here to help others!