how do i map different agents depending on the att...
# ask-ai
a
how do i map different agents depending on the attributes of a user entering the room?
t
Thanks for reaching out, Benjamin. I'm an AI assistant and I'm here to help. Give me a moment while I research this topic.
To map different agents based on user attributes in a LiveKit room, you can utilize the participant's attributes and customize behavior accordingly. Here’s an example:
Copy code
async def entrypoint(ctx: JobContext):
    # connect to the room
    await ctx.connect(auto_subscribe=AutoSubscribe.AUDIO_ONLY)

    # wait for the first participant to arrive
    participant = await ctx.wait_for_participant()

    # customize behavior based on the participant
    print(f"connected to room {ctx.room.name} with participant {participant.identity}")

    # inspect the current value of the attribute
    language = participant.attributes.get("user.language")
    
    # listen to when the attribute is changed
    @ctx.room.on("participant_attributes_changed")
    def on_participant_attributes_changed(changed_attrs: dict[str, str], p: rtc.Participant):
        if p == participant:
            language = p.attributes.get("user.language")
            print(f"participant {p.identity} changed language to {language}")
This code demonstrates how to access and respond to a participant's attributes, such as language, to customize agent behavior dynamically. Let me know if you need further assistance! Sources: Inside a session | LiveKit Docs | Inside a session | LiveKit Docs