A comprehensive healthcare consultation platform that combines a modern ChatGPT-style interface with intelligent AI agents for medical information collection, symptom analysis, hospital search, appointment processing, and patient support throughout their healthcare journey.
- ๐ค Multi-Agent AI System: Three specialized CrewAI agents for different phases of patient care
- ๐ฌ Intelligent Chat Interface: Natural conversation flow with context-aware responses
- ๐ฅ Hospital Discovery: Automated search for nearby medical institutions using Exa.ai
- ๐ Appointment Processing: Parallel processing of hospital websites to find available slots
- ๐ฃ๏ธ Journey Support: Comfort guidance and reassurance during travel to hospital
- ๐ Data Extraction: Structured JSON output for seamless integration with other systems
- ๐ Background Processing: Non-blocking appointment scraping and data processing
- ๐จ Modern UI: Clean, responsive design with dark/light theme support
- ๏ฟฝ Mobile Responsive: Works perfectly on all device sizes
- โก Real-time Processing: Live updates and background task management
- ๐ Session Management: Persistent sessions with conversation history
- ๐ Monitoring: Comprehensive logging with W&B Weave integration
- ๐ก๏ธ Error Handling: Robust error handling and graceful fallbacks
โโโโโโโโโโโโโโโโโโโ โโโโโโโโโโโโโโโโโโโโ โโโโโโโโโโโโโโโโโโโโ
โ Chat Agent โ โ Reasoning Agent โ โ Extraction Agent โ
โ (Info Collect) โ -> โ (Symptom Analys) โ -> โ (Data Structure) โ
โโโโโโโโโโโโโโโโโโโ โโโโโโโโโโโโโโโโโโโโ โโโโโโโโโโโโโโโโโโโโ
โ โ โ
โโโโโโโโโโโโโโโโโโโโโโโโโโผโโโโโโโโโโโโโโโโโโโโโโโโโ
โ
โโโโโโโโโโโโโโโผโโโโโโโโโโโโโโ
โ Gemini 2.5 Flash โ
โ (Google AI API) โ
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
User Input -> Chat Agent -> Basic Info Complete?
โ
โโ No: Continue Collection
โ
โโ Yes: Hospital Search (Exa.ai)
โ
โโ Background: Appointment Processing
โ
โโ Reasoning Agent -> Comfort Guidance
- FastAPI Server: REST API with session management
- CrewAI Agents: Specialized AI agents for different tasks
- Playwright: Browser automation for appointment scraping
- Exa.ai Integration: Hospital and clinic discovery
- W&B Weave: AI interaction monitoring and tracing
- Node.js 18+
- Python 3.11+
- Google Gemini API Key
- W&B API Key (for monitoring)
- Exa.ai API Key (for hospital search)
git clone <repository-url>
cd PatientHero
# Install frontend dependencies
npm install
# Setup Python environment
cd crewai_agents
chmod +x setup.sh
./setup.sh
# Install Playwright browsers
conda activate patienthero-crewai
playwright installCreate .env files with your API keys:
Root .env:
GEMINI_API_KEY=your_gemini_api_key
WANDB_API_KEY=your_wandb_api_key
WANDB_PROJECT=patienthero-crewai
WANDB_ENTITY=your_wandb_entity
EXA_API_KEY=your_exa_api_keycrewai_agents/.env:
GEMINI_API_KEY=your_gemini_api_key
WANDB_API_KEY=your_wandb_api_key
WANDB_PROJECT=patienthero-crewai
WANDB_ENTITY=your_wandb_entity
EXA_API_KEY=your_exa_api_key# Terminal 1: Start the API server
python api_server.py
# Terminal 2: Start the frontend
npm run dev- Frontend: http://localhost:3000
- API Documentation: http://localhost:8000/docs
- API Health Check: http://localhost:8000
- User starts conversation with greeting
- Chat Agent activates to collect:
- Medical condition/symptoms
- ZIP code for location
- Phone number for contact
- Insurance information
- Automatic hospital search using Exa.ai
- Background appointment processing with Playwright
- Data structure extraction with confidence scoring
- Reasoning Agent analysis of symptoms and conditions
- Comfort guidance provision (2 rounds of support)
- Journey assistance with practical tips
- Framework: Next.js 14 with App Router
- Language: TypeScript
- Styling: Tailwind CSS
- UI Components: Radix UI primitives
- Icons: Lucide React
- State Management: React hooks and context
- Theme: next-themes for dark/light mode
- API Framework: FastAPI
- AI Framework: CrewAI with custom Gemini LLM
- Language Model: Google Gemini 2.5 Flash
- Browser Automation: Playwright
- Search Engine: Exa.ai API
- Monitoring: W&B Weave
- Session Storage: In-memory (production: Redis/DB)
- Package Management: npm, conda/pip
- Code Quality: ESLint, Prettier
- Type Checking: TypeScript
- API Documentation: FastAPI auto-docs
PatientHero/
โโโ app/ # Next.js 14 app directory
โ โโโ globals.css # Global styles and themes
โ โโโ layout.tsx # Root layout with providers
โ โโโ page.tsx # Main chat interface
โโโ components/ # React components
โ โโโ ui/ # Reusable UI primitives
โ โโโ providers/ # Context providers
โ โโโ medical-consultation.tsx # Main chat component
โ โโโ appointment-flow.tsx # Appointment processing UI
โ โโโ sidebar.tsx # Navigation sidebar
โ โโโ theme-toggle.tsx # Dark/light mode toggle
โโโ lib/ # Utility functions and services
โ โโโ ai-service.ts # API communication layer
โ โโโ utils.ts # Helper functions
โ โโโ hooks.ts # Custom React hooks
โโโ crewai_agents/ # AI agent system
โ โโโ main.py # Core CrewAI implementation
โ โโโ exa_helper.py # Hospital search integration
โ โโโ requirements.txt # Python dependencies
โ โโโ environment.yml # Conda environment
โ โโโ setup.sh # Automated setup script
โโโ api_server.py # FastAPI backend server
โโโ process_clinics_parallel.py # Appointment processing
โโโ docs/ # Documentation
โ โโโ DEPLOYMENT_GUIDE.md
โ โโโ PROMPT_SYSTEM.md
โ โโโ WANDB_SUMMARY.md
โโโ scripts/ # Utility scripts
POST /api/chat- Process user input through AI agentsGET /api/status/{session_id}- Get session status and patient data
POST /api/complete-flow/{session_id}- Full medical flow processingGET /api/appointments/{session_id}- Get processed appointment dataPOST /api/appointments/process- Manual appointment processing
GET /api/comfort-guidance/{session_id}- Comfort guidance roundsPOST /api/sessions/{session_id}/end- End patient session
GET /api/sessions- List active sessions (debug)GET /- API health check
interface PatientData {
session_id: string;
timestamp: string;
medical_condition?: string;
zip_code?: string;
phone_number?: string;
insurance?: string;
symptoms?: string[];
reasoning_analysis?: string;
conversation_history: ConversationEntry[];
}interface AppointmentData {
hospital_name: string;
website: string;
institution_type: string;
accepts_user_insurance: string;
appointment_availability: {
available_slots: AppointmentSlot[];
total_slots_found: number;
next_available: string;
booking_method: string;
};
}- Role: Friendly medical intake specialist
- Goal: Collect essential patient information naturally
- Behavior: One question at a time, empathetic responses
- Transition: Switches to Reasoning Agent when basic info complete
- Role: Medical reasoning specialist
- Goal: Analyze symptoms and provide preliminary guidance
- Behavior: Evidence-based analysis, follow-up questions
- Output: Detailed symptom analysis and medical reasoning
- Role: Data extraction specialist
- Goal: Structure conversation data into JSON format
- Behavior: Intelligent parsing, confidence scoring
- Output: Structured patient data with metadata
- Search scope: .org and .gov domains only
- Filters: Location-based, insurance compatibility
- Output: Structured hospital data with contact information
- Method: Parallel Playwright browser automation
- Target: Hospital booking pages and forms
- Extraction: Available time slots, booking methods
- Performance: Concurrent processing for speed
- Standardization: Consistent appointment slot formats
- Validation: Remove invalid or malformed data
- Enhancement: Add booking methods and availability status
- Agent Interactions: Every AI model call traced
- Session Tracking: Complete conversation flows
- Performance Metrics: Response times, success rates
- Error Tracking: Detailed error logs and context
- Information Collection Rate: Percentage of complete patient profiles
- Agent Transition Success: Chat -> Reasoning -> Extraction flow
- Appointment Processing: Success rate of hospital data extraction
- User Engagement: Session duration and interaction quality
- Session Isolation: Each session independent and secure
- Temporary Storage: Patient data not permanently stored
- API Security: CORS protection and request validation
- Privacy: No data sharing with external services (except AI APIs)
- Content Filtering: Gemini safety settings configured
- Error Boundaries: Graceful handling of API failures
- Input Validation: Sanitization of user inputs
- Rate Limiting: Protection against abuse
# Start both services locally
python api_server.py &
npm run dev- Frontend: Vercel, Netlify, or similar
- Backend: Railway, Render, or VPS
- Database: PostgreSQL or MongoDB for persistence
- Monitoring: W&B dashboard for production monitoring
# Build and run with Docker
docker build -t patienthero .
docker run -p 3000:3000 -p 8000:8000 patientheronpm run test # Run test suite
npm run test:watch # Watch mode
npm run lint # Code quality checkcd crewai_agents
python test_complete_flow.py # Test complete AI flow
python -m pytest tests/ # Run unit tests# Test core endpoints
curl -X POST http://localhost:8000/api/chat \
-H "Content-Type: application/json" \
-d '{"user_input": "Hi, I have a fever", "session_id": "test-123"}'
curl -X POST http://localhost:8000/api/complete-flow/test-123- Fork the repository
- Create a feature branch
- Set up development environment
- Make your changes
- Add tests if applicable
- Submit a pull request
- Frontend: ESLint + Prettier configuration
- Backend: PEP 8 Python style guide
- Commits: Conventional commit messages
- Documentation: Update README for significant changes
Important: This application is designed for educational and demonstration purposes. It should not be used as a substitute for professional medical advice, diagnosis, or treatment. Always consult with qualified healthcare providers for medical concerns.
- User Authentication: Persistent user accounts
- Database Integration: Long-term data storage
- Real Appointment Booking: Direct integration with hospital systems
- Telemedicine: Video consultation capabilities
- Multi-language: Support for multiple languages
- Mobile App: Native iOS/Android applications
- Memory Enhancement: Long-term conversation memory
- Specialized Models: Domain-specific medical AI models
- Voice Interface: Speech-to-text and text-to-speech
- Predictive Analytics: Early symptom detection
- Personalization: Adaptive responses based on user history
- EHR Systems: Electronic health record integration
- Insurance APIs: Real-time coverage verification
- Pharmacy Systems: Prescription management
- Wearable Devices: Health data integration
- Emergency Services: Direct 911/emergency routing
This project is licensed under the MIT License - see the LICENSE file for details.
- CrewAI: Multi-agent AI framework
- Google Gemini: Advanced language model capabilities
- Exa.ai: Intelligent web search for healthcare
- W&B Weave: AI application monitoring and tracing
- Radix UI: Accessible component primitives
- Playwright: Reliable browser automation
- Deployment Guide - Detailed deployment instructions
- Prompt System Documentation - AI agent prompt engineering
- W&B Integration Guide - Monitoring and analytics setup
- API Documentation - Interactive API documentation
For technical support, bug reports, or feature requests:
- Check existing Issues
- Create a new issue with detailed description
- Include environment details and error logs
- Tag with appropriate labels
Built with โค๏ธ for better healthcare accessibility โ โโโ ui/ # Reusable UI components โ โโโ providers/ # Context providers โ โโโ sidebar.tsx # Chat sidebar โ โโโ theme-toggle.tsx # Theme switcher โโโ lib/ # Utility functions โ โโโ utils.ts # Helper functions โโโ public/ # Static assets โ โโโ manifest.json # PWA manifest โโโ types/ # TypeScript type definitions
## Key Components
### Chat Interface
- **Message Display**: Shows user and AI messages with timestamps
- **Real-time Input**: Send messages with Enter key or button click
- **Typing Indicators**: Visual feedback when AI is responding
- **Message History**: Persistent chat history across sessions
### Sidebar Navigation
- **Chat List**: Organized by date (Today, Yesterday, Previous 7 days, Older)
- **New Chat**: Create new conversations
- **Search**: Filter chats by title
- **Responsive**: Collapsible on mobile devices
### Theme System
- **Dark/Light Mode**: Toggle between themes
- **System Preference**: Respects user's system theme
- **Persistent**: Theme preference saved locally
## Customization
### Styling
The app uses Tailwind CSS with a custom color system. You can modify the theme in:
- `tailwind.config.js` - Tailwind configuration
- `app/globals.css` - CSS custom properties for colors
### AI Integration
To connect to actual AI services, modify the `sendMessage` function in `app/page.tsx`:
```typescript
// Replace the simulation with actual AI API calls
const sendMessage = async () => {
// Your AI API integration here
}
All UI components are in the components/ui/ directory and are built with Radix UI primitives for accessibility and customization.
- Fork the repository
- Create a feature branch
- Make your changes
- Add tests if applicable
- Submit a pull request
This project is licensed under the MIT License - see the LICENSE file for details.
This application is designed for educational and demonstration purposes. It should not be used as a substitute for professional medical advice, diagnosis, or treatment. Always consult with qualified healthcare providers for medical concerns.
- Modern Next.js 14 + TypeScript setup
- Responsive chat interface with sidebar
- Dark/light theme toggle
- Message input with auto-resize textarea
- Chat history management
- Loading states and animations
- Settings dialog
- PWA configuration with manifest
- Modern UI components (Button, Input, Card, Avatar, etc.)
- Proper favicon and app icons
- TypeScript type safety
- Tailwind CSS styling
- Radix UI component primitives
- Med42-8B Integration: Production-ready medical AI on Fly.io
- AI Service Layer: OpenAI-compatible API for seamless integration
- Medical Specialization: Healthcare-focused prompts and responses
- Deploy Med42-8B: Run
cd fly-llm-server && ./deploy.shfor cloud deployment - User authentication
- Database integration for chat persistence
- Message export functionality
- File upload support
- Voice input/output
- Medical data integration
- Advanced settings (model parameters)
- Chat sharing and collaboration
- Analytics and usage tracking
- Multi-language support
- Plugin system for medical tools
- Integration with EHR systems
- Appointment scheduling
- Medication reminders
- Health data visualization
- Telemedicine integration
The application is production-ready with complete AI integration!
- โ Med42-8B Integration: Production-ready medical AI on Fly.io
- โ OpenAI-Compatible API: Seamless integration with standard formats
- โ Medical Specialization: Healthcare-focused system prompts
- โ Scalable Deployment: Auto-scaling GPU infrastructure on Fly.io
Production Deployment (Recommended)
cd fly-llm-server && ./deploy.sh # Deploy Med42-8B to Fly.io
npm run dev # Start the frontend| Feature | Med42-8B on Fly.io | Local Setup |
|---|---|---|
| Cost | $50-150/month (scales to $0) | Free |
| Setup Time | 15 minutes | N/A |
| Performance | Very Fast (A10 GPU) | N/A |
| Privacy | Secure Cloud | N/A |
| Maintenance | Managed | N/A |
- Deploy Med42-8B: Follow the deployment guide in
fly-llm-server/DEPLOYMENT.md - Configure environment: Update
.env.localwith your Fly.io URL - Test integration: Ensure the frontend connects to your deployed backend
- Add authentication: For user management and chat persistence
The UI is production-ready and follows modern design patterns. All core components are implemented and the application is responsive across all device sizes.