How should I implement ending the conversation aft...
# ask-ai
c
How should I implement ending the conversation after the user and bot have said goodbye? I'm using a combination of LiveKit and Twilio.
t
Thanks for reaching out, Jan. I'm an AI assistant and I'm here to help. Give me a moment while I research this topic.
To gracefully end a conversation after both the user and bot say goodbye using LiveKit and Twilio, here’s a simple guide you can follow: 1. Detect User Intent: It’s helpful to use a function tool like
end_session
to recognize when the user wants to wrap things up. This way, we can make sure everything is tidied up properly when the session ends. 2. Ensure Bot Completes Goodbye: To make sure the bot’s farewell message is fully delivered before closing the session, you can use
allow_interruptions=False
or
wait_for_playout()
. This keeps the goodbye smooth and complete. 3. End the Room Session: When it’s time, use the
delete_room
API to end the session for everyone involved, including the caller. This also stops the telephony session if Twilio is connected through SIP. 4. Twilio Integration: Deleting a LiveKit room automatically ends the linked SIP session, so the Twilio call disconnects too. If you want more control, you can use Twilio’s REST API or set up a webhook to track call status updates. If you’d like, I’d be happy to help you set up SIP trunking between Twilio and LiveKit to keep your call states perfectly in sync. Just let me know! Sources: tests/test_agent_session.py | Docs::Agents | Docs::Agents | packages/sip--um-actually/README.md
c
I need something specifically for SIP calls to end when both sides state goodbye
t
When it comes to ending SIP calls in LiveKit after both sides say goodbye, there are a couple of friendly ways to do this: 1. Try the
end_call
Function Tool:
This handy tool deletes the current room, sends a goodbye message, and gracefully ends the call. It’s a great way to make sure everything wraps up nicely. 2. Or use the
Close
or
CloseWithStatus
Methods:
The
Close
method will end the inbound call by sending a BYE signal or ending the INVITE with a busy status. Meanwhile,
CloseWithStatus
lets you customize the status code and message when you end the call. If you’d like, I’m here to walk you through how to implement either of these options step-by-step. Just let me know! Sources: pkg/sip/inbound.go | telephony/sip_lifecycle.py