How can I distinguish between multiple non-agent p...
# ask-ai
f
How can I distinguish between multiple non-agent participants in the room?
t
Thanks for reaching out, Taras. I'm an AI assistant and I'm here to help. Give me a moment while I research this topic.
When you want to tell apart different non-agent participants in a LiveKit room, here are some handy identifiers and properties you can use: • Unique Identity (
identity
)
: Every participant has a unique
identity
that you, as the developer, provide. It’s unique within the room. For example:
participant.identity
. • Server-Generated SID (
sid
)
: This is a globally unique session ID assigned to each participant. For example:
participant.sid
. • Optional Display Name (
name
)
: This field is optional and great for showing in the UI or for debugging. For example:
participant.name
. • Custom Attributes: These are key-value pairs you can attach to participants for extra info, like roles or preferences. For example:
participant.attributes["role"]
. • Participant Kind (
kind
)
: This helps you tell agents from non-agents. Non-agent participants usually have the kind
STANDARD
. You can loop through the participants and use these properties to spot the differences. Here’s a quick example:
Copy code
for (const participant of room.remoteParticipants.values()) {
  console.log(`Participant: ${participant.identity}, Name: ${participant.name}, SID: ${participant.sid}`);
  if (participant.attributes['role'] === 'presenter') {
    // Handle presenter differently
  }
}
If you have any questions or need a hand with this, just let me know—I’m here to help! Sources: agent-console/lib/event-types.ts | How to set a fixed participant for agent audio processing | Rooms, participants, and tracks | LiveKit Docs | Inside a session | LiveKit Docs
f
How can I track which ChatMessage comes from which participant to add system instructions to the agent depending on the participant id?
t
To keep track of which
ChatMessage
comes from which participant and add system instructions based on the participant ID, you can rely on the sender information included in the message object. Here’s a friendly rundown of how it works across different SDKs: • JS/TS SDK: The
ReceivedChatMessage
interface has a
from
field of type
Participant
. You can easily get the sender's identity using
message.from.identity
. • Flutter SDK: The
ChatMessage
class comes with a
participant
field that’s filled when the message is created. You can access it through the
DataReceivedEvent
. • Python SDK: The
ChatMessageReceived
protobuf message includes a handy
participant_identity
field to identify who sent the message. • Go/Rust SDKs: The
ChatMessage
event handler gives you both the
chat_message
and
participant_identity
so you can easily link them together. • iOS (Swift): The
ChatMessage
struct has an optional
participant
field, which gets set during the
didReceiveData
callback. • Android (Kotlin): The
ChatMessage
data class includes a
participant
field filled with the sender's
Participant
object. • Node.js SDK: The
ChatMessage
event includes the
participant_identity
, making it simple to find out who sent the message. In all these cases, participant info is either right inside the message payload or comes along with the message in the event handler. If you want me to dive deeper into any specific SDK, just let me know—I’m here to help! Sources: Shared/Views/StreamEventTileView.swift | livekit-compose-components/src/main/java/io/livekit/android/compose/chat/Ch... | packages/livekit-rtc/src/room.ts | packages/core/etc/components-core.api.md | lib/src/context/chat_context.dart
f
I need Python SDK
t
In the Python SDK, you can easily keep track of which
ChatMessage
comes from which participant by using the
ChatMessageReceived
protobuf message. This message has a handy
participant_identity
field that clearly tells you who sent the message. Here’s a simple example to show you how it works:
Copy code
def on_chat_message_received(chat_message):
    sender_identity = chat_message.participant_identity
    print(f"Message from {sender_identity}: {chat_message.content}")
    
    # Add system instructions based on participant ID
    if sender_identity == "specific-participant-id":
        # Add your custom logic here
        pass
If you want, I’m here to help you with any part of implementing this—just let me know!