I want to have multiple web participants in the ro...
# ask-ai
a
I want to have multiple web participants in the room with agent initialy and then and on command from ui to remove agent participant
t
Thanks for reaching out, Sasha. I'm an AI assistant and I'm here to help. Give me a moment while I research this topic.
You can have multiple web participants and an agent initially present in a LiveKit room by generating individual access tokens for each participant and the agent, all referencing the same room name. Each web client uses its token to join the room. To remove the agent from the room based on a command from your UI—while keeping the other participants connected—you should have your agent process call the
ctx.shutdown()
method. This disconnects only the agent, letting the rest of the participants stay in the room. You can trigger this from your UI by sending a signal (such as via API call or WebSocket event) that your agent process listens for and then executes
ctx.shutdown()
. This approach allows for a seamless handoff and controlled agent exit without ending the entire session . If you instead want to end the session for everyone, you can delete the room using the LiveKit server API, which will disconnect all participants, including the agent. But for just removing the agent, triggering
ctx.shutdown()
from your agent process in response to your UI command is the recommended pattern. Sources: Anatomy of an Agent | LiveKit Docs | Dispatching agents | LiveKit Docs | Inside a session | LiveKit Docs | telephony/sip_lifecycle.py | agent-console/app/_components/participant-action-panel.tsx
a
Is there an API I can use from external process to do that
t
Hey there! Great news - LiveKit totally has a way for you to disconnect a specific participant from a room while keeping everyone else connected. It's super easy to do using the
removeParticipant
method in the server SDKs. Think of it like gently asking someone to step out of a group video call. Here's a quick Python example to show you how:
Copy code
from livekit import api

api_client = api.LiveKitAPI(
    os.getenv("LIVEKIT_URL"),
    os.getenv("LIVEKIT_API_KEY"),
    os.getenv("LIVEKIT_API_SECRET"),
)

await api_client.room.remove_participant(
    api.RemoveParticipantRequest(
        room=room_name,
        identity=participant_identity
    )
)
Cool part is, this works for any participant - not just agents! You'll just need roomAdmin permissions. And the same approach works across different server SDKs like Node.js, Kotlin, and Rust. Pro tip: If you want to make sure they can't jump right back in, consider setting short-lived tokens or just not sending a new token after removing them. Want more details? Check out the API documentation for each server SDK . Sources: src/main/kotlin/io/livekit/server/RoomServiceClient.kt | livekit-api/src/services/room.rs | Inside a session | LiveKit Docs | Managing participants | LiveKit Docs | packages/livekit-server-sdk/src/RoomServiceClient.ts | agent-console/app/_components/participant-action-panel.tsx | livekit-api/livekit/api/room_service.py
a
How to get participant identity from agent if i ahve access to room context in my web component
t
Hey there! Let me walk you through how to grab the agent's participant identity from your room context. It's pretty straightforward, I promise! 1. First, dive into the room's participants list. 2. Then, find the participant with
kind == AGENT
- that's your agent buddy. 3. Finally, peek at the
identity
property, which is the unique ID you'll use. If you're working with a framework that shows
participants
, you'll typically do something like this:
participants.find(p => p.kind === 'AGENT')
and then grab the
identity
. Easy peasy! Don't worry - this method works the same way across different LiveKit client setups. The agent's
identity
is your go-to for any API calls where you need to reference or manage the agent . Sources: lib/exts.dart | Core API primitives | LiveKit Docs | Sources/LiveKit/Agent/Room+Agent.swift
a
I am using react ui
t
Hey there! When you're working with React UI, we've got a super handy way to grab the agent participant's identity. The
useVoiceAssistant
hook (from
@livekit/components-react
) is your best friend here—it does all the heavy lifting of finding the agent in the room for you:
Copy code
import { useVoiceAssistant } from "@livekit/components-react";

function MyComponent() {
  const { agent } = useVoiceAssistant();
  const agentIdentity = agent?.identity;

  return (
    <div>
      {agentIdentity ? (
        <p>Agent Identity: {agentIdentity}</p>
      ) : (
        <p>No agent connected</p>
      )}
    </div>
  );
}
Now, if you're feeling a bit more adventurous, you could manually find the agent using
useRemoteParticipants
and filtering by
kind === ParticipantKind.AGENT
. But honestly? The
useVoiceAssistant
hook is your smoothest option for LiveKit React apps. It'll help you snag the agent's
identity
so you can do things like remove participants or whatever else you need to do . Sources: packages/react/src/hooks/useVoiceAssistant.ts | web/providers/GameProvider.tsx | Virtual avatar integrations | LiveKit Docs | src/components/playground/Playground.tsx
a
Can I disconnect agent from the room from react
t
Hey there! So, here's the deal with disconnecting participants in a LiveKit room. Your React web client can't directly kick someone out—even an agent. Only the participant themselves can disconnect on their end. If you want to remove someone from the room, you'll need to use the server-side
removeParticipant
API. Here's a friendly tip: the best way to handle this is to have your React app send a quick request to your backend when you want to disconnect the agent. Your backend can then use the LiveKit server SDK to show that participant the door, so to speak. The agent will get a disconnect event and will have to leave the room. It's the only way to remove someone from the outside of their own session . Pro move? If you want to be extra courteous, you could give the agent a heads-up via data or RPC before removing them. But remember, the actual removal always happens on the server side. Sources: src/room/Room.ts | packages/livekit-rtc/src/proto/participant_pb.ts | livekit-ffi/src/livekit.proto.rs | agent-console/app/api/room/remove-participant/route.ts | Connecting to LiveKit | LiveKit Docs | Inside a session | LiveKit Docs | web/providers/GameProvider.tsx
a
Is there a way to capture transcriptions from two web users after agent is removed
t
I don't have the answer you're looking for. You could also try asking your question: • in one of the other Slack channels or • to https://deepwiki.com/livekit/livekit_composite which is trained on all LiveKit source code If you find the answer, please post it here to help others!