Overview
Use EndCallTool to provide your agent with a tool that gracefully ends the call and disconnects from the room. The tool automatically handles cleanup, including optionally deleting the room and shutting down the session.
When the end_call tool is called:
- The agent generates a final response (based on
end_instructions). - The session shuts down after the response is complete.
- If
delete_roomisTrue, the room is deleted, disconnecting all participants. - The job process shuts down.
Basic usage
Add EndCallTool to your agent's tools:
from livekit.agents.beta.tools import EndCallToolfrom livekit.agents import Agentclass CustomerServiceAgent(Agent):def __init__(self):end_call_tool = EndCallTool()super().__init__(instructions="You are a helpful customer service agent.",tools=end_call_tool.tools,)
The LLM automatically has access to the end_call tool and can use it when the conversation is complete.
Custom implementation
By default, EndCallTool uses generic instructions for when and how to end the call. The following example customizes the tool with extra_description and end_instructions so the agent only ends the call after confirming the customer's issue is resolved and says a custom goodbye message.
from livekit.agents.beta.tools import EndCallToolfrom livekit.agents import Agentclass SupportAgent(Agent):def __init__(self):end_call_tool = EndCallTool(extra_description="Only end the call after confirming the customer's issue is resolved.",delete_room=True,end_instructions="Thank the customer for their time and wish them a good day.",)super().__init__(instructions="You are a technical support agent. Help resolve customer issues.",tools=end_call_tool.tools,)
Parameters
For a full list of parameters, see the EndCallTool reference.
stringOptionalAdditional description to add to the end call tool description. Useful for providing context-specific instructions.
boolOptionalDefault: TrueWhether to delete the room when the user ends the call. Deleting the room disconnects all remote users, including SIP callers.
stringOptionalDefault: say goodbye to the userTool output to the LLM for generating the tool response. This is the message the LLM receives after the tool is called.