Skip to main content

EndCallTool

Provide your agent with a tool that gracefully ends the call and disconnects from the room.

Available in
Beta
|
Python

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:

  1. The agent generates a final response (based on end_instructions).
  2. The session shuts down after the response is complete.
  3. If delete_room is True, the room is deleted, disconnecting all participants.
  4. The job process shuts down.

Basic usage

Add EndCallTool to your agent's tools:

from livekit.agents.beta.tools import EndCallTool
from livekit.agents import Agent
class 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 EndCallTool
from livekit.agents import Agent
class 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.

extra_descriptionstringOptional

Additional description to add to the end call tool description. Useful for providing context-specific instructions.

delete_roomboolOptionalDefault: True

Whether to delete the room when the user ends the call. Deleting the room disconnects all remote users, including SIP callers.

end_instructionsstringOptionalDefault: say goodbye to the user

Tool output to the LLM for generating the tool response. This is the message the LLM receives after the tool is called.