victorious-midnight-79553
10/05/2025, 6:25 PMon_enter method? or how do I add, say, the users name to the chat context?tall-airline-16756
10/05/2025, 6:25 PMtall-airline-16756
10/05/2025, 6:26 PMon_enter method or chat context. You can achieve this smoothly using the setAttributes and setName methods provided by the LiveKit SDK. These attributes and the participant's name will be synchronized across everyone in the room, which is really handy!
Here’s a simple way to set Attributes and Name:
1. Use setAttributes to add key-value pairs for your participant, like this:
await localParticipant.setAttributes({'name': 'John Doe', 'role': 'user'});
1. To update the display name, simply use `setName`:
await localParticipant.setName('John Doe');
Just a quick reminder: make sure your participant’s access token has the canUpdateOwnMetadata permission so these updates can go through without a hitch.
To access Attributes and Name:
• They’re synchronized and you can get them from any Participant object like this:
print('Participant name: ${participant.name}');
print('Participant attributes: ${participant.attributes}');
Keeping things up-to-date in real-time:
• You can listen for changes using events like onParticipantAttributesChanged and onParticipantNameChanged, so your chat context updates dynamically and feels seamless.
If you’d like a hand integrating this into your chat UI or AI agent, please don’t hesitate to reach out—I’m here to help!
Sources: livekit-ffi/src/livekit.proto.rs | External data and RAG | LiveKit Docs | lib/src/participant/local.dart | Participant attributes and metadata | LiveKit Docsvictorious-midnight-79553
10/05/2025, 6:31 PMcanUpdateOwnMetadata during auth token generation?tall-airline-16756
10/05/2025, 6:32 PMcanUpdateOwnMetadata during auth token generation, simply include it in the VideoGrant of the access token. This permission lets participants update their own metadata, name, and attributes, which can be really helpful!
Programmatic Example (Go):
grant := &auth.VideoGrant{
RoomJoin: true,
Room: "my-room",
CanUpdateOwnMetadata: true, // Enable permission
}
at := auth.NewAccessToken(apiKey, apiSecret).
SetIdentity("user-123").
SetVideoGrant(grant)
token, err := at.ToJWT()
Using LiveKit CLI:
lk token grant --identity=user123 --room=my-room --allow-update-metadata
Just a quick note: by default, canUpdateOwnMetadata is false if you don’t set it explicitly. So, make sure to include this permission if your app needs participants to update their metadata. If you have any questions or want me to walk you through it, I’m here to help!
Sources: Authentication | LiveKit Docs | livekit/livekit_room.pb.go | CLI Tools & Token Management | livekit/livekit_composite | DeepWiki | lib/src/participant/local.dart | Sources/LiveKit/Participant/LocalParticipant.swiftvictorious-midnight-79553
10/05/2025, 6:35 PMtall-airline-16756
10/05/2025, 6:35 PMon_enter, you can easily use the setName() and setAttributes() methods on your LocalParticipant object. These details get sent to the LiveKit server and become part of the participant's state, so other participants or server-side logic can access them too.
Here’s how you can do it:
1. Set the participant's name like this:
await localParticipant.setName('John Doe');
1. Then, set participant attributes like this:
await localParticipant.setAttributes({'role': 'user', 'department': 'sales'});
Just a quick heads-up: make sure the participant's token has the canUpdateOwnMetadata permission so these updates are allowed.
Another option: You might also want to include the name and attributes directly in the participant's access token when you generate it. This way, they’ll be ready and waiting as soon as the participant joins the room.
If you’d like me to walk you through any part of this or if you have any questions, please don’t hesitate to ask—I’m here to help!
Sources: lib/src/participant/local.dart | livekit-rtc/livekit/rtc/participant.py | Participant attributes and metadata | LiveKit Docs | lib/livekit/access_token.rbvictorious-midnight-79553
10/05/2025, 6:38 PMon_enter - ?tall-airline-16756
10/05/2025, 6:38 PMon_enter, here’s a simple guide you can follow:
1. Set Attributes During Token Generation:
You’ll want to include the attributes right in the access token payload. Here’s an example using Node.js:
const at = new AccessToken();
at.identity = 'my-participant';
at.addGrant({ roomJoin: true, room: 'my-room' });
at.attributes = {
name: 'John Doe',
role: 'user'
};
Just a quick reminder to make sure your token includes the canUpdateOwnMetadata permission, so updates are allowed.
2. Access Attributes in `on_enter`:
Since LiveKit doesn’t have a direct on_enter event, you can use events like participant_attributes_changed or participant_connected to access those attributes when a participant joins:
@room.on("participant_attributes_changed")
def on_participant_attributes_changed(changed_attributes, participant):
print("Participant attributes:", participant.attributes)
print("Changed:", changed_attributes)
Or, you can simply access participant.attributes right after the connection is established.
If you’d like, I’m here to help with more examples or clarify anything, especially for a specific SDK you’re working with. Just let me know!
Sources: Authentication | LiveKit Docs | examples/agent-dispatch/index.ts | lib/livekit/access_token.rb | examples/agent_dispatch.py | Participant attributes and metadata | LiveKit Docsvictorious-midnight-79553
10/05/2025, 6:48 PMtall-airline-16756
10/05/2025, 6:48 PMidentity is always available and name might be optional, it’s great to use name for a more natural greeting, but fall back to identity if name isn’t set. Here’s how you can do it:
greeting_name = participant.name if participant.name else participant.identity
await agent.say(f"Hello {greeting_name}, welcome to the room!", allow_interruptions=True)
2. Greet All Participants:
To make sure every participant feels welcomed as they join, you can use add_participant_entrypoint(). Here’s a simple example:
async def participant_greeter(ctx: JobContext, participant: rtc.Participant):
greeting_name = participant.name or participant.identity
await agent.say(f"Welcome, {greeting_name}!", allow_interruptions=True)
async def entrypoint(ctx: JobContext):
await ctx.connect()
ctx.add_participant_entrypoint(participant_greeter)
3. Personalize Using Metadata:
If you want to make greetings even more personal, you can pass user-specific details like full names or preferences through job metadata when initializing the agent:
user_info = ctx.job.metadata.get("user", {})
preferred_name = user_info.get("preferred_name", "")
await agent.say(f"Hi {preferred_name}, good to see you!", allow_interruptions=True)
4. Ensure Client-Side Name Setting:
It’s also helpful to encourage users to set their display name when they join the room, so greetings feel more personal and friendly:
await room.connect(token, { name: "Alice Johnson" });
Following these steps will help create a smooth and welcoming experience for everyone joining your room. If you have any questions or want to dive deeper into any part, just let me know—I’m here to help!
Sources: External data and RAG | LiveKit Docs | Rooms, participants, and tracks | LiveKit Docs | agent-examples/agent_examples/pipeline_agent.py | Job lifecycle | LiveKit Docsvictorious-midnight-79553
10/05/2025, 6:54 PMawait _room!.connect(
url,
token,
{name: "Alice Johnson" },
connectOptions: ConnectOptions(autoSubscribe: true)
);tall-airline-16756
10/05/2025, 6:55 PMname parameter directly in the connect method. Could you please let me know if your goal is to set the participant's name or some metadata during the connection? Or maybe you're looking for a different approach to make this happen? I'm here to help you figure this out!victorious-midnight-79553
10/05/2025, 6:56 PMon_enter method? give me a code sample in pythontall-airline-16756
10/05/2025, 6:57 PMon_enter method of your LiveKit agent. Let me share a friendly Python example to guide you:
from livekit_agent import Agent
class MyAgent(Agent):
async def on_enter(self):
# Here, we grab the participant's name set during token generation
participant_name = self.job_context.participant.name
print(f"Participant entered with name: {participant_name}")
# You can also check out other participant details
participant_identity = self.job_context.participant.identity
print(f"Participant identity: {participant_identity}")
# And here’s a little greeting for the participant
await self.say(f"Hello {participant_name}, welcome to the room!", allow_interruptions=True)
Just to explain a bit:
• The on_enter method runs when the agent joins the room.
• You can access the participant's name via self.job_context.participant.name, which matches the name set in the token.
• Feel free to explore other metadata too, like identity or any custom attributes you’ve added.
If you’d like me to walk you through this further or provide more examples, just let me know—I’m here to help!
Sources: Job lifecycle | LiveKit Docs | complex-agents/ivr-agent/README.md | livekit-rtc/livekit/rtc/room.py | Rooms, participants, and tracks | LiveKit Docsvictorious-midnight-79553
10/05/2025, 7:16 PMparticipant_name = self.job_context.participant.name
^^^^^^^^^^^^^^^^
AttributeError: 'Assistant' object has no attribute 'job_context'tall-airline-16756
10/05/2025, 7:17 PMself.job_context isn’t directly accessible in the on_enter method. To smoothly get the participant's name, it’s best to set up the participant data before starting the agent session. Here’s a friendly, corrected version of your implementation:
from dataclasses import dataclass
from livekit.agents import JobContext, AgentSession
from livekit import rtc
@dataclass
class UserData:
ctx: JobContext
participant_name: str
participant_identity: str
async def entrypoint(ctx: JobContext):
# Connect to the room
await ctx.connect()
# Wait for the first participant to join
participant: rtc.RemoteParticipant = await ctx.wait_for_participant()
# Safely get name, fall back to identity
name = participant.name or participant.identity
# Initialize UserData with known, safe values
user_data = UserData(
ctx=ctx,
participant_name=name,
participant_identity=participant.identity
)
# Start the agent session with pre-initialized data
session = AgentSession(userdata=user_data)
await session.start(room=ctx.room, agent=MyAgent())
class MyAgent(Agent):
async def on_enter(self):
# Access name safely via session.userdata
user_data = self.session.userdata
name = user_data.participant_name
await self.session.say(f"Hello, {name}! Welcome to the call.")
Here’s a quick explanation to help you along:
• We use ctx.wait_for_participant() to make sure a participant has joined before moving forward.
• The participant’s name is stored in a UserData object so we avoid any tricky dynamic access inside on_enter.
• Inside on_enter, we safely grab the name through self.session.userdata.
This way, you won’t run into that AttributeError, and everything should flow nicely. If anything’s still unclear or you want to dive deeper, just let me know—I’m here to help!
Sources: livekit-agents/livekit/agents/job.py | Job lifecycle | LiveKit Docs | Rooms, participants, and tracks | LiveKit Docs | complex-agents/ivr-agent/README.md