Skip to content

ajit-data-ai/voice-ai-agent-system

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

4 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

πŸŽ™οΈ Voice AI Agent System

Production-grade AI phone receptionist β€” answers calls, books appointments, handles emergencies, routes to staff

Node.js Retell AI Twilio Google Calendar License: MIT


"Recovered 18 missed appointments in the first month β€” the agent paid for itself on day 3." β€” Dental clinic client, New York


πŸ“ž Live Demo β€’ πŸŽ₯ Watch It Work β€’ Features β€’ Architecture β€’ Verticals β€’ Edge Cases β€’ Setup β€’ Hire Me


πŸ“ž Live Demo

🟒 Call the demo right now: +1 (XXX) XXX-XXXX

Tell Sophie you'd like to book a teeth cleaning. She'll check the calendar live, offer real time slots, confirm your details, book the appointment, and text you confirmation β€” all in under 90 seconds.

Demo agent runs 24/7. You'll receive a real SMS. No real appointment is booked at any actual clinic.


πŸŽ₯ Watch It Work

β–Ά Watch the 90-second demo

Live phone call β†’ real-time appointment booking β†’ calendar updated β†’ SMS confirmation, end to end.


πŸ”₯ What This Does

Small businesses lose an average of $126,000/year from missed calls. 85% of callers who don't reach someone won't call back.

This system deploys a 24/7 AI phone agent that:

  • Answers every call β€” even at 2am, weekends, holidays
  • Books, reschedules and cancels appointments directly into Google Calendar
  • Handles dental/medical emergencies β€” detects urgency, routes to staff instantly
  • Sends SMS confirmations automatically after every booking
  • Qualifies real estate leads and books showings without a human agent
  • Never forgets, never gets sick, never puts callers on hold

✨ Features

🧠 Intelligent Conversation Engine

  • 12 conversation flows covering every real-world scenario
  • Natural language understanding β€” handles "tomorrow afternoon", "next Monday", "sometime this week"
  • Graceful handling of angry callers, language barriers, silence, robocalls
  • Context-aware: distinguishes new vs returning patients, emergency vs routine

πŸ“… Real-Time Calendar Integration

  • Checks live availability before confirming any slot β€” zero double bookings
  • Race condition prevention β€” re-validates slot at booking moment (handles concurrent callers)
  • Supports multiple doctors/providers on separate calendars
  • Soft cancellations (events marked [CANCELLED], never deleted β€” preserves history)

πŸ“± Automated Notifications

  • Booking confirmation SMS sent instantly after scheduling
  • 24-hour and 2-hour appointment reminders
  • New patient intake form link via SMS
  • Staff alerts for emergencies and new patients

πŸ›‘οΈ Production-Grade Reliability

  • Retell webhook signature verification (rejects spoofed requests)
  • Exponential backoff on Google Calendar API rate limits
  • 8-second function timeout (prevents Retell's 10s hard cutoff)
  • Global error handler β€” server never crashes mid-call
  • unhandledRejection + uncaughtException handlers at process level

πŸ“Š Post-Call Analytics

Every call is automatically analyzed for: call_outcome β€’ patient_type β€’ caller_sentiment β€’ was_emergency β€’ unhandled_requests


πŸ—οΈ Architecture

System Overview

graph LR
    A[πŸ“± Caller dials<br/>Twilio Number] --> B[πŸŽ™οΈ Retell AI<br/>STT + LLM + TTS]
    B -->|Function Calls| C[βš™οΈ Express Webhook<br/>Signature verified]
    C --> D{Router}
    D -->|check_availability<br/>book_appointment| E[πŸ“… Google Calendar API]
    D -->|transfer_to_staff| F[πŸ“ž Twilio Voice<br/>Transfer]
    D -->|emergency| G[🚨 Staff SMS Alert]
    E --> H[πŸ“² Twilio SMS<br/>Confirmation]
    E --> I[πŸ“§ Email Backup]

    style A fill:#4F46E5,color:#fff
    style B fill:#7C3AED,color:#fff
    style C fill:#059669,color:#fff
    style E fill:#4285F4,color:#fff
    style F fill:#F22F46,color:#fff
    style G fill:#DC2626,color:#fff
    style H fill:#F22F46,color:#fff
Loading

Conversation Flow

stateDiagram-v2
    [*] --> Greeting
    Greeting --> IntentDetection: Caller speaks
    IntentDetection --> Booking: "Book appointment"
    IntentDetection --> Reschedule: "Change appointment"
    IntentDetection --> Cancel: "Cancel"
    IntentDetection --> FAQ: "Question"
    IntentDetection --> Emergency: "Pain / urgent"
    IntentDetection --> Transfer: "Speak to human"

    Booking --> CollectInfo
    CollectInfo --> CheckCalendar
    CheckCalendar --> OfferSlots: Available
    CheckCalendar --> Alternatives: Full
    OfferSlots --> ConfirmDetails
    ConfirmDetails --> BookSlot
    BookSlot --> SendSMS
    SendSMS --> [*]

    Emergency --> AssessUrgency
    AssessUrgency --> SameDayBook: Pain < 7
    AssessUrgency --> TransferUrgent: Pain β‰₯ 7
    TransferUrgent --> StaffAlert
    StaffAlert --> [*]
Loading

Layered Architecture

                    β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
                    β”‚           INCOMING CALL              β”‚
                    β”‚    (Patient dials clinic number)     β”‚
                    β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
                                   β”‚
                                   β–Ό
                    β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
                    β”‚           RETELL AI                  β”‚
                    β”‚   Voice Orchestration Layer          β”‚
                    β”‚   β€’ Speech-to-Text (STT)             β”‚
                    β”‚   β€’ LLM (GPT-4o mini)                β”‚
                    β”‚   β€’ Text-to-Speech (ElevenLabs)      β”‚
                    β”‚   β€’ ~600ms response latency          β”‚
                    β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
                                   β”‚ Function Calls (webhook)
                                   β–Ό
                    β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
                    β”‚         EXPRESS SERVER               β”‚
                    β”‚   β€’ Signature verification           β”‚
                    β”‚   β€’ Rate limiting + Helmet           β”‚
                    β”‚   β€’ 8s function timeout guard        β”‚
                    β”‚   β€’ Graceful error handling          β”‚
                    β””β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
                         β”‚         β”‚          β”‚
              β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β–Όβ”€β”€β”  β”Œβ”€β”€β”€β–Όβ”€β”€β”€β”€β”  β”Œβ”€β–Όβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
              β”‚  GOOGLE     β”‚  β”‚ TWILIO β”‚  β”‚  LOGGING   β”‚
              β”‚  CALENDAR   β”‚  β”‚  SMS   β”‚  β”‚  + ALERTS  β”‚
              β”‚             β”‚  β”‚        β”‚  β”‚            β”‚
              β”‚ β€’ Free/busy β”‚  β”‚ β€’ Book β”‚  β”‚ β€’ Winston  β”‚
              β”‚   query     β”‚  β”‚   conf β”‚  β”‚ β€’ Staff    β”‚
              β”‚ β€’ Create    β”‚  β”‚ β€’ 24hr β”‚  β”‚   SMS      β”‚
              β”‚ β€’ Update    β”‚  β”‚   rmndrβ”‚  β”‚ β€’ Health   β”‚
              β”‚ β€’ Soft del  β”‚  β”‚ β€’ Staffβ”‚  β”‚   check    β”‚
              β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜  β””β”€β”€β”€β”€β”€β”€β”€β”€β”˜  β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜

🏒 Supported Verticals

Vertical Agent Name Key Flows Status
🦷 Dental Clinics Sophie Book/Reschedule/Cancel, Emergency triage, FAQ, Insurance βœ… Production
🏠 Real Estate Alex Lead qualification, Showing scheduler, Discovery call booking βœ… Production
πŸ”§ Home Services Coming soon Emergency dispatch, Job booking, Quote requests πŸ”œ
πŸ₯ Medical Clinics Coming soon HIPAA-compliant scheduling, Referral routing πŸ”œ

🚨 Edge Cases Handled

50+ edge cases across 5 categories β€” documented in docs/EDGE-CASES.md

Booking Flow (15 cases)
  • Requested slot taken β†’ offers 3 alternatives automatically
  • Race condition (2 callers booking same slot simultaneously) β†’ pre-booking re-check
  • Booking too close to current time β†’ enforces configurable minimum advance hours
  • Holiday/closed day β†’ skipped in availability scan
  • Patient changes mind mid-booking β†’ restarts from date selection, no partial booking saved
  • Vague time preference ("afternoon") β†’ maps to 1:00 PM starting point
  • Multiple services β†’ books longest duration, notes both in calendar
Technical / API (15 cases)
  • Google Calendar 429 rate limit β†’ exponential backoff (2s, 4s, 8s)
  • OAuth token expiry β†’ auto-refresh via refresh token
  • Retell function timeout β†’ 8s guard returns graceful fallback before 10s hard limit
  • Twilio error 21610 (unsubscribed) β†’ permanent flag, no retry loop
  • Server crash during call β†’ uncaughtException logs + restarts via PM2
Caller Behavior (15 cases)
  • Complete silence β†’ 3s prompt β†’ 5s bridge β†’ 8s end call
  • Angry/frustrated caller β†’ validate β†’ empathize β†’ escalate (never argue)
  • "Are you a robot?" β†’ "I'm Sophie, the virtual receptionist!" (honest, not evasive)
  • Caller wants to book for someone else β†’ collects patient's info, not caller's
  • Robocall/spam β†’ silent end after 8s, no engagement
Emergency Scenarios (9 cases)
  • Pain 7+/10 β†’ immediate transfer (critical urgency) + staff SMS
  • Knocked-out tooth β†’ immediate transfer + ER guidance
  • Emergency after hours β†’ emergency phone number + callback logging
  • Emergency with no same-day slots β†’ first morning slot + OTC pain guidance

πŸ“ˆ Real-World Results

Metric Before AI Agent After AI Agent
Missed calls per week 22 0
New appointments (month 1) Baseline +18 recovered bookings
After-hours coverage ❌ None βœ… 24/7
Staff time on phones ~3 hrs/day ~30 min/day
Patient no-show rate Baseline -15% (SMS reminders)
ROI payback period β€” Day 3

πŸ› οΈ Tech Stack

Layer Technology Why
Voice orchestration Retell AI Lowest latency (~600ms), best calendar integrations
LLM GPT-4o mini Cost-efficient, fast, reliable function calling
TTS / Voice ElevenLabs Most natural-sounding voices
Phone numbers Twilio Industry standard, global coverage
Calendar Google Calendar API Universal β€” every clinic already uses it
Backend Node.js + Express Fast, async-first, WebSocket support
SMS Twilio Messaging Reliable delivery, detailed error codes
Date / Time date-fns + date-fns-tz Timezone-safe, no moment.js bloat
Logging Winston Structured logs, file rotation
Deployment Railway / Render / PM2 Zero-downtime, auto-restart

⚑ Quick Start

# 1. Clone
git clone https://github.com/ajit-data-ai/voice-ai-agent-system.git
cd voice-ai-agent-system

# 2. Install
npm install

# 3. Configure
cp .env.example .env
# Fill in your credentials (see docs/DEPLOYMENT.md for step-by-step)

# 4. Get Google refresh token (one-time)
node scripts/google-auth-setup.js

# 5. Run locally
npm run dev

# 6. Expose to internet (for Retell webhooks)
npx ngrok http 3000

Full deployment guide β†’ docs/DEPLOYMENT.md


πŸ“ Project Structure

voice-ai-agent-system/
β”œβ”€β”€ server.js                    ← Express server (entry point)
β”œβ”€β”€ agents/
β”‚   β”œβ”€β”€ dental/
β”‚   β”‚   └── system-prompt.txt    ← 12 conversation flows, full edge case handling
β”‚   └── real-estate/
β”‚       └── system-prompt.txt    ← Lead qualification + showing booking
β”œβ”€β”€ config/
β”‚   β”œβ”€β”€ agent-config.json        ← Retell agent config + 7 function schemas
β”‚   └── clinic-config.json       ← Per-client config template
β”œβ”€β”€ functions/
β”‚   β”œβ”€β”€ calendar.js              ← Google Calendar (check/book/reschedule/cancel)
β”‚   β”œβ”€β”€ sms.js                   ← Twilio (confirmations, reminders, alerts)
β”‚   └── appointments.js          ← Orchestration layer
β”œβ”€β”€ webhooks/
β”‚   └── retell-webhook.js        ← Webhook handler + signature verification
β”œβ”€β”€ utils/
β”‚   β”œβ”€β”€ date-helpers.js          ← Natural language date/time parsing
β”‚   └── logger.js                ← Structured logging
β”œβ”€β”€ monitoring/
β”‚   └── health-check.js          ← /health + /ping endpoints
β”œβ”€β”€ scripts/
β”‚   └── google-auth-setup.js     ← One-time OAuth token setup
└── docs/
    β”œβ”€β”€ ARCHITECTURE.md          ← System architecture, sequence diagrams, reliability patterns
    β”œβ”€β”€ DEPLOYMENT.md            ← Local β†’ production deployment guide
    └── EDGE-CASES.md            ← 50+ edge cases documented

πŸ”§ Per-Client Deployment

Each client gets their own isolated instance:

  • Dedicated Retell AI agent (cloned from vertical template)
  • Their own phone number (Twilio)
  • Connected to their Google Calendar
  • Customized prompt (name, hours, services, doctors, policies)
  • Staff notification routing

Setup time per new client: 2–4 hours β€” covered by a one-time setup fee.


πŸ§ͺ Testing

24 test scenarios covering happy path, edge cases, emergency flows, and failure modes.

cat tests/scenarios.md

No client goes live until all 24 scenarios pass.


πŸ’Ό For Hiring Clients

I build, deploy, and maintain custom AI voice agents for service businesses β€” typically dental clinics, real estate agencies, home services, medical practices, and law firms.

A typical engagement includes:

  • βœ… Custom-trained agent for your business (services, hours, providers, policies)
  • βœ… Local phone number
  • βœ… Direct Google Calendar / Calendly / Jane App integration
  • βœ… SMS confirmations + appointment reminders
  • βœ… Monthly performance report + ongoing prompt optimization
  • βœ… Staff escalation routing for emergencies + complex cases
  • βœ… Unlimited prompt updates as your business changes
  • βœ… Production monitoring + uptime SLA

🎁 Free 14-day pilot available for qualifying service businesses β€” call the live demo first, then book a discovery call.

πŸ“§ Discuss your project: your-email@domain.com Β· πŸ’Ό Upwork Β· πŸ”— LinkedIn


πŸ“„ License

MIT Β© Ajit


Built for deployment. Tested on real calls. Ready for your business.

⭐ Star this repo β€’ πŸ› Report an Issue

About

Production Voice AI Agent system - Retell AI + Google Calendar + Twilio. Dental, Real Estate & more verticals.

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors