https://retellai.com/?utm_source=discord&utm_medium=seo logo
My agent seems to have issues invoking the end_cal...
# ❓・ai-evy-support
c
@AI Evy My agent seems to have issues invoking the end_call function. It says goodbye but it does not hang up even if it's in the prompt. How can I reinforce this?
a
Thanks for tagging me @carlo_98907. I'll look through relevant sources and get back to you shortly.
### Answer To reinforce the end_call function invocation, here are several strategies based on the documentation and community experiences: For Custom LLM Integration: When using function calling with your custom LLM, ensure your function is properly defined [(1) ]() . The LLM needs to output a JSON object to trigger the function call, and you need to handle it correctly in your response event [(2) ]() . In your response event, set the
end_call
field to
true
to actually end the call after the content is spoken :
Copy code
json
{
  "response_type": "response",
  "content": "Have a great rest of your day",
  "end_call": true
}
Prompt Structure Best Practices: Structure your prompt with numbered steps, as this tends to improve LLM compliance [(3) ]() . For example: "When the conversation comes to an end or the user says 'bye': 1. Say 'have a great rest of your day'. 2. Use 'end_call' tool to end the call" Additional Safeguards: Consider setting up max call duration and max silence duration in your agent settings as backup measures to prevent overcharging if the end_call function fails . For Conversation Flow: If using conversation flow, you can attach the end_call tool to specific nodes or set it as a global node . Make sure your instructions are clear about when to use it . Testing: Always test using simulation and verify via logs afterward to ensure the function is being called correctly [(4) ]() . The key is ensuring both the prompt instruction and the technical implementation (setting
end_call: true
in the response) work together properly.
​ To learn more, see the sources I considered: [[1] Integrate Function Calling](https://docs.retellai.com/integrate-llm/integrate-function-calling) [[2] LLM WebSocket](https://docs.retellai.com/api-references/llm-websocket) [[3] Discord message from @sanava.ai on 2025-03-14](https://discord.com/channels/1186424376300679209/1294891368505937952/1350213549460553779) [[4] End Call Function Doesn’t Work](https://discord.com/channels/1186424376300679209/1356072431994933399) ​
Feel free to tag @AI Evy with additional questions. I also appreciate feedback, it helps me improve.
c
@AI Evy It seems the issue is when we use ChatGPT, any advise?
a
Thanks for the follow-up, @carlo_98907. I'll get back to you soon.
Function Calling Process: ChatGPT will evaluate the function definition with the prompts and reply back when it thinks it's time to call the function . The model will respond with the function name and arguments when it determines the call should end . Race Condition Issue: There's a known issue where if the user immediately talks back even after the
end_call: true
flag is sent, Retell might discard that flag and allow the conversation to continue [(2) ]() . This appears to be a race condition that can affect call termination consistency . Workaround Suggestions: One potential solution mentioned is to disconnect the LLM websocket whenever you want to end the call, though this might not be ideal . Another approach is implementing a timer mechanism to timeout and close the socket . Prompt Structure: Structure your instructions clearly with numbered steps, as this tends to improve compliance [(3) ]() : "When the conversation comes to an end or the user says 'bye': 1. Say 'have a great rest of your day'. 2. Use 'end_call' tool to end the call" The inconsistent behavior you're experiencing with ChatGPT appears to be a known issue that can occur due to timing and race conditions in the system [(2) ]() .
​ To learn more, see the sources I considered: [[1] How to use function calling to end the call in Retell AI](

https://www.youtube.com/watch?v=9qyML06RiT0▾

) [[2] Inconsistent Call Termination with end_call: true in agent_interrupt (Custom LLM)](https://discord.com/channels/1186424376300679209/1290770247153881190) [[3] Discord message from @mike_56558 on 2025-03-14](https://discord.com/channels/1186424376300679209/1294891368505937952/1350217287109705728) ​
### Answer Based on the available sources, when using ChatGPT/OpenAI models with Retell AI, there are specific considerations for function calling and call termination: Function Definition for ChatGPT: The function should be properly defined with clear descriptions and parameters [(1) ](

▾

) . For the end_call function, you need to define it like this:
Copy code
json
{
  "function": "end_call",
  "description": "End the call",
  "parameters": {
    "message": {
      "type": "string",
      "description": "The message you will say before ending the call with the customer"
    }
  }
}
Feel free to tag @AI Evy with additional questions. I also appreciate feedback, it helps me improve.