|
| 1 | +# VAPI Health Clinic - Complex Booking System |
| 2 | + |
| 3 | +## Overview |
| 4 | + |
| 5 | +This system provides an AI-powered voice assistant squad for VAPI Health Clinic that handles appointment scheduling, rescheduling, cancellation, and general inquiries. The assistant, **Amy** presents as a single unified assistant to callers. Internally, the system uses multiple specialized sub-agents—each representing Amy—each responsible for executing a specific workflow (Greet, Booking, Reschedule, Cancel, Transfer). Uses natural language processing to guide callers through appointment management workflows while maintaining a warm, professional, and empathetic tone. |
| 6 | + |
| 7 | +## System Architecture |
| 8 | + |
| 9 | +The system consists of three main components: |
| 10 | + |
| 11 | +1. **VAPI AI Assistants (squad members)** (`squad_config.json`) - The conversational AI squad that handles voice interactions |
| 12 | +2. **n8n Workflow** (`tools/scheduling/n8n_workflow.json`) - Backend automation that processes scheduling requests |
| 13 | +3. **cal.com API** - Calendar management system that stores and manages appointments |
| 14 | + |
| 15 | +## Important Notes |
| 16 | + |
| 17 | +- The system enforces business hours (9 AM - 5 PM) and will not book outside these times |
| 18 | +- The system uses number for booking (assumed +1 US numbers) |
| 19 | +- Doctor availability is automatically enforced based on day of week |
| 20 | +- *Rescheduling an appointment with a new Doctor isn't possible* |
| 21 | + - e.g., Booked with Dr Wang > reschedule and wan'ts Dr Chan availability > will fail |
| 22 | +- All scheduling operations require proper event type selection based on day, doctor, and consultation type |
| 23 | +- NOT Optimised for multiple booking records (ensure only 1 booking exists for rescheduling or cancellation for smooth operation) |
| 24 | +- Cal.COM bookins WILL fill up after use, sanitize unused bookings / cancel to avoid availability fill up. |
| 25 | +- Transfer calls goes to arbitrary US number (Jonas' from Talk AI) |
| 26 | +- Insurance collection details not required (added for realism) |
| 27 | + |
| 28 | +## AI Assistant (Squad): Amy |
| 29 | + |
| 30 | +Collectively, the VAPI Squad agents are designed to: |
| 31 | + |
| 32 | +- Answer patient questions and handle FAQs (extremely general, denoted in prompt) |
| 33 | +- Book, reschedule, and cancel healthcare appointments |
| 34 | +- Route callers to appropriate human staff when needed (one destination) |
| 35 | +- Maintain clinical professionalism without giving medical advice |
| 36 | + |
| 37 | +### Key Features |
| 38 | + |
| 39 | +- **Business Hours**: 9:00 AM - 5:00 PM, Sunday to Saturday (America/Los_Angeles) |
| 40 | +- **One question at a time**: Asks questions sequentially and waits for responses |
| 41 | +- **Natural conversation**: Never mentions "functions", "tools", or technical terms |
| 42 | +- **Guardrails**: Handles inappropriate questions and medical emergencies appropriately |
| 43 | + |
| 44 | +## VAPI Squad Architecture & Multi-Agent Behaviour |
| 45 | + |
| 46 | +Squad Framework (For All VAPI Health Clinic Agents) |
| 47 | + |
| 48 | +The VAPI Health Clinic assistant system operates as a multi-agent “Squad”, where each sub-assistant handles a specific operational domain. The Squad is composed of the following agents: |
| 49 | + |
| 50 | +1. **VAPI Internal Demo (Greet)** Agent – Handles introductions, intent detection, FAQs, and routes to the appropriate specialized agent. |
| 51 | + |
| 52 | +2. **VAPI Internal Demo (Booking)** Agent – Handles full booking workflow including patient intake, availability checks, and final appointment creation. |
| 53 | + |
| 54 | +3. **VAPI Internal Demo (Reschedule)** Agent – Handles appointment lookup, identity checking, availability search, and appointment movement. |
| 55 | + |
| 56 | +4. **VAPI Internal Demo (Cancel)** Agent – Handles appointment lookup, identity verification, and cancellation logic. |
| 57 | + |
| 58 | +5. **VAPI Internal Demo (Transfer)** Agent – Handles human routing: nursing, admin, billing, doctor, or reception. |
| 59 | + |
| 60 | +Each Squad agent inherits all global system rules, doctor availability, event type logic, n8n workflow behaviours, cal.com integration, and clinic guardrails from the unified system configuration. |
| 61 | + |
| 62 | +This section defines how agents coordinate, hand off, escalate, and fulfill tasks within the Squad. |
| 63 | + |
| 64 | +### Agent Handoff Logic (Silent Routing Between Agents) |
| 65 | + |
| 66 | +- All VAPI Squad agents must follow these routing rules: |
| 67 | + |
| 68 | +- Agents must **NEVER** say handoff phrases such as: |
| 69 | + |
| 70 | +“I will transfer you to…” |
| 71 | + |
| 72 | +“Let me get the booking agent…” |
| 73 | + |
| 74 | +“I’m switching you to another assistant…” |
| 75 | + |
| 76 | +- When intent is recognized, the agent must: |
| 77 | + |
| 78 | +Stop speaking immediately, and silently hand off to the correct Squad member. |
| 79 | + |
| 80 | +- Handoff occurs in the following scenarios: |
| 81 | + |
| 82 | +Intent Detected Correct Target Assistant |
| 83 | +1. Caller wants to book an appointment - **Booking Assistant** |
| 84 | +2. Caller wants to reschedule - **Reschedule Assistant** |
| 85 | +3. Caller wants to cancel - **Cancel Assistant** |
| 86 | +4. Caller wants to speak with nurse / doctor / billing / admin / reception - **Transfer Assistant** |
| 87 | +5. Caller wants general clinic info **All sub-assistant** handles |
| 88 | +6. Caller changes intent mid-flow Immediate silent transfer to the correct agent |
| 89 | + |
| 90 | +All sub-agents must return to the shared intent logic if caller attempts to redirect the conversation. |
| 91 | + |
| 92 | + |
| 93 | +## Scheduling Tools |
| 94 | + |
| 95 | +All scheduling operations are handled through five main tools that connect to the n8n workflow: |
| 96 | + |
| 97 | +### 1. `checkCalendarVAPIHealth` |
| 98 | + |
| 99 | +**Purpose**: Check available appointment slots |
| 100 | + |
| 101 | +**Parameters**: |
| 102 | +- `requestedTime` (required): Requested time in format `yyyy-mm-ddTHH:mm:ss` (e.g., `2025-07-04T11:00:00`) |
| 103 | +- `EventTypeID` (required): One of the four event type IDs |
| 104 | +- `EventTypeSlug` (required): One of the four event type slugs |
| 105 | +- `timeZone` (optional): Defaults to `America/Los_Angeles` |
| 106 | + |
| 107 | +**Logic** (from n8n workflow): |
| 108 | +- Queries cal.com API for available slots around the requested time |
| 109 | +- If exact match found → returns confirmation message |
| 110 | +- If no exact match but slots available → returns alternative times |
| 111 | +- If no slots available → expands search window (±2 hours) and retries |
| 112 | +- If still no slots → suggests alternative days |
| 113 | + |
| 114 | +### 2. `bookCalendarVAPIHealth` |
| 115 | + |
| 116 | +**Purpose**: Create a new appointment |
| 117 | + |
| 118 | +**Required Parameters**: |
| 119 | +- `firstName`, `lastName`: Patient name |
| 120 | +- `requestedTime`: Selected appointment time |
| 121 | +- `eventTypeID`, `eventTypeSlug`: Event type identifiers |
| 122 | + |
| 123 | +**Optional Parameters**: |
| 124 | +- `phone`: Patient phone number (normalized to E.164 format) |
| 125 | +- `birthDate`: Date of birth |
| 126 | +- `reason`: Reason for visit |
| 127 | +- `insuranceProvider`, `insuranceID`: Insurance information |
| 128 | + |
| 129 | +**Logic** (from n8n workflow): |
| 130 | +- Normalizes phone number to E.164 format (+1XXXXXXXXXX) |
| 131 | +- Creates booking via cal.com v2 API |
| 132 | +- Updates/creates patient record in n8n DataTable |
| 133 | +- Returns success confirmation with booking details |
| 134 | + |
| 135 | +### 3. `getCalendarVAPIHealth` |
| 136 | + |
| 137 | +**Purpose**: Retrieve existing appointment by patient details |
| 138 | + |
| 139 | +**Required Parameters**: |
| 140 | +- `phone`: Patient phone number |
| 141 | + |
| 142 | +**Optional Parameters**: |
| 143 | +- `name`: Patient name (for verification) |
| 144 | + |
| 145 | +**Logic** (from n8n workflow): |
| 146 | +- Normalizes phone number to E.164 format |
| 147 | +- Queries n8n DataTable for appointment by phone number |
| 148 | +- If found → retrieves appointment UID from cal.com |
| 149 | +- Returns appointment details (date, time, UID) |
| 150 | + |
| 151 | +### 4. `rescheduleCalendarVAPIHealth` |
| 152 | + |
| 153 | +**Purpose**: Change an existing appointment to a new time |
| 154 | + |
| 155 | +**Required Parameters**: |
| 156 | +- `bookinguid`: Unique identifier from `getCalendarVAPIHealth` |
| 157 | + |
| 158 | +**Optional Parameters**: |
| 159 | +- `start`: New start time in ISO 8601 UTC format |
| 160 | + |
| 161 | +**Logic** (from n8n workflow): |
| 162 | +- Calls cal.com v2 API to reschedule booking |
| 163 | +- Updates appointment time in n8n DataTable |
| 164 | +- Returns success confirmation with new appointment details |
| 165 | + |
| 166 | +### 5. `cancelCalendarVAPIHealth` |
| 167 | + |
| 168 | +**Purpose**: Cancel an existing appointment |
| 169 | + |
| 170 | +**Required Parameters**: |
| 171 | +- `phone`: Patient phone number |
| 172 | + |
| 173 | +**Optional Parameters**: |
| 174 | +- `name`: Patient name (for verification) |
| 175 | + |
| 176 | +**Logic** (from n8n workflow): |
| 177 | +- Retrieves appointment using `getCalendarVAPIHealth` logic |
| 178 | +- Cancels booking via cal.com v2 API |
| 179 | +- Optionally clears appointment data from DataTable |
| 180 | +- Returns cancellation confirmation |
| 181 | + |
| 182 | +## Event Types & Doctor Availability |
| 183 | + |
| 184 | +The system supports 4 event types in cal.com, mapped to specific doctors and consultation types: |
| 185 | + |
| 186 | +### Event Type Mapping |
| 187 | + |
| 188 | +| Event Type ID | Event Type Slug | Doctor | Consultation Type | Available Days | |
| 189 | +|---------------|----------------|--------|-------------------|----------------| |
| 190 | +| `3954317` | `dr-chan-clinic-30-minute` | Dr. Chan | In-person | Sunday, Wednesday, Saturday | |
| 191 | +| `3954310` | `dr-wong-clinic-30-minute` | Dr. Wong | In-person | Monday, Tuesday, Thursday, Friday | |
| 192 | +| `3954311` | `dr-chan-telehealth-30-minute` | Dr. Chan | Telehealth | Sunday, Wednesday, Saturday | |
| 193 | +| `3954306` | `dr-wong-telehealth-30-minute` | Dr. Wong | Telehealth | Monday, Tuesday, Thursday, Friday | |
| 194 | + |
| 195 | +### Doctor Availability |
| 196 | + |
| 197 | +**Dr. Chan** |
| 198 | +- Days: Sunday, Wednesday, Saturday |
| 199 | +- Hours: 9:00 AM - 5:00 PM |
| 200 | +- Timezone: America/Los_Angeles |
| 201 | + |
| 202 | +**Dr. Wong** |
| 203 | +- Days: Monday, Tuesday, Thursday, Friday |
| 204 | +- Hours: 9:00 AM - 5:00 PM |
| 205 | +- Timezone: America/Los_Angeles |
| 206 | + |
| 207 | +### Event Type Selection Logic |
| 208 | + |
| 209 | +The AI assistant automatically selects the correct event type based on: |
| 210 | +1. **Consultation type** (in-person vs telehealth) |
| 211 | +2. **Requested day of week** |
| 212 | +3. **Doctor preference** (if specified) |
| 213 | + |
| 214 | +Example: |
| 215 | +- Caller requests: "Telehealth appointment on Monday" |
| 216 | +- System selects: `3954306` / `dr-wong-telehealth-30-minute` (Dr. Wong, Telehealth, Monday) |
| 217 | + |
| 218 | +## n8n Workflow Logic |
| 219 | + |
| 220 | +The n8n workflow (`tools/scheduling/n8n_workflow.json`) handles all backend processing: |
| 221 | + |
| 222 | +### Webhook Endpoint |
| 223 | +- **URL**: `https://vapiai.app.n8n.cloud/webhook/calendar-book12` |
| 224 | +- **Method**: POST |
| 225 | +- Receives tool calls from VAPI AI assistant |
| 226 | + |
| 227 | +### Workflow Steps |
| 228 | + |
| 229 | +1. **Request Validation** |
| 230 | + - Validates incoming webhook is a tool-call request |
| 231 | + - Routes to appropriate handler based on tool name |
| 232 | + |
| 233 | +2. **Tool Routing (Switch Node)** |
| 234 | + - Routes to different flows based on tool name: |
| 235 | + - `checkCalendarVAPIHealth` → Availability checking flow |
| 236 | + - `bookCalendarVAPIHealth` → Booking flow |
| 237 | + - `getCalendarVAPIHealth` → Retrieval flow |
| 238 | + - `cancelCalendarVAPIHealth` → Cancellation flow |
| 239 | + - `rescheduleCalendarVAPIHealth` → Rescheduling flow |
| 240 | + |
| 241 | +3. **Phone Number Normalization** |
| 242 | + - Converts various phone formats to E.164 (+1XXXXXXXXXX) |
| 243 | + - Handles US numbers (10 digits) and international format (11 digits with country code) |
| 244 | + |
| 245 | +4. **DataTable Integration** |
| 246 | + - Stores patient information (name, phone, DOB, appointment UID, appointment time) |
| 247 | + - Uses phone number (E.164) as primary key |
| 248 | + - Supports upsert operations for patient records |
| 249 | + |
| 250 | +5. **cal.com API Integration** |
| 251 | + - **v1 API**: Used for checking availability (`/v1/slots`) |
| 252 | + - **v2 API**: Used for booking, rescheduling, and cancellation (`/v2/bookings`) |
| 253 | + - Handles timezone conversions (America/Los_Angeles) |
| 254 | + - Manages event type selection based on day/doctor/consultation type |
| 255 | + |
| 256 | +6. **Error Handling** |
| 257 | + - Returns appropriate error messages for failed operations |
| 258 | + - Handles missing appointments gracefully |
| 259 | + - Provides fallback responses for technical issues |
| 260 | + |
| 261 | +## Conversation Flow |
| 262 | + |
| 263 | +### Booking Flow |
| 264 | + |
| 265 | +1. **Intent Detection**: Caller expresses desire to book appointment |
| 266 | +2. **Information Collection**: VAPI Internal Demo (Booking) Amy collects: |
| 267 | + - First name, last name |
| 268 | + - Date of birth |
| 269 | + - Phone number |
| 270 | + - Reason for visit |
| 271 | + - Insurance information (optional) |
| 272 | + - Consultation type (in-person/telehealth) |
| 273 | + - Preferred time/day |
| 274 | + - Doctor preference (optional) |
| 275 | +3. **Availability Check**: Calls `checkCalendarVAPIHealth` with appropriate event type |
| 276 | +4. **Slot Selection**: Presents 2-4 available options to caller |
| 277 | +5. **Confirmation**: Confirms appointment details |
| 278 | +6. **Booking**: Calls `bookCalendarVAPIHealth` to create appointment |
| 279 | +7. **Confirmation**: Provides booking confirmation with details |
| 280 | + |
| 281 | +### Rescheduling Flow |
| 282 | + |
| 283 | +1. **Appointment Retrieval**: Uses `getCalendarVAPIHealth` to find existing appointment |
| 284 | +2. **Verification**: Confirms appointment details with caller |
| 285 | +3. **New Time Collection**: Asks for preferred new time |
| 286 | +4. **Availability Check**: Checks availability for new time |
| 287 | +5. **Rescheduling**: Calls `rescheduleCalendarVAPIHealth` with booking UID |
| 288 | +6. **Confirmation**: Confirms new appointment time |
| 289 | + |
| 290 | +### Cancellation Flow |
| 291 | + |
| 292 | +1. **Appointment Retrieval**: Uses `getCalendarVAPIHealth` to find appointment |
| 293 | +2. **Verification**: Confirms appointment to cancel |
| 294 | +3. **Cancellation**: Calls `cancelCalendarVAPIHealth` |
| 295 | +4. **Rebooking Offer**: Optionally offers to book new appointment |
| 296 | + |
| 297 | +## Data Storage |
| 298 | + |
| 299 | +Patient and appointment data is stored in: |
| 300 | +- **cal.com**: Primary source of truth for appointments |
| 301 | +- **n8n DataTable**: Patient records with appointment references |
| 302 | + - Fields: `first_name`, `last_name`, `phone`, `dob`, `appointment_uid`, `appointment_time` |
| 303 | + |
| 304 | +## Timezone Handling |
| 305 | + |
| 306 | +- All appointments are managed in **America/Los_Angeles** timezone |
| 307 | +- The system converts between UTC (for API calls) and Pacific Time (for user communication) |
| 308 | +- Business hours are enforced: 9:00 AM - 5:00 PM Pacific Time |
| 309 | + |
| 310 | +## Error Handling |
| 311 | + |
| 312 | +The system handles various error scenarios: |
| 313 | + |
| 314 | +- **No appointment found**: Offers to book new appointment |
| 315 | +- **Time slot unavailable**: Suggests alternative times |
| 316 | +- **Technical errors**: Provides user-friendly error messages and fallback options |
| 317 | +- **Invalid phone numbers**: Normalizes or requests clarification |
| 318 | + |
| 319 | +## Security & Privacy |
| 320 | + |
| 321 | +- Phone numbers are normalized and stored in E.164 format |
| 322 | +- Patient data is stored securely in n8n DataTable |
| 323 | +- All API communications use secure HTTPS endpoints |
| 324 | +- HIPAA compliance considerations are built into the system design |
| 325 | + |
| 326 | +## Configuration Files |
| 327 | + |
| 328 | +- `squad_config.json`: VAPI AI assistant (squad) configuration with system prompt |
| 329 | +- `tools/scheduling/n8n_workflow.json`: n8n workflow definition |
| 330 | +- `tools/scheduling/*.json`: Individual tool definitions for VAPI |
| 331 | + |
| 332 | +## Core Guardrails (Identical Across All Squad Agents) |
| 333 | + |
| 334 | +All agents must enforce: |
| 335 | + |
| 336 | +- Never say “tool”, “function”, “API”, or technical references. |
| 337 | +- Never expose backend processes. |
| 338 | +- Never speak during handoff. |
| 339 | +- Always ask one question at a time. |
| 340 | +- Respect “—” and “…” as silent pauses only. |
| 341 | +- Only repeat details when caller explicitly requests repetition. |
| 342 | +- No personal opinions, no speculation. |
| 343 | +- Never cancel, reschedule, or modify appointments without explicit caller confirmation. |
| 344 | +- Follow business hours rule at all times. |
| 345 | +- Maintain consistent warm professional tone across all agents. |
| 346 | +- When switching assistant: stop speaking, do not say any handoff wording, and immediately continue the call under the new workflow context. |
0 commit comments