OpenAI tool is not called reliably
# support
l
I have a task in my conversation flow, which should always call a tool 'send_email'. It only does from time to time - usually only if the customer mentions word 'email'. I am attaching the part of the conversation flow:
Copy code
yaml
2. Inform the customer: "Ok, so I am sending the code to your email right now.".
- Trigger the 'send_email' function.
- <wait for 'send_email' result>
- Proceed to step 3.
Function:
Copy code
js
{
  type: 'function',
  messages: [
    {
      type: 'request-complete',
      content: `It was sent! The code you can use is ${pronouncation}.`,
    },
    {
      type: 'request-failed',
      content: `Ah, I couldn't send the email right now. The code you can use is ${pronouncation}.`,
    },
    {
      type: 'request-response-delayed',
      content: `um give me a sec`,
      timingMilliseconds: 2000,
    },
  ],
  function: {
    name: 'send_email',
    description: 'Sends an email with the code to the customer.',
  },
  async: false,
  server: {
    url: `${env.PUBLIC_URL}/email`,
  },
},
How can I make the tool call reliable? I've tried making it
async: true
, but it did not help
v
According to [documentation](https://discord.com/channels/1211482211119796234/1211483291191083018/threads/1325000684231196775), incorrect response formats can cause tool call failures. ### 5. Enable Monitoring Add monitoring to help diagnose issues:
Copy code
js
const assistant = {
  monitorPlan: {
    listenEnabled: true,
    controlEnabled: true
  }
};
This will help you see what's happening during the call and identify potential issues. ### 6. Model Temperature Consider setting a lower temperature (0-0.3) for more predictable responses, as suggested in [community discussions](https://discord.com/channels/1211482211119796234/1211483291191083018/threads/1341892594044633099). Is there anything specific about these suggestions you'd like me to elaborate on? Sources: - [https://discord.com/channels/1211482211119796234/1211483291191083018/threads/1336440478727667844](https://discord.com/channels/1211482211119796234/1211483291191083018/threads/1336440478727667844) - [https://discord.com/channels/1211482211119796234/1211483291191083018/threads/1341835360094785587](https://discord.com/channels/1211482211119796234/1211483291191083018/threads/1341835360094785587) - [https://discord.com/channels/1211482211119796234/1211483291191083018/threads/1325000684231196775](https://discord.com/channels/1211482211119796234/1211483291191083018/threads/1325000684231196775) - [https://discord.com/channels/1211482211119796234/1211483291191083018/threads/1340737584309211136](https://discord.com/channels/1211482211119796234/1211483291191083018/threads/1340737584309211136) - [https://discord.com/channels/1211482211119796234/1211483291191083018/threads/1341892594044633099](https://discord.com/channels/1211482211119796234/1211483291191083018/threads/1341892594044633099)
Hi there! 👋 I see you're having trouble with the reliability of your
send_email
tool call in your conversation flow. I'm unable to diagnose the specific issue with your server implementation at
${env.PUBLIC_URL}/email
, but I can definitely help with several approaches to improve the reliability of your tool calls. Here are some strategies to make your OpenAI tool calls more reliable: ### 1. Model Selection Consider using a more stable model for production. According to [community discussions](https://discord.com/channels/1211482211119796234/1211483291191083018/threads/1336440478727667844), it's recommended to "use GPT-4o for production and realtime for development/testing" as the realtime model may be less stable. ### 2. Tool Configuration Adjustments Try these configuration changes:
Copy code
js
{
  type: 'function',
  messages: [], // Set empty messages array to prevent default messages
  function: {
    name: 'send_email',
    description: 'Sends an email with the code to the customer.',
  },
  async: false, // Keep synchronous
  blocking: true, // Add this to ensure it waits for completion
  server: {
    url: `${env.PUBLIC_URL}/email`,
  },
}
Setting
blocking: true
will make the tool call wait for the
onComplete
callback after the message is spoken before proceeding, which may help with reliability. ### 3. Prompt Engineering Modify your conversation flow to explicitly instruct the LLM to call the tool:
Copy code
yaml
2. Inform the customer: "Ok, so I am sending the code to your email right now. I will now use the send_email tool to send you the code."
- Trigger the 'send_email' function.
- <wait for 'send_email' result>
- Proceed to step 3.
### 4. Response Format Ensure your server is returning the correct JSON format that Vapi expects:
Copy code
json
{
    "results": [{
        "toolCallId": "dynamically_replace_with_actual_id",
        "result": "Email sent successfully with code XYZ"
    }]
}
b
Thank you for reaching out to us. We've received your message and will get back to you as soon as possible.
Hi, checking if this is resolved/solved for you?
l
Hey, no, all the suggested changes were tried before. I am already using the suggested model. The prompt is the same. Changes to 4 and 5 steps are irrelevant if the function is not called at all
b
Hey! To help track down this issue, could you share: - The call ID - When exactly this happened (the timestamp) - What response you expected to get - What response you actually got instead This would really help us figure out what went wrong!
l
Hey, Call id:
f4fe2b4c-1359-4cd1-875e-095931bfbf27
So it said this twice in the call "Ok, so I am sending the code to your email right now." at
15:49:05:119
and
15:49:08:190
It should've called
send_email
function both times, but it did not do that even a single time
b
Change it to the following and then it will work.
Copy code
"Ok, so I am sending the code to your email right now. and  Trigger the 'send_email' function