end_call
The end_call tool lets agents hang up a phone call after saying goodbye. Instead of waiting indefinitely for the caller to disconnect, the agent can end the call programmatically via Twilio’s REST API.
When It’s Registered
Section titled “When It’s Registered”This tool is always available — every agent has access to end_call regardless of configuration. The system injects usage instructions into the agent’s system prompt automatically.
Tool Definition
Section titled “Tool Definition”{ "name": "end_call", "description": "Ends the current phone call. Use this tool after you have said your final goodbye and the conversation is complete. IMPORTANT: wait a moment after saying goodbye before calling this tool, so the caller hears your farewell before the call disconnects.", "parameters": { "type": "object", "properties": {}, "required": [] }}The tool takes no parameters — the agent simply invokes it when ready to hang up.
Execution Flow
Section titled “Execution Flow”Model calls end_call({}) → Send mark event to Twilio after buffered farewell audio → Twilio plays all buffered audio, then echoes mark back → On mark echo: call Twilio REST API to end the call → Safety net: if mark echo never arrives, force hangup after 15 secondsTwilio REST API Call
Section titled “Twilio REST API Call”POST https://api.twilio.com/2010-04-01/Accounts/{AccountSid}/Calls/{CallSid}.jsonAuthorization: Basic {base64(AccountSid:AuthToken)}Content-Type: application/x-www-form-urlencoded
Status=completedSetting the call status to completed immediately terminates the call for both parties.
Usage Instructions
Section titled “Usage Instructions”The system automatically injects instructions into every agent’s prompt:
“After saying goodbye and completing the conversation, use the
end_calltool to hang up. Wait a moment after saying goodbye before calling this tool, so the caller hears your farewell before the call disconnects.”
Implementation Files
Section titled “Implementation Files”| File | Purpose |
|---|---|
build_end_call_tool_definition_service.rs | Returns the tool definition |
handle_end_call_tool_call_service.rs | Calls Twilio REST API to set call status to completed |
collect_agent_tools_service.rs | Registers end_call for all agents |
end_call_util.rs | Twilio REST API helper |
Error Handling
Section titled “Error Handling”- Missing Twilio credentials →
AppError::InvalidInput - Twilio API request fails →
AppError::Internalwith error details
Related Pages
Section titled “Related Pages”- Agent Tools Overview — voice and task tool systems
- Agent — agent session setup and tool collection