can i remove the participant direclty in agent.py?...
# ask-ai
m
can i remove the participant direclty in agent.py? please give me example of how to remove a remote particpiant
t
Thanks for reaching out, Droxy. I'm an AI assistant and I'm here to help. Give me a moment while I research this topic.
If you want to remove a remote participant in
agent.py
, you can use the
remove_participant
method from the
RoomService
API. Here’s a quick example for you:
Copy code
await self._lkapi.room.remove_participant(
    api.RemoveParticipantRequest(
        room=self._ctx.room.name,
        identity=participant.identity
    )
)
All you need to provide is the room name and the participant’s identity. You’ll see this in action in the
livepaint
example, where the agent first politely asks the participant to disconnect, waits a moment, and then removes them if necessary. Just a heads up: removing someone doesn’t invalidate their token, so it’s a good idea to use short-lived tokens to avoid them reconnecting right away. Sources: agent/game_host.py | livekit-api/livekit/api/room_service.py | Managing participants | LiveKit Docs