"an unexpected error occured" on tool call
# support
b
Call Id: 46d2b594-e051-40bc-a06e-46df8b36e771 My API for the tool call showed no issues and returned what seems a healthy response The VAPI logs show:
Copy code
{
  "name": "call_PH8mMMjyeQt0ZSfe",
  "role": "tool_call_result",
  "time": 1737057643352,
  "result": "An unexpected error occurred.",
  "toolCallId": "call_PH8mMMjyeQt0ZSfe",
  "secondsFromStart": 24.426
}
And the client received the same. I get this with gpt-4o-realtime-preview-2024-12-17 but not "gpt-3.5-turbo". I appreciate the realtime is in preview/beta so is not production ready but would be good to know what is happening here. Maybe it doesn't support tool calling?
v
You can continue this conversation by mentioning me in the message.
@Ben I'm sorry to hear that you're experiencing issues with the API call. It seems like there might be an unexpected error occurring with the gpt-4o-realtime-preview-2024-12-17 model when it comes to tool calling. Since this model is in preview/beta, it's possible that some features, such as tool calling, might not be fully supported or could contain bugs that are not present in the more stable gpt-3.5-turbo model. To better assist you, could you please provide more details about the API call you're making? Specifically, I would need to know the parameters and the context of the call to understand what might be causing the issue. Once I have more information, I can help you troubleshoot the problem more effectively.
b
The tool call
Copy code
{
  "role": "tool_calls",
  "time": 1737057643348,
  "message": "",
  "toolCalls": [
    {
      "id": "call_5LnMhRC3IgMAVgV1",
      "type": "function",
      "function": {
        "name": "retrieve_and_generate",
        "arguments": "{\"query\": \"経費精算 締め切りはいつ\"}"
      }
    }
  ],
  "secondsFromStart": 24.422
}
Worked and was received by the API - which is performing RAG and returning a jsonified response in the correct format described here: https://docs.vapi.ai/tools-calling
@User
s
@Ben You must return the response in string format currently it is in record or object format which doesn't works. The tool expects the string that will be spoken out.
Copy code
json
{
    "results": [
        {
            "toolCallId": "X",
            "result": "Y"
        }
    ]
}
If you want to store the result in message history, you can stringify the response in the format below, and the message content will be voiced out.
Copy code
json
"results": [
    {
      "toolCallId": "<insert-your-tool-call-id-here>",
      "result": "<insert-tool-call-result-here>",
      "message": {
        "type": "request-complete",
        "role": "assistant",
        "content": "<insert-the-content-here>"
      }
    }
  ]
}
b
I see thank you, I will try this
@Shubham Bajaj so if we wish to return the result of the tool to the conversation without voicing it out (i.e. to inform the LLM of the tool result so it can decide how next to proceed), would the correct way be to set the content of the message to an empty string?
Copy code
"results": [
    {
      "toolCallId": "<insert-your-tool-call-id-here>",
      "result": "<JSON stringified response data here>",
      "message": {
        "type": "request-complete",
        "role": "assistant",
        "content": ""
      }
    }
  ]
}
As if we omit the message field you are saying I think that it will try and voice out the result string instead
s
@Ben no if you want LLM to decide what response to generate next then simply use the result property only.
b
@Shubham Bajaj please could you look into call ID 8d9efbd2-9a27-4240-9aa5-301093cc1a78 and help me understand why I am still hitting 'unexpected errors' with the Realtime API
Copy code
{
  "name": "call_xlnxf7fo9OLkVAhK",
  "role": "tool_call_result",
  "time": 1738068305471,
  "result": "An unexpected error occurred.",
  "toolCallId": "call_xlnxf7fo9OLkVAhK",
  "secondsFromStart": 18.751
}
The output of the model has the JSON in format described, with a field 'result' which is a JSON serialised string, so the format matches that you describe as far as I can see I wonder if it could be related to certain tokens not being parsable by VAPI/OpenAI even after setting
result=json.dumps(content, ensure_ascii=False)
- but the unexpected error is hidden from me - I presume on your side you might be able to see what error specifically is occuring The other thing I notice is that sometimes VAPI sends this kind of message to the assistant conversation update:
Copy code
{
          "role": "tool",
          "tool_call_id": "call_Sp57yvMnrz0v9aGj",
          "content": "Tool Result Still Pending But Proceed Further If Possible."
        },
And the bot then it maybe uses that as a queue to re-call the tool, resulting in a spam of tool calls (?) at least we see several tool calls occuring when we get unexpected errors. More generally, if the tool call is synchronous and not yet responded, I do not understand why we would be prompting the bot to "Proceed Further" --> that seems like a bug? How can I inform VAPI to block until the call returns? I've already set it as syncronous and a generous server timeout but that doesn't seem to afefect this message when using Realtime API.
s
> "content": "Tool Result Still Pending But Proceed Further If Possible." In messagesToOpenAIFormatted, whenever a tool call (i.e., a function call) lacks a corresponding tool-call-result in the conversation messages, the function inserts the placeholder text,* "Tool Result Still Pending But Proceed Further If Possible.".* This occurs when a tool call has been requested, yet the conversation data does not include the relevant "tool_call_result" object for that call. Consequently, the function replaces it with a placeholder result in the combined/merged chat history, allowing the remainder of the code or the LLM to manage it consistently, particularly in scenarios involving parallel tool calls. In simpler terms, this message appears because the code consolidates all tool calls into the final OpenAI-formatted conversation, and if any tool call is still awaiting a genuine result (or if no result was ever documented), it utilizes the placeholder to convey: “We do not currently possess a genuine tool response, but please continue if possible.”
@Ben this doesn't means it results into frequent tool calls.
@Ben The LLM triggers the same tool function repeatedly and in quick succession (parallel tools calling) then the function ends up with multiple “parallel” calls. This often causes overlapping or conflicting operations in the backend. Either: 1. Manage all concurrent calls so each request is handled properly and responded to, or 2. Adjust your prompts (or conversation flow) so only a single instance of
retrieve_and_generate
is called at a time. That way, you avoid collisions and “unexpected error” conditions that come from unhandled parallel calls.
b
@Shubham Bajaj thank you for the explanation, so these unexpected errors are result of multiple parallel calls by the LLM to the tool. With the same prompt, I do not get this with standard LLMs, it's likely the nature of the speech to speech model for Realtime API that means it can send multiple calls before waiting for a response. I've tested my API and I can respond to concurrent requests - from the point of view of my API server it's just receiving serial calls with short interval no errors reported, so I assume the unexpected error is occurring in that VAPI middleware when multiple calls are occuring with no response within a certain timeframe. Regarding solutions: 1. Managing concurrent calls - I'm using a Flask API which can respond to multiple concurrent calls and delivers a response for each 2. Adjust the prompts - Given the LLM has no concept of time, I'm not quite sure how one could adjust it to ensure it "waits" for a response (which is the behaviour we get for free with non-Realtime API it seems) . I assume the reason it is repeating the tool call is because while it is waiting for the response it is receiving an instruction from VAPI "Tool Result Still Pending But Proceed Further If Possible." and so it seems plausible the realtime model assumes the logical thing to do is call the same tool again. I could try and explicitly prompt it to ignore such request and wait until it receives a tool_call_result object before making any further speech mark maybe, but even better would be an option to disable ability of the LLM to perform parallel calls entirely somehow
s
> send multiple calls before waiting for a response. The LLM waits for all tool call response, you were expecting a one tool call instead you have receive multiple and returned the response for one of them only and not for the other because of these in logs you observed "An unexpected error occurred." > "Tool Result Still Pending But Proceed Further If Possible." Because of multiple tools calling we have to add this so LLM doesn't errors out if for some tool call reference is missing and add this placeholder gives LLM an percievence result will arrive later kinda promise.
9 Views