astonishing-ability-75576
07/13/2025, 5:17 PMtall-airline-16756
07/13/2025, 5:17 PMtall-airline-16756
07/13/2025, 5:18 PMctx.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.tsxastonishing-ability-75576
07/13/2025, 5:20 PMtall-airline-16756
07/13/2025, 5:21 PMremoveParticipant
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:
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.pyastonishing-ability-75576
07/13/2025, 5:33 PMtall-airline-16756
07/13/2025, 5:34 PMkind == 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.swiftastonishing-ability-75576
07/13/2025, 5:40 PMtall-airline-16756
07/13/2025, 5:40 PMuseVoiceAssistant
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:
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.tsxastonishing-ability-75576
07/13/2025, 6:20 PMtall-airline-16756
07/13/2025, 6:21 PMremoveParticipant
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.tsxastonishing-ability-75576
07/13/2025, 6:28 PMtall-airline-16756
07/13/2025, 6:29 PM