victorious-midnight-79553
10/22/2025, 6:46 PMwith_attributes refers to participant attributes or room attributes?
and how do I later access this attribute in a tool cool?
token = api.AccessToken(os.getenv('LIVEKIT_API_KEY'), os.getenv('LIVEKIT_API_SECRET')) \
.with_identity("identity") \
.with_name("name") \
.with_grants(api.VideoGrants(room_join=True, room=room_name)) \
.with_attributes({"user_name": "name", "group_id": "100"})tall-airline-16756
10/22/2025, 6:46 PMtall-airline-16756
10/22/2025, 6:48 PMwith_attributes method in your code snippet actually refers to participant attributes, not room attributes. These attributes are key-value pairs tied to a participant, which you can use to store any custom metadata you need.
When you want to access these attributes later on, you can simply use the attributes property of the participant object. Here’s a quick example:
# Access attributes of a participant
participant_attributes = participant.attributes
Also, if you want to keep track of any changes to participant attributes, you can listen for the participant_attributes_changed event like this:
@room.on("participant_attributes_changed")
def on_participant_attributes_changed(changed_attributes, participant):
print("Attributes changed:", changed_attributes)
print("Current attributes:", participant.attributes)
If anything feels unclear or if you’d like me to walk you through it step-by-step, just let me know—I’m here to help!
Sources: Core Platform Architecture & Authentication | livekit/livekit_composite | D... | livekit-rtc/livekit/rtc/_proto/data_stream_pb2.pyi | Participant attributes and metadata | LiveKit Docsvictorious-midnight-79553
10/23/2025, 5:03 PMparticipant_attributes = participant.attributes
I didn't quite follow this code snippet - could you give me a sample of how to get the participant attribute within a tool call? do I have to use the run context? is that the most latency optimised method? any other methodtall-airline-16756
10/23/2025, 5:04 PMwith_attributes) or some custom session data stored in the RunContext? Also, would you like this data to be shared and synchronized across all participants in the room, or is it something specific to your current session? I’m here to help you get this sorted out!
Sources: packages/react/src/hooks/useParticipantAttributes.ts | Runtime/Scripts/Participant.cs | Participant attributes and metadata | LiveKit Docs | examples/voice_agents/realtime_joke_teller.py | basics/tool_calling.pyvictorious-midnight-79553
10/23/2025, 5:06 PMtoken = api.AccessToken(os.getenv('LIVEKIT_API_KEY'), os.getenv('LIVEKIT_API_SECRET')) \
.with_identity("identity") \
.with_name("name") \
.with_grants(api.VideoGrants(room_join=True, room=room_name)) \
.with_attributes({"user_name": "name", "group_id": "100"})
so I want to access the group_id I set (using the with_attributes..) within a tool call in pythontall-airline-16756
10/23/2025, 5:07 PMgroup_id attribute set using with_attributes in your token, you can retrieve it from the participant's attributes during a tool call. Let me walk you through how you can do this:
Example:
@function_tool
def get_group_id(context: RunContext):
# Access the current room
room = context.room
# Access local participant attributes
local_attrs = room.local_participant.attributes
print("Local participant attributes:", local_attrs)
# Retrieve the 'group_id' attribute
group_id = local_attrs.get("group_id")
print("Group ID:", group_id)
return group_id
Key Notes:
• Attributes are stored as key-value pairs in the attributes property of the participant object.
• Make sure the participant has the canUpdateOwnMetadata permission in their access token to update or access attributes.
• You can also access attributes of remote participants using room.remote_participants.
If you have any questions or need further clarification, please don’t hesitate to ask—I’m here to help!
Sources: livekit-rtc/livekit/rtc/room.py | Participant attributes and metadata | LiveKit Docs | telephony/sip_lifecycle.py | ivr-nagivator/README.mdocvictorious-midnight-79553
10/23/2025, 5:14 PMAttributeError: 'RunContext' object has no attribute 'room'tall-airline-16756
10/23/2025, 5:17 PMAttributeError: 'RunContext' object has no attribute 'room', which usually means the room object isn't directly accessible from the RunContext. A good way to handle this is by accessing the room through the userdata.ctx property or a similar context setup. Here's a refreshed example that might help:
@function_tool
def get_group_id(context: RunContext[UserData]):
# Access userdata context
userdata = context.userdata
# Check if context and room are available
if not userdata.ctx or not userdata.ctx.room:
return "Error: Room context is not available."
room = userdata.ctx.room
# Access local participant attributes
local_attrs = room.local_participant.attributes
group_id = local_attrs.get("group_id")
return group_id
If your setup doesn’t include userdata.ctx, no worries—just double-check how your tool is configured to access the room or participants. Feel free to reach out if you’d like me to walk you through it or if you have any other questions. I’m here to help!
Sources: context-readmes/USERDATA_GUIDE.md | livekit-agents/livekit/agents/job.py