https://retellai.com/?utm_source=discord&utm_medium=seo logo
custom function / tool is making multiple requests...
# ❓・ai-evy-support
n
@AI Evy custom function / tool is making multiple requests towards our endpoint every time the agent uses it. How to limit this to only one request per chat session?
a
Thanks for tagging me @NR. I'll look through relevant sources and get back to you shortly.
### Answer --- Based on the available documentation, there isn't a built-in setting to limit a custom function to only one request per chat/call session. [(1) ]() , [(2) ]() However, here are a few approaches you can consider: 1. Handle deduplication on your server side When Retell calls your custom function endpoint, it includes the
call
object with a unique
call_id
. [(1) ]() , [(2) ]() You can use this
call_id
to track whether the function has already been executed for that session and return a cached response for subsequent requests. 2. Use dynamic variables to track state You can extract a response variable from your first function call and save it as a dynamic variable. [(1) ]() , [(2) ]() Then, update your prompt to instruct the agent to only call the function if that variable hasn't been set yet. 3. Adjust your prompt Include explicit instructions in your prompt about when to invoke the custom function—for example: "Only call
your_function_name
once at the beginning of the conversation" or "Do not call
your_function_name
if you have already retrieved the information." [(1) ]() Note on retries: When a request fails, Retell will retry up to 2 times. , [(2) ]() If you're seeing multiple requests, ensure your endpoint is returning a 200-299 status code to indicate success. Would you like more details on imple
menting any of these approaches?
​ To learn more, see the sources I considered: [[1] Integrate any system with custom function](https://docs.retellai.com/build/single-multi-prompt/custom-function) [[2] Custom Function](https://docs.retellai.com/build/conversation-flow/custom-function) ​
Feel free to tag @AI Evy with additional questions. I also appreciate feedback, it helps me improve.
n
what response should the tool return for retell to interpert it as a successful request
@AI Evy what response should the tool return for retell to interpert it as a successful request
a
Thanks for the follow-up, @NR. I'll get back to you soon.
### Answer For Retell to interpret a custom function response as successful: HTTP Status Code: Return a status code between 200-299. [(1) ]() Response Format: The response can be in various formats: - string - buffer - JSON object - blob All formats will be converted to string before being sent to the LLM for further processing. Example response (JSON) :
Copy code
javascript
return res.json("25f and sunny") ;
Or in Python:
Copy code
python
return JSONResponse(status_code=200, content={"result": "25f and sunny"})
Note: The function result is capped at 15,000 characters to prevent overloading the LLM context window.
​ To learn more, see the sources I considered: [[1] Custom Function](https://docs.retellai.com/build/conversation-flow/custom-function) ​
Feel free to tag @AI Evy with additional questions. I also appreciate feedback, it helps me improve.