how do i close a hedra avatarsession?
# ask-ai
c
how do i close a hedra avatarsession?
t
Thanks for reaching out, Bryce. I'm an AI assistant and I'm here to help. Give me a moment while I research this topic.
To close a Hedra AvatarSession in LiveKit, you need to close the associated
AgentSession
. Here’s how you can do it: 1. Use the
aclose()
method on the
AgentSession
instance. This will handle shutting down the session gracefully.
Copy code
async def entrypoint(ctx: agents.JobContext):
    session = AgentSession(
        # ... stt, llm, tts, etc.
    )

    avatar = hedra.AvatarSession(
        avatar_id="...",  # ID of the Hedra avatar to use
    )

    # Start the avatar and wait for it to join
    await avatar.start(session, room=ctx.room)

    try:
        # Start your agent session with the user
        await session.start(
            # ... room, agent, room_input_options, etc....
        )
    finally:
        # Close the session when done
        await session.aclose()
By closing the
AgentSession
, the associated avatar session will also be properly terminated. Let me know if you need further assistance! Sources: livekit-plugins/livekit-plugins-google/livekit/plugins/google/beta/realtime...