https://retellai.com/?utm_source=discord&utm_medium=seo logo
Custom Function running in a Infinite Loop
# ❓・bug-report
a
Thanks for tagging me @meek_55. I'll look through relevant sources and get back to you shortly.
### Answer When a custom function in Retell AI runs in an infinite loop and the response isn't passed to the next node, it usually means the function node is not transitioning properly after execution. Here are the key things to check: 1. Make sure the function node’s "Wait for Result" setting is configured correctly. If enabled, the node will wait for the function to finish before transitioning. If the function never returns a valid response or the response is not parsed as expected, it can cause the node to get stuck [(1) ]() . 2. Confirm that your custom function returns a response with a status code between 200–299. Only responses in this range are considered successful and will allow the flow to proceed [(2) ]() . 3. Ensure the API response is not empty and matches the expected format, especially if you are extracting values for dynamic variables. If the expected variable isn’t found, transition conditions based on it may fail, causing a loop . 4. Attach a conversation node after the function node to handle the result and move the flow forward [(1) ]() . If you've checked these and the issue persists, review your transition logic and any conditions based on the function result. You can also test and debug the flow using the LLM Playground to observe how the function result is handled [(3) ]() .
​ To learn more, see the sources I considered: [[1] Function Node Overview](https://docs.retellai.com/build/conversation-flow/function-node) [[2] Custom Function](https://docs.retellai.com/build/conversation-flow/custom-function) [[3] Manually test your agent](https://docs.retellai.com/test/llm-playground) ​
Feel free to tag @AI Evy with additional questions. I also appreciate feedback, it helps me improve.
m
@AI Evy But I have instructed in the prompt saying that these parameters should be derived by the Agent and passed on to the Function
a
Thanks for the follow-up, @meek_55. I'll get back to you soon.
### Answer If you've already instructed in the prompt that the agent should extract parameters and pass them to the function, make sure your function/tool usage instructions are explicit and match the parameter names exactly. For Single/Multi Prompt agents, the LLM relies on clear, step-by-step tool usage instructions to know when and how to call a function with the right arguments. If the parameters aren't being extracted as expected, double-check that your prompt includes specific triggers and references the function/tool by its exact name, along with the required parameters. For example, you might use a format like:
Copy code
///## Tool Usage Instructions
1. Gather initial information about the customer's issue.
2. If the customer mentions "get weather":
   → Call function `get_weather` with `city`
[(1) ]() If the prompt instructions are not precise or the LLM is unsure when to call the function, parameter extraction may fail, which would prevent the function from running as intended or passing results forward. Review your prompt and tool instructions for clarity and alignment with the function definition .
Feel free to tag @AI Evy with additional questions. I also appreciate feedback, it helps me improve.
​ To learn more, see the sources I considered: [[1] Prompt Engineering Guide](https://docs.retellai.com/build/prompt-engineering-guide) ​
o
Hello @meek_55 , Can you explain more ?
m
Sure sir, I have defined a Custom Function in the Conversational Flow, A function that performs a GET request from an API, it is running in a infinite loop. For the reference I have attached both the Custom Function and API GET request details. The information from the Custom Function is not being passed to the next node. If I keep a timeout it will not pass any information to the next node. https://cdn.discordapp.com/attachments/1437744163272523876/1437758251205791785/image.png?ex=69146837&is=691316b7&hm=b19408237d8bf440514439a47c655752ef5b3feed1999f418eeced506c5f6412& https://cdn.discordapp.com/attachments/1437744163272523876/1437758251595989062/image.png?ex=69146837&is=691316b7&hm=dd0632de2a5a95c69597e228c5c8af55fd6533ef01ba9a161b09ce96f53ae5b5&
o
Hello @meek_55 , can you point out where is the infite loop? or do you mean it stuck on this node ?
m
Yeah infinite loop which I meant is it is stuck in this node
o
okay I get what you mean , so it stuck because the transition condition is not met
can you show me how you set up these variables ?
m
So the variable are derived by the Agents using instructions in a prompt based on user's response and is instructed to store these in variables and pass it to the other node. I have included the instructions. https://cdn.discordapp.com/attachments/1437744163272523876/1437766620817658008/message.txt?ex=69147002&is=69131e82&hm=5753b4451ea11b36bdf1b0d1886c7879a275bb741b61e1d222873bab5d81f230&
o
So you can't really assign the variables though just prompting you have to use a tool to do that , what you can do is use the extract dynamic variables to assign values to variables https://docs.retellai.com/build/conversation-flow/extract-dv-node#extract-dynamic-variable-node
m
Thank You sir.
o
You are welcoem