Passing in variables fields for calls
# support
k
My function tool requires three inputs: shop_id, customer_phone, and reason. The reason field is the field that requires ai to extract info from the conversation. However the shop_id and customer_phone fields don't need ai to extract info from the conversation. Instead values for these fields are passed in as variables from my code. Is there a way to do this using vapi tool calling?
v
Hi there! 👋 I understand you're looking to pass
shop_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**:
Copy code
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:
Copy code
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 function
const result = await yourFunction(shop_id, customer_phone, reason); vapi.respondToToolCall(toolCall, result); } }); ``` According to the [Vapi documentation on dynamic variables](https://docs.vapi.ai/assistants/dynamic-variables), you can set variable values when starting a call using
assistantOverrides
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)
k
can you show me how to implement in python instead?
k
You just need to define those function parameters and add the description to those fields so that when LLM does a similarity search, it can find out these two terms are similar and pass the values according to the conversation. It's all about prompting and tool creation - nothing else.
8 Views