few-businessperson-10768
08/28/2025, 9:15 AMtall-airline-16756
08/28/2025, 9:15 AMtall-airline-16756
08/28/2025, 9:16 AMmetadata field. This works great for things like user profiles or setting up the session context.
• AgentSession.userdata: This userdata attribute lets you keep session-specific info that you can update as you go. It’s type-safe and perfect for maintaining state during the session.
• RPC (Remote Procedure Calls): If you want real-time, two-way communication—like submitting forms or triggering actions—RPC is the way to go.
• Data Messages: Using the publishData API, you can send real-time updates or even transfer files. It supports both reliable and lossy data transfer, depending on what you need.
• Participant Attributes: This lets you set and get user-specific settings, like preferences or language options.
Each method fits different situations, so if you want, I’d be happy to walk you through how to set up any of these in detail. Just let me know!
Sources: Workflows | LiveKit Docs | Web and mobile frontends | LiveKit Docs | complex-agents/turn-taking/agent.py | Data messages | LiveKit Docs | agent-console/app/api/room/send-data/route.tsfew-businessperson-10768
08/28/2025, 9:17 AMtall-airline-16756
08/28/2025, 9:18 AMsetAttributes(). For example:
await room.local_participant.set_attributes({"user.language": "en", "user.role": "speaker"})
• Using Server APIs: You can also set attributes through the RoomServiceClient. For example:
const roomServiceClient = new RoomServiceClient('myhost', 'api-key', 'my secret');
roomServiceClient.updateParticipant('room', 'identity', {
attributes: {
'user.language': 'es',
'user.role': 'moderator',
},
});
• Accessing Attributes in an Agent: Inside an agent, you can grab participant attributes via the JobContext and the connected participant object. Here’s how:
async def entrypoint(ctx: JobContext):
await ctx.connect(auto_subscribe=AutoSubscribe.AUDIO_ONLY)
participant = await ctx.wait_for_participant()
language = participant.attributes.get("user.language")
role = participant.attributes.get("user.role")
print(f"Language: {language}, Role: {role}")
If you have any questions or want a hand with the implementation, just let me know—I’m here to help!
Sources: Participant attributes and metadata | LiveKit Docs | Participant attributes and metadata | LiveKit Docs | examples/participant_attributes.py | Job lifecycle | LiveKit Docs | Inside a session | LiveKit Docsfew-businessperson-10768
08/28/2025, 9:19 AMtall-airline-16756
08/28/2025, 9:19 AMsetAttributes method on your localParticipant like this:
room.localParticipant.setAttributes({
myKey: 'myValue',
myOtherKey: 'otherValue',
});
• If you ever want to delete an attribute, just set its value to an empty string:
room.localParticipant.setAttributes({
myKey: '', // This will delete the attribute
});
• Accessing Participant Attributes: You can grab the attributes from any Participant object like this:
const attributes = participant.attributes;
console.log(attributes['myKey']);
• And if you want to keep an eye on attribute changes, just listen for the ParticipantAttributesChanged event:
room.on(RoomEvent.ParticipantAttributesChanged, (changed, participant) => {
console.log('participant attributes changed', changed);
console.log('all attributes', participant.attributes);
});
Feel free to reach out if you want me to walk you through more examples or if you have any questions!
Sources: Participant attributes and metadata | LiveKit Docs | Participant attributes and metadata | LiveKit Docs | packages/core/src/observables/participant.ts