A 24/7 emergency triaging phone call application that connects injured or endangered individuals with AI agents for situation assessment and guidance. The system persists caller memory across sessions and provides a real-time dashboard for monitoring active calls.
- Frontend: React + TypeScript + Mantine UI
- Backend: Node.js + Express + TypeScript
- Database: PostgreSQL with emergency call schemas
- Voice API: VAPI integration for phone calls
- AI Agents: Letta (formerly MemGPT) for persistent memory
- Real-time: WebSocket connections for dashboard updates
- Hosting: Vercel (frontend) + Railway/Render (backend)
โโโโโโโโโโโโโโโโโโโ โโโโโโโโโโโโโโโโโโโโ โโโโโโโโโโโโโโโโโโโ
โ Emergency โ โ VAPI Voice โ โ Dashboard โ
โ Caller โโโโโบโ Assistant โโโโโบโ Operators โ
โโโโโโโโโโโโโโโโโโโ โโโโโโโโโโโโโโโโโโโโ โโโโโโโโโโโโโโโโโโโ
โ โ
โผ โผ
โโโโโโโโโโโโโโโโโโโ โโโโโโโโโโโโโโโโโโโโ โโโโโโโโโโโโโโโโโโโ
โ Letta AI โโโโโบโ Backend API โโโโโบโ Real-time โ
โ Memory Agent โ โ (Node.js) โ โ WebSocket โ
โโโโโโโโโโโโโโโโโโโ โโโโโโโโโโโโโโโโโโโโ โโโโโโโโโโโโโโโโโโโ
โ
โผ
โโโโโโโโโโโโโโโโโโโโ
โ PostgreSQL โ
โ Database โ
โโโโโโโโโโโโโโโโโโโโ
- Node.js 18+ and npm
- PostgreSQL 14+
- VAPI account and API key
- Letta account and API key
# Clone the repository
git clone <repository-url>
cd emergency-triage
# Install backend dependencies
cd backend
npm install
# Install frontend dependencies
cd ../frontend
npm installCreate .env files for both backend and frontend:
Backend .env:
DATABASE_URL=postgresql://username:password@localhost:5432/emergency_triage
VAPI_API_KEY=your_vapi_api_key
VAPI_PHONE_NUMBER=your_emergency_number
LETTA_API_KEY=your_letta_api_key
JWT_SECRET=your_jwt_secret
PORT=3001
FRONTEND_URL=http://localhost:3000Frontend .env:
REACT_APP_API_BASE_URL=http://localhost:3001
REACT_APP_WS_URL=http://localhost:3001# Create PostgreSQL database
createdb emergency_triage
# Run setup and test script
npx ts-node setup-and-test.ts# Terminal 1: Start backend
cd backend
npm run dev
# Terminal 2: Start frontend
cd frontend
npm startOpen http://localhost:3000 to access the real-time emergency dashboard.
- Instant Response: < 3 second call answering
- AI Triage: Automated situation assessment
- Multi-language: English, Spanish, French support, etc
- Severity Classification: CRITICAL, HIGH, MEDIUM, LOW levels
- Real-time Transcription: Live speech-to-text processing
- Caller Profiles: Automatic identification via phone number
- Medical History: Persistent health condition tracking
- Emergency History: Previous call outcomes and patterns
- Location Data: GPS coordinates and address storage
- Risk Assessment: Dynamic risk profile calculation
- Live Call Monitoring: Active call status and transcriptions
- Emergency Alerts: Critical situation notifications
- Caller Context: Historical data and risk profiles
- Escalation Controls: Human operator handoff
- Analytics: Call volume, response times, outcomes
- Auto-escalation: Based on severity and caller history
- Human Operators: Specialized emergency response staff
- Emergency Services: Direct 911/emergency services dispatch
- Supervisor Alerts: Complex situation management
# Calls Management
POST /api/calls/initiate # Start emergency call
GET /api/calls/active # Get active calls
GET /api/calls/history # Get call history
POST /api/calls/escalate # Escalate to human operator
POST /api/calls/webhook/vapi # VAPI webhook handler
# User & Memory Management
GET /api/users/:id # Get user profile
POST /api/users # Create user profile
GET /api/users/:id/memory # Get caller memory
PUT /api/users/:id/memory # Update caller memory
# Dashboard & Analytics
GET /api/dashboard/stats # Dashboard statistics
GET /api/dashboard/active-calls # Active calls for dashboard
GET /api/dashboard/recent-calls # Recent call history// Client-side event listeners
socket.on("newCall", (call) => {
/* Handle new emergency call */
});
socket.on("callUpdate", (event) => {
/* Handle call status update */
});
socket.on("callEscalated", (data) => {
/* Handle escalation */
});
socket.on("emergencyAlert", (alert) => {
/* Handle critical alert */
});-- User profiles and caller information
users (id, phone_number, risk_profile, preferred_language, created_at)
-- Emergency call records
calls (id, user_id, emergency_type, severity_level, status, transcription, outcome, created_at)
-- Persistent caller memory
memory_records (id, user_id, memory_type, content, created_at, updated_at)
-- Escalation tracking
escalation_log (id, call_id, escalation_type, reason, created_at)
-- Emergency services dispatch
emergency_dispatch_log (id, call_id, service_type, dispatch_time, status)The system uses Letta AI agents for persistent caller memory:
// Caller memory structure
interface CallerMemory {
userId: string;
phoneNumber: string;
medicalHistory: string[];
previousEmergencies: EmergencyRecord[];
location: LocationData;
emergencyContacts: Contact[];
riskProfile: "LOW" | "MEDIUM" | "HIGH" | "CRITICAL";
lastCallSummary: string;
}- Immediate Assessment: Severity classification within 30 seconds
- Contextual Analysis: Historical pattern recognition
- Escalation Logic: Automated decision tree for human handoff
- Memory Updates: Real-time learning from each interaction
// Emergency triage assistant settings
{
"name": "Emergency Triage Assistant",
"model": "gpt-4",
"voice": "professional-calm",
"systemMessage": "Emergency triage AI with medical protocols...",
"functions": ["escalate_to_human", "dispatch_emergency_services"],
"recordingEnabled": true,
"maxDurationSeconds": 1800
}- Incoming Call: VAPI answers with emergency greeting
- Situation Assessment: Structured triage questions
- Memory Retrieval: Access caller's historical context
- AI Analysis: Severity determination and guidance
- Escalation Decision: Human/emergency services if needed
- Memory Update: Store call outcomes and learnings
- CRITICAL: Life-threatening (heart attack, stroke, severe bleeding)
- HIGH: Serious but stable (broken bones, difficulty breathing)
- MEDIUM: Concerning but manageable (moderate injury, infection)
- LOW: Minor issues (small cuts, mild symptoms)
- Critical severity assessment
- High-risk caller with concerning symptoms
- Extended call duration (>10 minutes)
- Caller becomes unresponsive
- Specific keywords ("can't breathe", "unconscious")
- Active Calls: Real-time emergency call count
- Response Times: Average time to answer and assess
- Escalation Rate: Percentage requiring human intervention
- Outcome Tracking: Call resolution and follow-up
- Risk Distribution: Caller risk profile analytics
- High call volume detection
- Extended response times
- Service availability issues
- Critical emergency patterns
- HIPAA-compliant medical information handling
- Encrypted database storage
- Secure API authentication
- Audit logging for all actions
- Override capabilities for supervisors
- Emergency service direct dispatch
- Call recording and transcription storage
- Regulatory compliance reporting
# Frontend (Vercel)
vercel --prod
# Backend (Railway)
railway login
railway deploy
# Database (Railway PostgreSQL)
railway add postgresqlEnsure all production environment variables are configured:
- Database connection strings
- API keys for VAPI and Letta
- JWT secrets and security tokens
- Emergency service integration credentials
Run the comprehensive test suite:
# Setup database and run all tests
npx ts-node setup-and-test.ts
# Individual test components
npm run test:emergency-flow
npm run test:dashboard
npm run test:escalation- Call Answer: < 3 seconds
- Initial Assessment: < 30 seconds
- Escalation: < 60 seconds for critical cases
- Memory Retrieval: < 1 second
- Database connection pooling
- WebSocket connection management
- Caching for frequent queries
- Load balancing for high call volumes
- Video call capability for visual assessment
- Integration with local emergency services
- Advanced AI diagnosis and treatment recommendations
- Mobile app for emergency contacts
- Geographic routing to local resources
- Multi-language support expansion
- Wearable device integration
- Predictive emergency analysis
For technical support or questions about the Emergency Triage System:
- Documentation: See inline code comments and API docs
- Issues: Report bugs via the issue tracker
- Emergency Protocol Questions: Consult medical professionals
- System Status: Monitor dashboard health indicators