Where to create and how to modify Tools Calling
# support
n
I am going through the https://docs.vapi.ai/tools-calling documentation and trying to figure out where I would modify the payload to get this working. In the vapi dashboard, I've updated the 'Server Url' to point to my server, and the function is being correctly triggered in the following format: { "message": { "type": "function-call", "call": { Call Object }, "functionCall": { "name": "sendEmail", "parameters": "{ \"emailAddress\": \"john@example.com\"}" } } } Do I have to modify the above request payload to the below format, { "type": "function", "messages": [ ... ], "function": { ... }, "async": false, "server": { ... } } I'm not understanding where this payload change should occur. Thanks for the assistance!
v
Hi @nicksi0555, I'm an AI assistant for Vapi. I'll analyze available sources and get back to you shortly.
----------------------------- **While I generate an answer, here are some sources that might be helpful**: * [Tools Calling]() * [Server URLs]() * [Server Events]() * [Function Calling]() -----------------------------
### Answer To modify the Tools Calling payload for your needs, you would typically do so within your application or script that interacts with Vapi. The process goes as follows: 1. Create Function Configuration: The payload structure you provided represents the configuration for a "function" type tool within Vapi. You should define this configuration in the part of your code that sets up or defines the behavior of your voice AI assistant. The payload you have seen in the documentation is meant to be used as a template to adapt according to your specific needs [(1)]() . 2. Modifying the Payload: Based on the template provided in the documentation, you would: - Change the
"name"
under the
"function"
object to match your specific function. - Adjust the
"parameters"
object to include the data your function requires. - Modify the
"messages"
array to contain the messages you want the AI to communicate to the user at different stages of the tool's execution. - Set the
"async"
value based on whether you want the function call to be synchronous or asynchronous. - Replace the URL in the
"server"
object with your server's endpoint URL. Here's an example modification based on the template:
Copy code
json
{
  "type": "function",
  "messages": [
    {
      "type": "request-start",
      "content": "Checking the weather forecast. Please wait..."
    },
    {
      "type": "request-complete",
      "content": "The weather in location is"
    }
  ],
  "function": {
    "name": "sendEmail",
    "parameters": {
      "type": "object",
      "properties": {
        "emailAddress": {
          "type": "string"
        }
      }
    },
    "description": "Sends an email to the specified address."
  },
  "async": false,
  "server": {
    "url": "https://your-server.com/send-email"
  }
}
This modification aligns with the structure you're looking to achieve. Note that
"messages"
and other parts of the payload should be filled out according to your application's logic and requirements. Remember, the payload structure and modifications are usually handled within your code that interacts with Vapi, whether it's for setting up assistants or defining specific voice AI behaviors. Ensure to test your configurations thoroughly to confirm that the behavior aligns with your expectations.
n
Ok still not understanding whether I would make the payload change there or not. The example modification doesn't include any of the sendEmail paramter values.
v
Got it. Tagging @User for additional help.
s
Tools calling is only supported via API call. Like what is your exact usecase?
n
Sure. So I am having someone book an appointment. So they would say the date (May 1st), and my checkAvailability function is being triggered. In the vapi dashboard, I updated the Server Url to be my server, and it is correctly going here, router.post('/assistantServerUrl', async (req, res) => { const reqBody = JSON.parse(req.body); const message = reqBody.message; if (message?.functionCall === 'checkApptAvailability') { res.status(200).send({}); } }); Just not understanding how to execute the API call to the function tools (whether to include inside the {} brackets or where once I get to my server). Thanks.
s

https://www.youtube.com/watch?v=l6yDtXfIarM

n
Great thanks for the link. Yep, I have already wired everything up in make.com and my system prompt and make.com scenarios are very similar (using google calendar instead). The video doesn't provide an example of how to integrate the function tools so that we can interject various messages using "request-start" or "request-response-delayed" for customization purposes.
s
you need to use api to add it
n
I see. I think I'm following. So the api call would be after the function has triggered and it has gone into the make.com scenario, correct?
So I took one of the api calls I already did as an example below. 1. What would the vapi url be for that? 2. Would the request content be something like the below, { "type": "function", "messages": [ ... ], "function": { ... }, "async": false, "server": { ... } }
s
No. You need to create first tool calling using api in vapi then you need to return the tool result in the format that I mentioned in the doc
n
Ok I see. So when I go to vapi's Swagger UI, I just see the FunctionTool schema but not a way to execute it 🤔 . Am I looking in the wrong place?
Ah ok. So we are supposed to input the function tools in the CreateAssistant and UpdateAssistant methods, correct?
I was thinking there would be a separate FunctionTool method I could execute for this.
s
Yup.
n
ok so i was able to include the tools function in the following format to verify user info before checking availability. The assistant correctly says "Verifying user info, Please wait...", but the function is never called. I have also selected all the serverMessages options (e.g. "functioncall", etc). Why is it not triggering the function? { "model": { "model": "gpt-4", "provider": "openai", "messages": [ { "role": "system", "content": "Only here to show template." } ], "tools": [ { "type": "function", "messages": [ { "type": "request-start", "content": "Verifying user info. Please wait..." }, { "type": "request-failed", "content": "I wasn't able to verify user information right now." }, { "type": "request-response-delayed", "content": "It appears there is some delay in verifying user info.", "timingMilliseconds": 1000 } ], "function": { "name": "verifyUserInfo", "parameters": { "type": "object", "properties": { "accessWord": { "type": "string", "description": "The access word to allow usage of the assistant." } } }, "description": "Use this function to verify user information before booking any appointments." }, "async": false, "server": { "url": "Make url link" } } ], "maxTokens": 250, "temperature": 0 } }
s
Can you send me the call_id?
n
Sure call id is 9dbed299-8187-4a49-8ea2-87f6bba0c9b3
the latest one is 16e106a6-f75c-484d-98f4-dc116a36fcac both should be in the same format
Your tool_calling and function aren't saved properly due to which it is happening
please try to save it once more
n
Ok I see. So the functions should also have the below? "functions": [ { "name": "verifyUserInfo", "async": false, "serverUrl": "Make url", "parameters": { "type": "object", "properties": { "accessWord": { "type": "string", "description": "The access word to allow usage of the assistant." } } }, "description": "Use this function to verify user information before booking any appointments." } ]
I wasn't sure if it was required or not since it was already inside the tools array.
n
Cool thanks 😎! Will test this today and let you know.
s
Okay.
n
Cool thanks Sahil. Finally got it working. What fixed it was adding "tool-calls" in the serverMessages. One thing that is tricky is that when we are using Swagger UI and/or Vapi API calls to update our assistants, we can no longer use the Publish functionality on the Vapi assistant dashboard. I kept changing system prompt there and publishing and all my tool functions kept getting erased. I will need to remember that if trying to use all the newest Vapi features I shouldn't be using the Vapi assistant dashboard as I think the Publish command is doing a PUT vice PATCH.
k
Please @Sahil, This should be added to the docs. I spent hours on this. Thanks OP
s
@nicksi0555 can you share your configuration here so that other people get benefit from it as well?
I will add it.
n
Sure here is a usable config template. One note: Your content must specify the function as a tool's function as otherwise the assistant will likely wait for another trigger (e.g. "are you there") before it knows to execute as a tool's function. I kept having it get to the "request-start" statement, but would require another push to execute. Just adding "tool's" before function fixed that 🙂 . Hope this helps!
s
@A.Salem this might be useful for you!
I will update the docs
s
I'm having problem using tools in my API. Consistently get this error message: "assistant.model.each value in tools.function.property server should not exist". Not sure what's wrong. Please help. "function": { "name": "bookAppointment", "description": "When the user want to book an appointment.", "parameters": { "type": "object", "properties": { "Name": { "type": "string", "description": "This is the name of the user" }, "BookingTime": { "type": "string", "description": "This is the time and day the user would like to book" } }, "required": [ "Name", "BookingTime" ] }, "async": false, "server": { "url": "Make URL" } } }
s
Can you send the full payload? @Savannah
what is the exact issue that you are facing?
s
Copy code
{
  "message": [
    "assistant.model.each value in tools.function.property server should not exist"
  ],
  "error": "Bad Request",
  "statusCode": 400
}
I removed this, still get the same error.
s
You are providing server property inside the tools function section but rather it should be tools level.
s
It's working now. Thank you @Sahil . You're genius.