https://retellai.com/?utm_source=discord&utm_medium=seo logo
I am instructing an agent to call one of two funct...
# ❓・ai-evy-support
g
@AI Evy I am instructing an agent to call one of two functions in a multi-prompt depending on what the previous agent state was. It keeps ignoring my instruction to check the {{previous_agent_state}} dynamic variable and just continuously calls the same function regardless of the previous state.
a
Thanks for tagging me @Goopa Snoops. I'll look through relevant sources and get back to you shortly.
### Answer There are a few things to check when the agent isn't respecting dynamic variable conditions for function calling: 1. Ensure the dynamic variable is properly set and available Dynamic variables use the
{{variable_name}}
syntax and can be used in prompts and tool descriptions. [(1) ]() Make sure
{{previous_agent_state}}
is actually being populated with a value—if it's empty or undefined, the LLM won't have the context needed to make the decision. 2. Be explicit in your prompt about when to call each function It's best to include in the prompt explicitly when is the best time to invoke each function. [(2) ]() For example:
Copy code
When {{previous_agent_state}} equals "state_a", call the `function_one` function.
When {{previous_agent_state}} equals "state_b", call the `function_two` function.
3. Consider using multi-prompt states with edges instead If you're using a multi-prompt agent, you may get more reliable behavior by using states with edges rather than relying solely on dynamic variable checks within a single state. States help reduce prompt length and tool choices, allowing the LLM to better focus and follow rules, minimizing hallucination. [(3) ]() You can't jump to nodes using just the prompt—you have to use the edges for state transitions. [(4) ]() 4. Check your model selection Some users have reported that state transitions and conditional logic work more reliably with certain models. If you're experiencing inconsistent behavior, you might try a different model.
​ To learn more, see the sources I considered: [[1] Dynamic Variables](https://docs.retellai.com/build/dynamic-variables) [[2] Integrate any system with custom function](https://docs.retellai.com/build/single-multi-prompt/custom-function) [[3] Get Retell LLM](https://docs.retellai.com/api-references/get-retell-llm) [[4] Multi prompt agent not always transitioning to the next state](https://discord.com/channels/1186424376300679209/1412769473227657329) ​
Feel free to tag @AI Evy with additional questions. I also appreciate feedback, it helps me improve.