69_scipio_69
# general-english
k
@Vapi My VAPI assistant is calling a tool but never gets the response. In the Call Logs, it calls my tool:
Copy code
{
  "role": "tool_calls",
  "time": 1734737382819,
  "message": "",
  "toolCalls": [
    {
      "id": "call_TqgLckrEWeMHFNUBoHnMjwFv",
      "type": "function",
      "function": {
        "name": "check_date_availability",
        "arguments": "{\"preferred_date\": \"tomorrow 2pm\"}"
      },
      "isPrecededByText": true
    }
  ],
  "secondsFromStart": 16.117
}
And later in the Call Logs it says it’s getting no result:
Copy code
{
  "name": "check_date_availability",
  "role": "tool_call_result",
  "time": 1734737385540,
  "result": "No result returned.",
  "toolCallId": "call_TqgLckrEWeMHFNUBoHnMjwFv",
  "secondsFromStart": 18.838
}
However, in the Webhook Logs, I can see a response with the format I’m expecting from the Docs (https://docs.vapi.ai/tools-calling):
Copy code
{
  "results": [
    {
      "toolCallId": "call_TqgLckrEWeMHFNUBoHnMjwFv",
      "result": [
        "08:00:00",
        "08:30:00",
        "09:00:00"
      ]
    }
  ]
}
v
@Kamil It seems like there might be a discrepancy between the expected response format and what your VAPI assistant is able to process. The response you've provided is correctly formatted according to the documentation, so the issue might be on the receiving end. Here are a few steps you can take to troubleshoot the issue: 1. **Check Response Timing**: Ensure that your server is responding within the expected time frame. If the response is delayed, the VAPI assistant might time out and log "No result returned." 2. **Verify Endpoint Configuration**: Double-check that the server URL configured in your VAPI assistant is correct and that it is pointing to the right endpoint which handles the tool calls. 3. **Inspect Response Headers**: Make sure that the response from your server includes the correct content-type header (
application/json
) and that it is not causing parsing issues on the VAPI assistant side. 4. **Review Server Logs**: Look at your server logs to confirm that the request from the VAPI assistant is being received and that the response is being sent correctly. 5. **Contact Support**: If after checking these points the issue persists, it might be a good idea to reach out to VAPI support with the details of your implementation and the logs you've collected. If you need further assistance or if you'd like me to perform any specific actions, please let me know!
k
@Vapi For reference, this is the code for my tool call:
Copy code
@app.post("/check_date_availability")
async def check_date_availability_vapi_tool(request: Request):
    payload = await request.json()
    preferred_date = payload["message"]["toolCalls"][0]["function"]["arguments"][
        "preferred_date"
    ]

    # TODO: compute start, end dates from preferred date
    time_slots = ghl_service.get_free_time_slots(
        unix_start_date="1734930000000",
        unix_end_date="1735016100000",
        timezone="America/New_York",
    )
    formatted_time_slots = ghl_util.format_time_slots(time_slots)
    toolCallId: str = payload["message"]["toolCalls"][0]["id"]
    formatted_time_slots_vapi_tool_response = vapi_util.format_vapi_tool_call_response(
        toolCallId=toolCallId, result=formatted_time_slots
    )
    return formatted_time_slots_vapi_tool_response

def format_vapi_tool_call_response(toolCallId: str, result):
    response = {"results": [{"toolCallId": toolCallId, "result": json.dumps(result)}]}
    return json.dumps(response)
Do you think there is an issue with how im returning the result of the tool call? As you can see, im returning a json
v
@Kamil Based on the code snippet you've provided, there is a potential issue with the way the result is being returned in the
format_vapi_tool_call_response
function. You are using
json.dumps
on the
result
before including it in the
response
dictionary, and then again using
json.dumps
on the entire
response
. This double encoding could be causing the problem. Here's the corrected version of the
format_vapi_tool_call_response
function:
Copy code
python
def format_vapi_tool_call_response(toolCallId: str, result):
    # No need to use json.dumps on the result here, as it will be encoded when the entire response is dumped to JSON
    response = {"results": [{"toolCallId": toolCallId, "result": result}]}
    return json.dumps(response)  # Only one json.dumps call is necessary
With this change, the
result
will be a JSON object within the
response
JSON, rather than a stringified JSON within the
response
JSON. This should align with the expected format for the VAPI assistant to process the response correctly.
k
@Vapi no, doesnt change anything assistant is still unable to see the result is it that when returning the tool call result from the python server sdk in python, im supposed to make some kind of http request?
@User Do you guys know why the assistant isnt able to see the call results and the Call Logs say as much, whereas the Webhook logs clearly show im returning the right type of response for the tool call??
@Vapi hello??
v
@Kamil I apologize for any confusion. Let's try to address the issue step by step. When you're returning the result of a tool call from your server, you should not need to make an additional HTTP request. The response to the POST request made by the VAPI assistant should be sufficient, provided it's in the correct format. The response format for a tool call should typically look like this:
Copy code
json
{
  "results": [
    {
      "toolCallId": "the_tool_call_id_received_in_request",
      "result": {
        // ... the actual result object, not stringified
      }
    }
  ]
}
From your code, it seems you are correctly structuring the response. However, the double
json.dumps
might be causing the issue. The
result
should be a JSON object, not a string. The
json.dumps
should only be called once to convert the entire response object to a JSON-formatted string before returning it. If the assistant is still unable to see the call results, here are a few things to check: 1. **Content-Type Header**: Ensure that the response has the
Content-Type
header set to
application/json
. 2. **Status Code**: The HTTP status code should be
200 OK
to indicate a successful response. 3. **Tool Call ID**: Verify that the
toolCallId
in the response matches the
toolCallId
received in the request. 4. **No Extra Encoding**: Ensure that the
result
is a JSON object and not a stringified JSON within the response. 5. **Logs**: Review the Webhook logs and Call Logs to see if there are any discrepancies or errors reported. If you've checked all of these and the issue persists, it might be best to reach out to the support team with specific details of the problem, including request and response logs, for further assistance. Please ask support for more info on this.
k
Ok, I fixed the issue. For anyone who might be reading this in the future, I fixed this by returning a JSONResponse at the server endpoints for the tool call:
Copy code
@app.post("/check_date_availability")
async def check_date_availability_vapi_tool(request: Request):
    payload = await request.json()
    # logging.info(f"DEBUG check date availability payload: {payload}")
    preferred_date = payload["message"]["toolCalls"][0]["function"]["arguments"][
        "preferred_date"
    ]

    # TODO: compute start, end dates from preferred date
    time_slots = ghl_service.get_free_time_slots(
        unix_start_date="1734930000000",
        unix_end_date="1735016100000",
        timezone="America/New_York",
    )
    formatted_time_slots = ghl_util.format_time_slots(time_slots)
    toolCallId: str = payload["message"]["toolCalls"][0]["id"]
    formatted_time_slots_vapi_tool_response = vapi_util.format_vapi_tool_call_response(
        toolCallId=toolCallId, result=formatted_time_slots
    )
    logging.info(
        f"DEBUG check date availability time_slots: {formatted_time_slots_vapi_tool_response}"
    )
    return JSONResponse(
        content=formatted_time_slots_vapi_tool_response,
        headers={"Content-Type": "application/json"},
    )
s
Hey @Kamil 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 me figure out what went wrong!
2 Views