Kamil
12/21/2024, 3:21 PM{
"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:
{
"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):
{
"results": [
{
"toolCallId": "call_TqgLckrEWeMHFNUBoHnMjwFv",
"result": [
"08:00:00",
"08:30:00",
"09:00:00"
]
}
]
}Vapi
12/21/2024, 3:21 PMapplication/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!Kamil
12/21/2024, 3:24 PM@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 jsonVapi
12/21/2024, 3:24 PMformat_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:
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.Kamil
12/21/2024, 3:38 PMKamil
12/21/2024, 3:41 PMKamil
12/21/2024, 3:47 PMVapi
12/21/2024, 3:48 PMjson
{
"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.Kamil
12/21/2024, 4:02 PM@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"},
)Shubham Bajaj
01/02/2025, 8:10 AM