https://retellai.com/?utm_source=discord&utm_medium=seo logo
Unnecessary Function Calling
# ❓・bug-report
n
Let's say my AI agent has called a function appointment booking, but when I speak or interrupt the agent while the function is being called, then the AI agent books my first appointment but also tries to book another appointment right after it, without notifying me with a completion message which throws conflict. How am I supposed to resolve this issue, that even when I say something or interrupt the AI in between it does not call the function again. Model = gpt 4-o
n
If you are using Retell LLM, then this might be a race condition type situation in which the team can only help @eviewang_ @Zexia - Retell AI
e
maybe ask customer to confirm the time AI is going to book.
this problem can be solved when our new agent builder releases
n
Yea, I did try that as well, but even if there is some background that the agent detects, so it does the same thing again.
@NJ@eviewang_ Currently, I am not using the retell LLM, I am using a custom LLM, and yes I have tried state management inside my prompts but it didnt help. Furthermore, I am utilizing the method that Evy mentioned yesterday but in case of any unnecessary noise, the agent behaves in the same way.
Copy code
this is the state management prompt that I am using:

### State Management:
- **Track the current conversation state using a global variable called "state"**
- **Maintain a single, continuous conversation state**
- **Do NOT restart the function call for intermediate inputs or patient querys**
- **Use the following states to keep track of the conversation:**
   - `Information Collection State`
   - `Function Calling State`
   - `Completion State`

- **Handle interruptions gracefully:**
   - If the user says casual phrases like "thank you," "yes," or "sure" during a function call, respond with an acknowledgment without re-triggering the function call.
   - Use an "in-progress" flag once a function call starts, preventing repeated calls until the current action is completed.
   - **STRICTLY** Do not call a single function more than once one after another even if the patient tells you to.
b
I have had this problem. I solved by assuming this can happen and not relying on prompting. Write your API calls in a way that can be idempotent. One way to do that when its a POST / UPDATE is to cache the response. So if the AI books the appointment but then decides to do it again, it will just instead retrieve the previous response from the cache.
h
@b34r43b Can you please provide more information about how you cached the response? I am trying to cache the response but in my case the agent just becomes silent, I guess the reason is response_id mismatch. But anyhow I think I am looking at wrong direction, so if you can give some more insights on how to properly cache the response that would be really helpful for us.
What I am doing is that when the agent calls the appointment booking function, I store the name of the function in a dictionary along with the param, function call time and the response of that function. So if that same function is called lets say within next 10 seconds or 15 seconds. I will simply return the response from the dictionary. But the problem here is that the agent becomes silent due to the same response_id being sent twice. I tried by manually changing the response_id to +1 but It's still causing the same issue.
@eviewang_