How do I send persistent, structured call data thr...
# support
a
I've had one challenge that has persisted for a long time now. I simply want to send custom structured data to the call during the assistant-request. Nothing I try works. The agent cannot see any variable data that I send and I am forced to use a tool call which is very clunky for structured data that should be consistent throughout the duration of the call. How can i simply send a json object that the agent can actually see and use during the assistant request? (i've tried customData, messages, standalone json objects, etc.). BTW customData was recommended by the ChatGPT VAPI assistant multiple times and it is not supported when it is included in the request. To clarify: I can send a tool call and the assistant can read it great, but I have to produce that same data every single time the tool gets called. This wastes resources, bandwidth, and clutters up the communications. I want to send my assistant real-time data that is good for the entire duration of the call. Not a single variable, but knowledge it can use easily. I seem to be able to send something that might be accessible here and there, but I always have to coerce the agent, at best, to utilize the data. Hopefully you have a resolution for this, what I believe, is an extremely important topic.
Here is a very basic call where I simply ask today's date. The agent should be able to answer this without my help, but no, she gives today's date as October 30th, 2023. This makes the entire call useless for my purposes. So, one object I have tried many ways to send is answers to what this question is so I'm not taking chances. Here is the callid so you can hear the recording: 73e02233-8071-48dd-a6c6-245c4c805018. I can send this data (or similar data since I've done many iterations of this now) in a single tool call and I get that to work great. The problem: she calls it again and again and again for data that doesn't change regardless of what I say in the prompt.
Here is an example of JSON that I would like the agent to understand. It seems simple but the agent simply can't answer what these questions mean in a consistent manner: { "assistantId": "f4632dda-f6f8-46e2-b6d1-00a6319959e1", "assistantOverrides": { "firstMessage": "Testing Party-On", "firstMessageMode": "assistant-speaks-first" }, "variableValues": { "CurrentDayAndTime":"Thursday, March 20, 2025 12:00 AM", "TodaysDate":"Thursday, March 20, 2025", "TomorrowsDate":"Friday, March 21, 2025", "now": { "StartDate": "2025-03-20", "EndDate": "2025-03-20" }, "right now": { "StartDate": "2025-03-20", "EndDate": "2025-03-20" }, "immediately": { "StartDate": "2025-03-20", "EndDate": "2025-03-20" }, "asap": { "StartDate": "2025-03-20", "EndDate": "2025-03-20" }, "soon": { "StartDate": "2025-03-20", "EndDate": "2025-03-23" }, "real soon": { "StartDate": "2025-03-20", "EndDate": "2025-03-22" }, "today": { "StartDate": "2025-03-20", "EndDate": "2025-03-20" }, "tonight": { "StartDate": "2025-03-20", "EndDate": "2025-03-20" }, "tomorrow": { "StartDate": "2025-03-21", "EndDate": "2025-03-21" }, "this weekend": { "StartDate": "2025-03-21", "EndDate": "2025-03-23" }, "next weekend": { "StartDate": "2025-03-28", "EndDate": "2025-03-30" } } }
u
Yea, the model will return the date ita trained. So this will be wrong. I usually inject the date as a variable when I build the assistant, either via make, n8n etc. Then in the prompt reference it.
Or you can make a tool call to get the date time from your server so it knows. The llms don't have access to real time data unless you give it to them
s
@awf When initiating a call, include your structured data this way:
Copy code
javascript
{
  "assistantId": "f4632dda-f6f8-46e2-b6d1-00a6319959e1",
  "assistantOverrides": {
    "variableValues": {
      "CurrentDayAndTime": "Thursday, March 20, 2025 12:00 AM",
      "TodaysDate": "Thursday, March 20, 2025", 
      "TomorrowsDate": "Friday, March 21, 2025",
      "today_start": "2025-03-20",
      "today_end": "2025-03-20",
      "tomorrow_start": "2025-03-21",
      "tomorrow_end": "2025-03-21",
      "thisWeekend_start": "2025-03-21",
      "thisWeekend_end": "2025-03-23",
      "nextWeekend_start": "2025-03-28",
      "nextWeekend_end": "2025-03-30"
    }
  }
}
Important: As mentioned, VAPI only supports string values without line breaks in variableValues, which is why I've flattened the nested structure from your original JSON. ### Configure your assistant's system prompt to reference these values:
Copy code
You are an assistant with access to accurate date and time information.

IMPORTANT: Always use the following real-time data when discussing dates or times:
- Current date and time: {{CurrentDayAndTime}}
- Today's date: {{TodaysDate}}
- Tomorrow's date: {{TomorrowsDate}}

For date ranges, refer to the following predefined periods:
- Today: {{today_start}} to {{today_end}}
- Tomorrow: {{tomorrow_start}} to {{tomorrow_end}}
- This weekend: {{thisWeekend_start}} to {{thisWeekend_end}}
- Next weekend: {{nextWeekend_start}} to {{nextWeekend_end}}

NEVER use your training data's date information. Always refer to the provided values above.
### Implementation Steps: 1. Update your assistant's system prompt to reference these variable names using the double curly brace syntax:
{{VariableName}}
2. Create a function in your application that prepares the assistantOverrides object before each call:
Copy code
javascript
function prepareAssistantOverrides() {
  const now = new Date();
  
  // Generate all the date strings
  const currentDateTime = formatDate(now, {includeTime: true});
  const todaysDate = formatDate(now);
  
  const tomorrow = new Date(now);
  tomorrow.setDate(now.getDate() + 1);
  const tomorrowsDate = formatDate(tomorrow);
  
  // Create weekend dates
  const thisWeekendStart = getNextDayOfWeek(now, 5); // Friday
  const thisWeekendEnd = new Date(thisWeekendStart);
  thisWeekendEnd.setDate(thisWeekendStart.getDate() + 2); // Sunday
  
  const nextWeekendStart = new Date(thisWeekendStart);
  nextWeekendStart.setDate(thisWeekendStart.getDate() + 7); // Next Friday
  const nextWeekendEnd = new Date(nextWeekendStart);
  nextWeekendEnd.setDate(nextWeekendStart.getDate() + 2); // Next Sunday
  
  return {
    variableValues: {
      "CurrentDayAndTime": currentDateTime,
      "TodaysDate": todaysDate,
      "TomorrowsDate": tomorrowsDate,
      "today_start": formatDateISO(now),
      "today_end": formatDateISO(now),
      "tomorrow_start": formatDateISO(tomorrow),
      "tomorrow_end": formatDateISO(tomorrow),
      "thisWeekend_start": formatDateISO(thisWeekendStart),
      "thisWeekend_end": formatDateISO(thisWeekendEnd),
      "nextWeekend_start": formatDateISO(nextWeekendStart),
      "nextWeekend_end": formatDateISO(nextWeekendEnd)
    }
  };
}

// Helper functions
function formatDate(date, options = {}) {
  return date.toLocaleString('en-US', {
    weekday: 'long',
    month: 'long',
    day: 'numeric',
    year: 'numeric',
    ...(options.includeTime ? {
      hour: 'numeric',
      minute: 'numeric',
      hour12: true
    } : {})
  });
}

function formatDateISO(date) {
  return date.toISOString().split('T')[0];
}

function getNextDayOfWeek(date, dayOfWeek) {
  const resultDate = new Date(date);
  resultDate.setDate(date.getDate() + (7 + dayOfWeek - date.getDay()) % 7);
  return resultDate;
}
3. Make your VAPI call with these overrides:
Copy code
javascript
const response = await vapi.calls.create({
  assistantId: "your-assistant-id",
  assistantOverrides: prepareAssistantOverrides(),
  // other call parameters...
});
2 Views