Live Demo · Medical Clinic AI Receptionist · by Harvey Liu

Talk to a
Medical AI Phone Agent

A live call to a production AI voice agent for a family clinic. I designed and built every layer myself, from SIP signalling and the media engine to the RAG pipeline and intent classifier. Both call paths reach the same agent, with a end-to-end response.

Choose how to call

+1 236-466-1681

Call from any phone; standard call rates apply. Your phone → Amazon Connect IVR → Amazon Lex V2 → AWS Lambda, spoken by Amazon Polly. Key 1 goes on to my AI agent; key 2 stays in a Lex bot and stores bookings in DynamoDB.

Ask for a person at any time, or press 0 to be transferred to Harvey.  ·  How do these four paths compare? →

+1 236-462-9646

Call from any phone; standard call rates apply. Your phone → Twilio Studio IVR. Key 3 goes through Twilio ConversationRelay and a WebSocket to my Python AI agent; key 4 goes to a Google Dialogflow CX agent with a knowledge base.

What you will hear: “Hello, and thank you for calling Harvey’s Clinic. This demo line is powered by Twilio. For sales, press 1. For support, press 2. To speak with Harvey’s Python AI agent, press 3. To speak with our Google Dialogflow CX agent, press 4. To speak with Harvey directly, press 0. To hear these options again, press star.”

Press 0 at the main menu to be transferred to Harvey.  ·  How do Twilio voice AI options compare? →

Your browser → Janus WebRTC → Java SIP server → VoIP media engine → Aliyun ASR/TTS → AI agent

Initializing...
Clinic AI Line

Tested on PC Chrome / Firefox / Edge · iOS Safari (iPhone / iPad)

More intents to try:

Greeting
"Hello, good morning!"
"Hey, is anyone there?"
Command
"Transfer me to a human agent."
"I want to talk to a representative."
"Can you repeat that?"
"byebye","hangup"
"I beg your pardon"
"Turn up the volume"
"Can you speak louder please"
"Turn down the volume"
"Please lower your voice"
Feedback
"That's very helpful, thank you."

Try asking (QUERY):

Hours
"What are your clinic hours?"
Walk-in
"Do you accept walk-ins?"
Prescription
"Can I get a refill over the phone?"
Sick Note
"I need a doctor's note for work."
Late
"I'm 15 minutes late for my appointment."
Referral
"Checking on my specialist referral."
Urgent
"My mother collapsed and is unconscious."
New Patient
"Can I register as a new patient?"
Implicit inheritance
1. "I'm running about 15 minutes late for my appointment."
2. "What if I can't make it at all?"
3. "How much is the cancellation fee?"
Entity Normalization
1. "I need a sick note for work."
2. "Can I get a repeat prescription?"
3. "I need to check my blood work results."
Boundary / Out of Scope
1. "What are your clinic hours?"
2. "Can you book me a flight to Toronto?"
3. "What's the weather like today?"
Urgent Fast-Track
1. "my mother has a headache. She is unconscious."
2. "My chest hurts and I can't breathe."
3. "I feel a bit dizzy."

Chitchat:

Chitchat
"How are you today?"  ·  "Tell me a joke"

Please ask me a question about the clinic knowledge base ▾

About This System

Intelligent Voice Agent for Medical Clinics

A production-grade AI phone assistant built from the ground up — custom Java SIP signalling server, VoIP media engine, Aliyun ASR/TTS, local RAG pipeline with BGE embeddings and pgvector, real-time 5-class intent classification, and sub-2s end-to-end latency. The same agent also answers calls through Amazon Connect, bridged by Amazon Lex V2 and AWS Lambda.

Python / FastAPI pgvector RAG BGE Embeddings Qwen LLM Intent Classifier Rerank Pipeline Java SIP Server VoIP Java Media Aliyun ASR / TTS Janus WebRTC gpt-4o Redis Ubuntu Docker Amazon Connect Amazon Lex V2 AWS Lambda Amazon Polly
In-house VoIP architecture diagram
Speech Polly TTS for all keys Integration EventBridge warm-up Backend Caller PSTN · mobile Amazon Connect Contact flow IVR menu · DTMF Queue human agent on TRANSFER Key 1 Key 2 Key 4 Key 5 Amazon Lex V2 speech → text turn-taking Lambda Lex adapter Python Harvey's Python AI agent FastAPI · /ai_send same agent as the In-house VoIP diagram (RAG · cache · MongoDB) HTTP Lex V2 booking bot NLU · slot filling Lambda code hook verify caller Amazon DynamoDB book · check · cancel 1 booking per patient Amazon Lex V2 speech → text Lambda Python Amazon Bedrock Flow Bedrock Knowledge Base Agentic CX block agentic voice ASR · Polly TTS Connect AI agent Agentic CX designer barge-in Q&A knowledge base small talk on Amazon Nova 2 Lite TRANSFER (keys 1 and 5) Keys 1, 2, 4: Lex V2 turns speech into text and Polly speaks the reply. Key 5: Amazon Connect agentic voice does ASR, Polly speaks. Key 1 sends the text to my own agent.

Compare the four Amazon Connect paths: Lex + Lambda, Lex booking bot, Bedrock Flow and Agentic CX →

Caller any phone Twilio Studio IVR main menu ConversationRelay Twilio ASR · TTS Twilio Connect Virtual Agent streams audio only Harvey live person Key 3 Key 4 Key 0 callai.top server · AWS EC2 nginx TLS · :443 relay_server.py :7600 Harvey's Python AI agent ai_send :6626 same agent as the In-house VoIP diagram (RAG · cache · MongoDB) WSS HTTP Google Cloud Dialogflow CX agent Google ASR · TTS · flows Knowledge base data store · clinic docs audio Key 3: Twilio does ASR and TTS; my server only handles text. Key 4: Twilio streams the call audio to Google, which does ASR, TTS and the dialog.

Compare Twilio voice AI options: Gather, ConversationRelay, Media Streams, Virtual Agent and SIP Trunking →

Key Technical Highlights

How It Works: RAG, Intent Routing and Real-Time Voice

🧠
Intent Classification
5-class intent classifier with entity normalization and category routing.
🔍
Two-Stage RAG
BGE-large embedding → pgvector ANN search → BGE-reranker cross-encoder. Fast-track for high-confidence hits. Sub-400ms retrieval.
⚡
Dynamic LLM Routing
Simple queries auto-downgrade to a faster model. Complex answers use a higher-capability model (qwen-plus or gpt-4o). Supports both Aliyun Qwen and OpenAI backends. Saves 500–800ms per turn.
📞
Custom SIP Stack
Self-developed Java SIP signalling server + VoIP media engine. WebRTC bridged via Janus gateway.
🚨
Instant Repeat Response
L1,L2 Two-tier Redis cache answers repeated and paraphrased questions instantly — exact match <5ms, semantic match <300ms, bypassing RAG.
🌐
Multilingual Ready
Same pipeline runs Chinese education (bge-zh) and English clinic (bge-en). Config-driven, no code changes.
🔄
Session Management
Multi-turn conversation with automatic session lifecycle. Context inherited across turns — caller never needs to repeat themselves. Sessions auto-expire after 30 minutes.
☁️
Amazon Connect Integration
Lex V2 handles speech only; every utterance goes through a Lambda adapter to the same agent, which decides intent and when to hand off. Multi-turn stays inside Lex, with silence handling, retry on backend timeout, and transfer to a live queue.
🏗️
Full-Stack AI Telephony System
Sole architect and developer of the AI agent layer, and deployed end-to-end on AWS EC2 — from database to browser demo.
🔌
Twilio ConversationRelay
Twilio handles speech; a Python WebSocket relay behind nginx passes text to the same agent. Handles barge-in, silence prompts, retry on backend errors, and hands control back to Studio to transfer or end the call.
🗺️
Google Dialogflow CX
A second Twilio path hands the call to a Dialogflow CX agent with a knowledge base. Twilio streams the audio; Google does speech recognition, text-to-speech and the dialog.
📅
Self-Service Booking
Lex V2 slot filling with a Python Lambda code hook. Verifies the caller once per call, then books, checks or cancels in DynamoDB, with a conditional write so each patient holds only one booking.

Compare Twilio voice AI options: Gather, ConversationRelay, Media Streams, Virtual Agent and SIP Trunking →

Compare the four Amazon Connect paths: Lex + Lambda, Lex booking bot, Bedrock Flow and Agentic CX →

Changelog

Update History

November 2026

Twilio Phone Line (Method 2, keys 3 and 4)

Added a second phone line on Twilio. A Twilio Studio IVR answers the call and routes by keypress. Key 3 uses Twilio ConversationRelay: Twilio handles speech recognition and text-to-speech, and streams each turn over a WebSocket to my Python agent, which runs the same RAG and intent backend. Key 4 uses Twilio's Connect Virtual Agent to hand the call to a Google Dialogflow CX agent with a knowledge base; Press 0 to reach me directly, or star to repeat the menu.

October 2026

Self-service Booking Line (key 2)

Added an Amazon Lex V2 bot for booking, checking and cancelling family-doctor appointments. Lex handles intent recognition and slot filling; a Python Lambda code hook reads back and verifies the caller's health number and date of birth once per call, then reads and writes DynamoDB. A conditional write enforces one appointment per patient, health numbers are masked in logs, and Lambda's IAM role can reach only that one table.

October 2026

Amazon Connect Phone Line (key 1)

The agent now also answers real phone calls at +1 236-466-1681. Amazon Connect runs the IVR menu, Lex V2 transcribes speech, and a Lambda adapter forwards each turn to the same RAG and intent backend. Includes silence handling, timeout retry, scheduled warm-up, and live-agent transfer.

June 5, 2026

L1 / L2 Redis Semantic Cache

Two-tier Redis cache intercepts repeat and paraphrased queries before RAG — exact match under 5ms, semantic match under 300ms. Includes FAQ warmup, fallback detection, and cache export tool.

Copyright & Attribution

Intellectual Property Notice

RAG Pipeline · AI Agent · Intent Classifier
Designed and developed by Harvey Liu. Originally built in Java, refactored in Python (2026).
SIP Server (Java)
Designed and developed under Harvey Liu's technical lead at LCall Technology. The compiled software is freely available for download and use. Source code is proprietary.
VoIP / PBX Media Engine (Java)
Designed and developed under Harvey Liu's technical lead at LCall Technology. Copyright © LCall Technology. Used with permission for personal portfolio demonstration and technical discussion purposes only. Not for commercial use.
WebRTC Browser Demo (JavaScript)
The browser-side SIP demo is built upon the open-source Janus Gateway demo code (janus.js, sip.js) by Meetecho s.r.l., licensed under the MIT License. Modified and integrated for portfolio demonstration purposes.