<@U07FRRZH2GN> how to remove agent from room
# ask-ai
m
@icy-policeman-64898 how to remove agent from room
t
Thanks for reaching out, Rajadurai. I'm an AI assistant and I'm here to help. Give me a moment while I research this topic.
To remove an agent (or any participant) from a LiveKit room, use the
removeParticipant
method available in the LiveKit server SDKs (Node.js, Python, Go, Kotlin, Rust). This action requires roomAdmin permissions and will forcibly disconnect the target participant from the room. Here is a summary of the main approaches: • Node.js:
await roomService.removeParticipant(roomName, identity);
Python:
await room_service.remove_participant(RoomParticipantIdentity(room="room_name", identity="participant_identity"))
Key steps: 1. Identify the room name and the participant's identity (the agent you want to remove). 2. Call the relevant
removeParticipant
method from your backend using the server SDK with the necessary credentials. Note: Removing an agent will disconnect them, but their token is not invalidated—they could re-join if they still possess a valid token. To prevent rejoining, limit the token’s TTL or avoid issuing a new one to that participant. If you need code samples or instructions for another SDK or want to know how to handle agent roles specifically, let me know your stack and I can provide tailored details. References: Node.js, Python, Go, Kotlin, Rust SDK docs and LiveKit API documentation. Sources: livekit-api/livekit/api/room_service.py | Managing participants | LiveKit Docs | src/main/kotlin/io/livekit/server/RoomServiceClient.kt | livekit/livekit_room.twirp.go | packages/livekit-server-sdk/src/RoomServiceClient.ts | livekit-api/src/services/room.rs | agent-console/hooks/use-livekit/use-livekit-action.tsx | pkg/rtc/room.go | agent/game_host.py
m
@icy-policeman-64898 how to get the agent's participant id
t
Hey there! Let me walk you through how you can grab an agent's participant ID—we've got a few handy ways to do this depending on what you're working on. • Inside an agent session: No sweat! Just loop through
ctx.room.remote_participants.values()
and you'll easily access each participant's
identity
while you're connected to the room. • Server-side: If you're on the backend, the server API's
list_participants
method is your friend. It'll fetch all participants in a room, complete with
identity
and
sid
details. Here's a quick Python example to show you how:`participants_response = await lkapi.room.list_participants(room_proto.ListParticipantsRequest(room=room_name)) for participant in participants_response.participants: print(f"Identity: {participant.identity}") print(f"SID: {participant.sid}")` Pro tip: Just remember that
participant.identity
is the unique ID you set up (perfect for your app logic), while
sid
is the system-generated identifier. For most scenarios, you'll want to use
identity
when you're looking to target or remove an agent from a room. Sources: Managing participants | LiveKit Docs | mcp/server.py | Core API primitives | LiveKit Docs | Inside a session | LiveKit Docs | How to set a fixed participant for agent audio processing
m
@icy-policeman-64898 AttributeError: module 'livekit.api.room_service' has no attribute 'remove_participant'
t
Hey there! I totally understand the frustration with the
remove_participant
method. Let me help you sort this out. The method is actually part of the
RoomService
class in the Python SDK, and you'll want to access it through
lkapi.room.remove_participant(...)
. Usually, this error pops up when there's a small mix-up with imports, how you're using the
LiveKitAPI
object, or if your SDK is a bit outdated. • Here's the right way to do it:
Copy code
from livekit import api
lkapi = api.LiveKitAPI(url, api_key, api_secret)
await lkapi.room.remove_participant(
    api.RoomParticipantIdentity(room="room-name", identity="participant-identity")
)
Just make sure you're calling
remove_participant
on
lkapi.room
(not straight from the module), and if things are still wonky, try upgrading your LiveKit Python SDK. You've got this! 😊 Sources: livekit-api/livekit/api/room_service.py | agent/game_host.py
m
@icy-policeman-64898 how to list all particpants in a room
t
Hey there! Wondering how to get a list of all participants in a LiveKit room? No worries, I've got a super straightforward way to do that using the Python SDK. Basically, you'll use the
list_participants
method from the server API, which makes it super easy to see who's in the room.
Copy code
from livekit import api
from livekit.protocol import room as room_proto

lkapi = api.LiveKitAPI(url, api_key, api_secret)
request = room_proto.ListParticipantsRequest(room="room-name")
response = await lkapi.room.list_participants(request)
for participant in response.participants:
    print(f"Identity: {participant.identity}")
    print(f"SID: {participant.sid}")
    print(f"State: {participant.state}")
    print(f"Metadata: {participant.metadata}")
Quick tip: Just make sure you've got
room_admin
permissions in your access token, and you'll be all set! Sources: README.md | telephony/sip_lifecycle.py