archpunch
08/05/2025, 8:55 PMdef create_call():
resp = requests.post(
"https://api.vapi.ai/call",
headers={"Authorization": API_KEY, "Content-Type": "application/json"},
json={
"assistantId": ASSISTANT_ID,
"transport": {
"provider": "vapi.websocket",
"audioFormat": {
"format": "pcm_s16le",
"container": "raw",
"sampleRate": SR
}
},
"assistantOverrides": {
"variableValues": {
"full_name": "",
"phone": "",
"date": "",
"time": "",
"appointment_type": ""
}
}
}
)
if not resp.ok:
print("Failed to create call:", resp.text)
return None
return resp.json()["transport"]["websocketCallUrl"]
call id for example:
9cda111e-53f5-4fe6-97f6-da072adbde6carchpunch
08/05/2025, 8:57 PM{
"id": "71276008-3da2-48c6-bc80-31b3b9d0d63d",
"createdAt": "2025-06-14T20:16:34.394Z",
"updatedAt": "2025-08-05T18:00:45.226Z",
"type": "function",
"function": {
"name": "search_patient",
"strict": true,
"parameters": {
"type": "object",
"properties": {
"phone": {
"description": "",
"type": "string"
},
"full_name": {
"description": "",
"type": "string"
}
},
"required": []
}
},
"messages": [
{
"role": "assistant",
"type": "request-complete",
"content": "I have found patient {{full_name}}. The phone number is: {{phone}}. Do you want to schedule an appointment?",
"conditions": [
{
"param": "phone",
"value": "\"\"",
"operator": "neq"
}
],
"endCallAfterSpokenEnabled": false
},
{
"type": "request-start",
"content": "Please wait a second, i am checking our database for the patient called {{full_name}}",
"blocking": false,
"conditions": [
{
"param": "full_name",
"value": "\"\"",
"operator": "neq"
}
]
},
{
"type": "request-response-delayed",
"content": "I am facing some delay, sorry for that.",
"timingMilliseconds": 1000
}
],
"orgId": "577d690d-6bc1-40e5-ba66-2baad1505f3f",
"async": false
}
i am getting tool call request:
search_patient (call_id=call_rnm9I0v5U6A8NUsWn4OwTHhc): {"full_name": "Xxx"}
And i am sending answer:
{'results': [{'toolCallId': 'call_rnm9I0v5U6A8NUsWn4OwTHhc', 'result': {'full_name': 'Xxx', 'phone': 'Yyy'}}]}}archpunch
08/05/2025, 8:58 PMasync def handle_tool_call(ws, tool_call):
import uuid
call_id = tool_call["id"]
tool_name = tool_call["function"]["name"]
args = json.loads(tool_call["function"].get("arguments", "{}") or "{}")
result = {}
try:
if tool_name == "search_patient":
r = requests.get("https://scheduling-test.vercel.app/patients/search", params=args)
if r.ok and r.text.strip():
d = r.json()
user_data.update({
"user_id": d.get("user_id"),
"full_name": d.get("full_name"),
"phone": d.get("phone")
})
result = {
"full_name": d.get("full_name"),
"phone": d.get("phone")
}
payload_data = {
"user_id": user_data["user_id"],
"datetime": f"{args.get('date')} {args.get('time')}",
"appointment_type": appointment_type,
"full_name": user_data.get("full_name"),
"phone": user_data.get("phone")
}
r = requests.post("https://scheduling-test.vercel.app/appointments/create", json=payload_data)
data = r.json()
if data.get("status") == "success":
result = {
"full_name": user_data["full_name"],
"date": args.get("date"),
"time": args.get("time"),
"appointment_type": appointment_type
}
else:
print(f"Unknown tool: {tool_name}")
except Exception as e:
print(f"Error in {tool_name}: {e}")
result = {}
payload = {
"results": [{
"toolCallId": call_id,
"result": result
}]
}
await ws.send(json.dumps(payload))archpunch
08/05/2025, 9:01 PM{
"role": "bot",
"time": 1754416697157,
"source": "",
"endTime": 1754416701547,
"message": "Thank you for calling Vera Dental of Riverton. Uh, this is Robin, your health care coordinator.",
"duration": 4310,
"secondsFromStart": 0.79999995
}
{
"role": "user",
"time": 1754416702906.9998,
"endTime": 1754416706257,
"message": "Hi. Please provide me with the information about patient Max.",
"duration": 3060.000244140625,
"secondsFromStart": 6.5499997
}
{
"role": "bot",
"time": 1754416707746.999,
"source": "",
"endTime": 1754416710007,
"message": "Please wait a second. I am checking our database.",
"duration": 2260.0009765625,
"secondsFromStart": 11.389999
}
{
"role": "tool_calls",
"time": 1754416708120,
"message": "",
"toolCalls": [
{
"id": "call_rnm9I0v5U6A8NUsWn4OwTHhc",
"type": "function",
"function": {
"name": "search_patient",
"arguments": "{\"full_name\": \"Max\"}"
}
}
],
"secondsFromStart": 9.858
}
{
"role": "bot",
"time": 1754416710927.001,
"source": "",
"endTime": 1754416711767,
"message": "For the patient called",
"duration": 839.9990234375,
"secondsFromStart": 14.570001
}
{
"name": "search_patient",
"role": "tool_call_result",
"time": 1754416713018,
"result": "No result returned.",
"toolCallId": "call_rnm9I0v5U6A8NUsWn4OwTHhc",
"secondsFromStart": 14.756
}
{
"role": "bot",
"time": 1754416713687,
"source": "",
"endTime": 1754416722717,
"message": "I'm sorry, but I couldn't find any information for a patient named Max in our records. Could you please provide a full name or a phone number for more accurate results?",
"duration": 8470,
"secondsFromStart": 17.33
}
so the assistant still doesnt get any tool call answer from my API. I have spent several months and this problem and dont know what to do, pls help me. I can send full script of my apiHilal @ UnitZero AI
08/05/2025, 9:03 PMHilal @ UnitZero AI
08/05/2025, 9:04 PMHilal @ UnitZero AI
08/05/2025, 9:04 PMarchpunch
08/13/2025, 11:28 AMarchpunch
08/13/2025, 11:43 AMarchpunch
08/13/2025, 11:51 AMChiranjeet Mishra
08/15/2025, 5:29 PM{
"results": [
{
"toolCallId": "X",
"result": "Y"
}
]
}archpunch
08/17/2025, 4:00 PMChiranjeet Mishra
08/19/2025, 1:59 PMarchpunch
08/19/2025, 7:06 PMChiranjeet Mishra
08/21/2025, 3:49 PMkyle
09/05/2025, 12:10 AMarchpunch
09/16/2025, 11:06 AMChiranjeet Mishra
09/18/2025, 6:56 AM