kirby
04/08/2025, 12:15 AMVapi Support Bot
04/08/2025, 12:17 AMshop_id
and customer_phone
directly from your code while having AI extract the reason
field from the conversation. Good news - this is definitely possible with Vapi tool calling!
Yes, Vapi tool calling can handle this mixed approach where some variables come directly from your code and others are extracted by AI from the conversation.
Here's how you can do this:
1. **Define your function tool with all three parameters**:
json
{
"type": "function",
"functionName": "your_function_name",
"parameters": {
"type": "object",
"properties": {
"shop_id": {
"type": "string",
"description": "The ID of the shop"
},
"customer_phone": {
"type": "string",
"description": "The customer's phone number"
},
"reason": {
"type": "string",
"description": "The reason extracted from the conversation"
}
},
"required": ["shop_id", "customer_phone", "reason"]
}
}
2. Pass your variables directly from code using assistantOverrides
with variableValues
when starting a call:
javascript
vapiInstance = vapiSDK.run({
apiKey: apiKey,
assistant: assistant,
config: config,
assistantOverrides: {
variableValues: {
shop_id: "your-shop-id-here",
customer_phone: "customer-phone-here"
}
}
});
3. Handle the tool call in your code:
```javascript
vapi.on("tool-call", async (toolCall) => {
if (toolCall.name === "your_function_name") {
// The AI will have extracted the reason from the conversation
// while shop_id and customer_phone come from your variables
const { shop_id, customer_phone, reason } = toolCall.parameters;
// Use all three parameters to call your functionVapi Support Bot
04/08/2025, 12:17 AMassistantOverrides
with variableValues
. The AI will then extract the reason
from the conversation while using your directly passed variables for shop_id
and customer_phone
.
Is there anything specific about this implementation you'd like me to explain further?
Sources:
- [Vapi documentation on dynamic variables](https://docs.vapi.ai/assistants/dynamic-variables)
- [Discord thread on passing variables to tool calls](https://discord.com/channels/1211482211119796234/1211483291191083018/threads/1315677399026765855)
- [Discord thread on handling tool calls](https://discord.com/channels/1211482211119796234/1211483291191083018/threads/1341350119957594163)kirby
04/08/2025, 12:21 AMKINGS BIG
04/08/2025, 7:28 PM