how do i kick someone from a call
# ask-ai
n
how do i kick someone from a call
t
Thanks for reaching out, Sebastian. I'm an AI assistant and I'm here to help. Give me a moment while I research this topic.
To remove someone from a call in LiveKit, you can use the appropriate API methods. Here are two approaches: • Using the
hangup
method:
This method removes a specific participant from the room. Example code:
Copy code
async def hangup(self):
    try:
        await self.api.room.remove_participant(api.RoomParticipantIdentity(
            room=self.room.name,
            identity=self.participant.identity,
        ))
    except Exception as e:
        # It's possible that the user has already hung up, this error can be ignored
        <http://logger.info|logger.info>(f"received error while ending call: {e}")
Using the
end_call
function:
This function can also be used to end the call for a specific participant. Example code:
Copy code
@llm.ai_callable()
async def end_call(self):
    """Called when the user wants to end the call"""
    <http://logger.info|logger.info>(f"ending the call for {self.participant.identity}")
    await self.hangup()
These methods effectively kick the participant from the call. Let me know if you need further assistance! Sources: Making calls using SIP | LiveKit Docs | Making calls using SIP | LiveKit Docs
n
2025-06-05 225131,080 - ERROR livekit.agents - exception occurred while executing tool {"function": "hangup_call", "speech_id": "speech_4ae4ee698a20"} Traceback (most recent call last): File "C:\Users\sebae\OneDrive\Escritorio\convhersa-agents\agents\convhersa\main.py", line 107, in hangup_call await ctx.api.room.remove_participant(api.RemoveParticipantResponse( ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ ValueError: Protocol message RemoveParticipantResponse has no "room" field.
t
The error you encountered,
ValueError: Protocol message RemoveParticipantResponse has no 'room' field
, occurs because the
RemoveParticipantResponse
object returned by the
remove_participant
method is an empty response object and does not contain a
room
field. To resolve this issue, ensure that you are not trying to access a
room
field on the response object. The
remove_participant
method takes a
RoomParticipantIdentity
object as input (which does have a
room
field), but the response itself is empty and does not include any fields. If you need further clarification or assistance, feel free to ask! Sources: livekit.api.room_service API documentation
n
im confused ctx = get_job_context() handle = self.session.say(final_message, allow_interruptions=False) if handle: await handle.wait_for_playout() await asyncio.sleep(0.5) await ctx.api.room.remove_participant(api.RoomParticipantIdentity( room=ctx.room.name, identity=self.manager.user_participant.identity, )) if self.manager.user_participant: await self.manager.perform_post_call_actions( participant=self.manager.user_participant, agent=self, explicit_ended_reason="AGENT_ENDED_CALL", shutdown_context=False ) await ctx.api.room.delete_room(api.DeleteRoomRequest(room=ctx.room.name)) logger.info(f"Room {ctx.room.name} gracefully hung up.")
t
Thank you for sharing the code snippet. Based on your implementation, the issue seems to be with the usage of the
remove_participant
method. Here's an example of how to correctly use it:
Copy code
# Create a RoomParticipantIdentity object with room name and participant identity
remove_request = RoomParticipantIdentity(
    room="room_name",
    identity="participant_identity"
)

# Call the remove_participant method
response = await room_client.remove_participant(remove_request)
This method forcibly disconnects the participant from the room. However, note that this action does not invalidate the participant's token. To prevent them from rejoining, you should either generate access tokens with a short TTL or ensure your backend does not provide a new token to the same participant. In your code, ensure that the
ctx.api.room.remove_participant
call is correctly structured and that you are not attempting to access fields on the response object, as it is empty. Let me know if you need further clarification! Sources: Managing participants | LiveKit Docs | livekit.api.room_service API documentation