Skip to content

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.

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.

{
"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.

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 seconds
POST https://api.twilio.com/2010-04-01/Accounts/{AccountSid}/Calls/{CallSid}.json
Authorization: Basic {base64(AccountSid:AuthToken)}
Content-Type: application/x-www-form-urlencoded
Status=completed

Setting the call status to completed immediately terminates the call for both parties.

The system automatically injects instructions into every agent’s prompt:

“After saying goodbye and completing the conversation, use the end_call tool to hang up. Wait a moment after saying goodbye before calling this tool, so the caller hears your farewell before the call disconnects.”

FilePurpose
build_end_call_tool_definition_service.rsReturns the tool definition
handle_end_call_tool_call_service.rsCalls Twilio REST API to set call status to completed
collect_agent_tools_service.rsRegisters end_call for all agents
end_call_util.rsTwilio REST API helper
  • Missing Twilio credentials → AppError::InvalidInput
  • Twilio API request fails → AppError::Internal with error details