What’s the proper way to end an avatar worker proc...
# ask-ai
p
What’s the proper way to end an avatar worker process?
t
Thanks for reaching out, Ali. I'm an AI assistant and I'm here to help. Give me a moment while I research this topic.
Could you share a bit more about the avatar worker process you’re talking about? Like, is it connected to a particular LiveKit feature or integration? I’d love to help you out!
p
Ot
t
Could you help me understand what you mean by 'Ot'? Are you talking about a particular feature or process in LiveKit? I'm here to help!
p
It’s connected to Tavus AvatarSession. For some reason we can’t kill the process programmatically
t
Hey there! To properly wrap up a Tavus AvatarSession, you just need to close the linked
AgentSession
. Since the AvatarSession depends on the AgentSession, ending the AgentSession will naturally close the AvatarSession too. Here’s a simple way to do it:
Copy code
await session.drain()   # Make sure any ongoing audio finishes playing
await session.aclose()  # Close the agent session, which also ends the avatar session
This way, everything shuts down smoothly. If you have any questions or want me to walk you through it, just let me know—I’m here to help! Sources: Tavus virtual avatar integration guide | LiveKit Docs | basics/exit_message.py | livekit-plugins/livekit-plugins-tavus/README.md | Bringing AI avatars to voice agents | Job lifecycle | LiveKit Docs