How to stop a video avatar (tavus for example) fro...
# ask-ai
h
How to stop a video avatar (tavus for example) from within the "Agent"
t
Thanks for reaching out, Gabi. I'm an AI assistant and I'm here to help. Give me a moment while I research this topic.
Hey! Just to make sure I understand you correctly, when you say you want to stop the video avatar, do you mean you’d like to programmatically end the avatar session, disconnect the avatar participant from the room, or something else? I’m here to help! Sources: Tavus virtual avatar integration guide | LiveKit Docs
h
yes, disconnect the avatar participant from the room
t
If you want to disconnect the avatar participant from the room, you can use the
RemoveParticipant
API from LiveKit's server-side SDKs. This handy method will remove a participant from a room and trigger a
Disconnected
event for them. Here’s a quick example in Node.js:
Copy code
import { RoomServiceClient } from "livekit-server-sdk";

const roomService = new RoomServiceClient(LIVEKIT_URL, API_KEY, API_SECRET);
await roomService.removeParticipant(roomName, participantIdentity);
And if you’re working with Python, here’s how you can do it:
Copy code
from livekit.api import LiveKitAPI, RoomParticipantIdentity

api_client = LiveKitAPI(url=API_URL, api_key=API_KEY, api_secret=API_SECRET)
await api_client.room.remove_participant(
    RoomParticipantIdentity(room=room_name, identity=participant_identity)
)
Just swap out
roomName
and
participantIdentity
with your actual room name and the participant’s identity. Also, make sure your service has the
roomAdmin
permission to make this work. If you hit any bumps or have more questions, feel free to ask—I’m here to help! Sources: packages/livekit-rtc/src/proto/room_pb.ts | livekit-api/livekit/api/room_service.py | Managing participants | LiveKit Docs | lib/src/core/room.dart | src/room/Room.ts
h
will this also handle the room output? when starting the avatar it does:
Copy code
agent_session.output.audio = DataStreamAudioOutput(
            room=room,
            destination_identity=self._avatar_participant_identity,
            sample_rate=SAMPLE_RATE,
            wait_remote_track=rtc.TrackKind.KIND_VIDEO,
        )
t
When you remove a participant from the room, they’ll get disconnected, but it’s a bit unclear if this also stops things like
DataStreamAudioOutput
automatically. Could you let me know if you’d like some help with stopping these outputs manually? Or are you noticing any particular problems with them sticking around after the disconnection?
h
can you find how the tavus avatar starts (by its plugin) and help me reverse it when disconnecting the avatar participant (i think that upon creation it forwards the output to the video agent, and it needs to be reverted on video agent disconnect)
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!
h
is there a way to send a custom event to an AgentSession or room?