Support Inquiry: Tool Calls Functionality in Web-B...
# support
s
Hi Team, I’m new to the platform and exploring its capabilities. I’d like to know if web-based calling ( https://docs.vapi.ai/quickstart/web ) supports customly created tool calls functionality within the agentOptions. I attempted to implement it but didn't work. Can anyone please clarify whether tool calls are supported in web-based calls ?
s
You'll need to process the tools on the back end - make sure you have an exposed endpoint that it can ping with the payload
Provide the assistant config code and I will tell you if it's configured properly
p
Hey Sahil, yes you can use custom tools with web calling as well. Let me know if you any issues?
s
Hi @SlaviSavanovic @Shubham Bajaj Thanks a lot for your help! You can see below three snippets of code the first one assistant options how i am passing the tools the second is the get_weather function which is also im the same file (not hosted seperately somewhere) and third one shows vapi.on tool calls logic Let me know if this works or I need to follow different apprach const assistantOptions = { name: "Marie", firstMessage: "Hello, I'm Marie, your dedicated assistant. How can I assis you today ?", transcriber: { provider: "deepgram", model: "nova-2", language: "en-US", }, voice: { provider: "playht", voiceId: "jennifer", }, model: { provider: "openai", model: "gpt-4o-mini", messages: [ { role: "system", content:
Hello, I'm Marie, your dedicated assistant. You can ask me about weather updates!
, }, ], tools: [{ "type": "function", "function": { "name": "get_weather", "description": "Retrieves current weather for the given location.", "strict": true, "parameters": { "type": "object", "properties": { "location": { "type": "string", "description": "City and country e.g. Bogotá, Colombia" }, "units": { "type": ["string", "null"], "enum": ["celsius", "fahrenheit"], "description": "Units the temperature will be returned in." } }, "required": ["location", "units"], "additionalProperties": false } }, "async":false }] }, };
const get_weather = async ({location, units }) => { console.log(
Fetching weather for ${location} with units in ${units}...
); let temperature = units === "fahrenheit" ? "77°F" : "25°C"; let condition = "Sunny"; return { results: [ { result:
${location}'s weather today is ${temperature}, ${condition}.
, }, ], }; };
vapi.on("tool-call", async (toolCall) => { console.log("Tool call received:", toolCall); if (toolCall.name === "get_weather") { const { location, units } = toolCall.parameters; console.log(
Calling get_weather for location: ${location}, units: ${units}
); const weatherData = await get_weather({ location, units }); console.log("Responding with weather data:", weatherData); vapi.respondToToolCall(toolCall, weatherData); } });
s
@Sahil , I would create a tool on either the dashboard or api, and I would use the tool id. But you can also pass it through like this, is it working for you?
s
no it's not working actually are u sure we can pass tools like this or we need to create tools in different server and give the server url ?
s
Hey @Sahil could you please confirm if you are blocked? If yes then can you share more information.
s
Hi @Shubham Bajaj Thanks for following up. Yes, I am now able to make function calls, as I have hosted a separate backend service with the functional endpoints.