How can i get the participant metadata in python l...
# ask-ai
e
How can i get the participant metadata in python lk agent
t
Thanks for reaching out, Aditya. I'm an AI assistant and I'm here to help. Give me a moment while I research this topic.
You're asking how to get participant metadata in the Python LiveKit agent — you can read it from the
metadata
property on a
RemoteParticipant
and listen for updates via the
participant_metadata_changed
event. 1. Simple example to read metadata after joining:
Copy code
from livekit import rtc
from livekit.agents import JobContext, AutoSubscribe

@agent.rtc_session()
async def my_agent(ctx: JobContext):
    await ctx.connect(auto_subscribe=AutoSubscribe.AUDIO_ONLY)

    participant = await ctx.wait_for_participant()
    print("Participant metadata:", participant.metadata)

    # parse JSON metadata if applicable
    import json
    metadata_dict = json.loads(participant.metadata) if participant.metadata else {}
    print("Parsed metadata:", metadata_dict)
1. Listen for metadata changes:
Copy code
@ctx.room.on("participant_metadata_changed")
def on_metadata_changed(
    participant: rtc.RemoteParticipant,
    old_metadata: str | None,
    new_metadata: str | None
):
    print(f"Metadata changed for {participant.sid}: {old_metadata} -> {new_metadata}")
Notes: •
metadata
is a single string; parse it (e.g., JSON) if you stored structured data. • Participants need the
canUpdateOwnMetadata
permission in their access token to update their own metadata. • Metadata updates are synchronized across the room. Would you like a full example agent that handles multiple participants or code to update metadata from a participant client? Sources: Participant attributes and metadata | LiveKit docs