CoolFace
Apppublic

kuldeepmishra76/medicare-receptionist-voice-agent

sourceHugging Facemitupdated 3mo agoView on Hugging Face
0likes
App README

๐Ÿฅ Multi-Doctor Voice Appointment Scheduling Agent

An intelligent, multi-doctor hospital voice receptionist agent that handles appointment booking, rescheduling, cancellation, and general medical inquiries through natural voice conversations.


๐Ÿ–ผ๏ธ Preview & Dashboard Screenshots

๐Ÿ–ฅ๏ธ Admin Dashboard Overview๐ŸŽ™๏ธ Interactive Voice Simulator
Admin DashboardVoice Simulator

๐ŸŒŸ Key Features

  • โ€”โšก Hybrid Ultra-Fast Pipeline: Uses a 0ms Latency Deterministic State Engine for standard booking steps & specialty inquiries, with automatic fallback to Groq LLM (`llama-3.1-8b-instant`) for complex off-script questions.
  • โ€”๐ŸŽ™๏ธ Voice Integration: Supports Vapi AI Webhooks, ElevenLabs Scribe STT / Whisper, and ElevenLabs TTS for voice generation.
  • โ€”๐Ÿค– LangGraph Agent Workflow: State-machine orchestration using LangGraph with LangChain tools for real database querying and conflict validation.
  • โ€”๐Ÿ—“๏ธ Smart Conflict Validation Engine: Prevents duplicate bookings, doctor overlaps, patient overlaps, and validates doctor working hours, working days, and leave dates.
  • โ€”๐Ÿ“… Google Calendar Sync: Automatically creates, updates, or deletes events on Google Calendar for booked appointments (with smart mock mode fallback).
  • โ€”๐Ÿ“ฑ Multi-Channel Notifications: Sends confirmation, reschedule, and cancellation alerts via Twilio SMS, Twilio WhatsApp, and Resend HTML Email.
  • โ€”๐Ÿ–ฅ๏ธ Interactive Admin Dashboard & Voice Simulator: Web dashboard (/dashboard) featuring real-time metrics, appointment management, doctor management, patient directory, and a built-in voice call testing environment with Web Speech API support.

๐Ÿ—๏ธ Architecture & Voice Pipeline Flow

                               โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
                               โ”‚       User Voice Input          โ”‚
                               โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜
                                                โ”‚
                                                โ–ผ
                               โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
                               โ”‚  ElevenLabs Scribe STT / Vapi   โ”‚
                               โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜
                                                โ”‚
                                                โ–ผ
                               โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
                               โ”‚      Fast Voice Router          โ”‚
                               โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜
                                      โ”‚                  โ”‚
                (Standard Booking/Inquiry)              (Complex Inquiry)
                                      โ”‚                  โ”‚
                                      โ–ผ                  โ–ผ
     โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”    โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
     โ”‚ Deterministic Fast Rule Engine    โ”‚    โ”‚  LangGraph State Machine Agent    โ”‚
     โ”‚ โ€ข Instant <10ms response          โ”‚    โ”‚  โ€ข Groq llama-3.1-8b-instant      โ”‚
     โ”‚ โ€ข 0 Token Cost & Zero Latency     โ”‚    โ”‚  โ€ข Async Database Tools           โ”‚
     โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜    โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜
                      โ”‚                                        โ”‚
                      โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜
                                          โ”‚
                                          โ–ผ
                      โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
                      โ”‚ Async SQLAlchemy Database (SQLite/Pg) โ”‚
                      โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜
                                          โ”‚
                      โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ดโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
                      โ”‚                                       โ”‚
                      โ–ผ                                       โ–ผ
     โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”  โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
     โ”‚ Google Calendar API Event Sync    โ”‚  โ”‚ Multi-Channel Notifications       โ”‚
     โ”‚ (Create / Reschedule / Cancel)    โ”‚  โ”‚ (Twilio SMS, WhatsApp, Email)     โ”‚
     โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜  โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜
                                          โ”‚
                                          โ–ผ
                      โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
                      โ”‚ ElevenLabs TTS Voice Audio Output     โ”‚
                      โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜

โšก Quick Start & Installation

1. Clone Repository & Setup Environment

bash
# Clone the repository
git clone <repository-url>
cd voice-agent-for-doctor

# Create virtual environment
python -m venv venv

# Activate virtual environment
# Windows:
venv\Scripts\activate
# macOS/Linux:
source venv/bin/activate

2. Install Dependencies

bash
pip install -r requirements.txt

3. Configure Environment Variables

Create a .env file in the project root:

bash
cp .env.example .env

Edit .env and fill in your API keys (Groq, ElevenLabs, Twilio, Resend, Google Calendar, etc.).

4. Seed Database with Sample Doctors

Populate the database with initial doctors across 8 medical specializations:

bash
python scripts/seed_doctors.py

5. Run Server

bash
python run.py
# OR
uvicorn app.main:app --reload --host 0.0.0.0 --port 8000

๐Ÿ–ฅ๏ธ Accessing Interfaces


๐Ÿ“ Project Structure

voice-agent-for-doctor/
โ”œโ”€โ”€ app/
โ”‚   โ”œโ”€โ”€ main.py                    # FastAPI application entry point & static mounting
โ”‚   โ”œโ”€โ”€ config.py                  # Pydantic Settings & environment variables
โ”‚   โ”œโ”€โ”€ database.py                # Async SQLAlchemy engine & session factory
โ”‚   โ”œโ”€โ”€ models/                    # ORM Models (Patient, Doctor, DoctorLeave, Appointment)
โ”‚   โ”œโ”€โ”€ schemas/                   # Pydantic Schemas for API validation
โ”‚   โ”œโ”€โ”€ agents/                    # LangGraph workflow, nodes, tools, and shared state
โ”‚   โ”‚   โ”œโ”€โ”€ graph.py               # StateGraph workflow router definition
โ”‚   โ”‚   โ”œโ”€โ”€ nodes.py               # Node functions with LLM fallback
โ”‚   โ”‚   โ”œโ”€โ”€ state.py               # AgentState TypedDict definition
โ”‚   โ”‚   โ””โ”€โ”€ tools.py               # Async DB tools for LangGraph agent
โ”‚   โ”œโ”€โ”€ api/routes/                # REST API Routers
โ”‚   โ”‚   โ”œโ”€โ”€ auth.py                # Admin security middleware
โ”‚   โ”‚   โ”œโ”€โ”€ patients.py            # Patient CRUD & phone/code lookup
โ”‚   โ”‚   โ”œโ”€โ”€ doctors.py             # Doctor profile & availability slot generation
โ”‚   โ”‚   โ”œโ”€โ”€ appointments.py       # Appointment booking & conflict validation
โ”‚   โ”‚   โ””โ”€โ”€ voice.py               # Vapi AI webhook & voice simulator routes
โ”‚   โ””โ”€โ”€ services/                  # Core Business Logic Layer
โ”‚       โ”œโ”€โ”€ appointment_service.py # Conflict validation & booking logic
โ”‚       โ”œโ”€โ”€ doctor_service.py      # Doctor availability, shift hours & leave
โ”‚       โ”œโ”€โ”€ patient_service.py     # Patient registration & phone normalization
โ”‚       โ”œโ”€โ”€ calendar_service.py   # Google Calendar API sync
โ”‚       โ”œโ”€โ”€ elevenlabs_service.py # ElevenLabs TTS & STT integration
โ”‚       โ””โ”€โ”€ notification_service.py# SMS (Twilio), WhatsApp, & Email delivery
โ”œโ”€โ”€ frontend/                      # Web Admin Dashboard & Simulator UI
โ”‚   โ”œโ”€โ”€ index.html                 # Single page app layout with Dark/Light theme
โ”‚   โ”œโ”€โ”€ app.js                     # Dynamic fetcher & Web Speech API integration
โ”‚   โ””โ”€โ”€ styles.css                 # Modern CSS design system
โ”œโ”€โ”€ scripts/
โ”‚   โ””โ”€โ”€ seed_doctors.py            # Script to seed initial sample doctors
โ”œโ”€โ”€ tests/
โ”‚   โ””โ”€โ”€ test_agents.py             # Pytest suite for symptom mapping logic
โ”œโ”€โ”€ run.py                         # Application runner
โ”œโ”€โ”€ requirements.txt               # Project dependencies
โ”œโ”€โ”€ .env.example                   # Environment configuration template
โ””โ”€โ”€ README.md                      # Documentation

๐Ÿ”‘ Environment Configuration (.env)

KeyPurposeRequired?
GROQ_API_KEYGroq LLM API key (llama-3.1-8b-instant)Recommended
ELEVENLABS_API_KEYElevenLabs Text-to-Speech & Speech-to-TextOptional (mock fallback)
ELEVENLABS_VOICE_IDVoice ID (Defaults to Sarah voice)Optional
TWILIO_ACCOUNT_SID / TWILIO_AUTH_TOKENTwilio SMS & WhatsApp notificationsOptional (mock fallback)
RESEND_API_KEYResend API for HTML Email confirmationOptional (mock fallback)
GOOGLE_CLIENT_ID / GOOGLE_CLIENT_SECRETGoogle Calendar event syncOptional (mock fallback)
ADMIN_API_KEYAdmin API header key (X-Admin-Key)Optional

๐Ÿงช Running Tests

Run the test suite using pytest:

bash
pytest tests/ -v

๐Ÿ“œ License

MIT License. Developed for intelligent automated medical receptionist and voice appointment scheduling systems.