A medical assistant built with LangGraph and Langchain that provides personalized health advice based on patient records using OpenAI embeddings and FAISS vector search.
The agent demonstrates how it can prevent patients from taking contraindicated medications. For example:
- Patient: "I am Atin Sanyal. I'm having a runny nose, should I take aspirin?"
- Agent: Analyzes Atin's medical history (diabetes, hypertension, allergies) and warns against aspirin due to potential interactions with his current medications (Lisinopril, Metformin)
- OpenAI API key
- Galileo API key for logging
-
Clone the repository:
git clone <repository-url> cd patient-query
-
Install dependencies:
pip install -r requirements.txt
-
Set up environment variables: Create a
.envfile based onenv_template.txt:cp env_template.txt .env
Fill in your API keys:
OPENAI_API_KEY=your_openai_api_key_here GALILEO_PROJECT=xyz GALILEO_LOG_STREAM=abc GALILEO_API_KEY=your_galileo_key GALILEO_CONSOLE_URL=your_galileo_url
Run the healthcare agent:
python healthcare_agent.py --project PROJECT_NAME --logstream LOGSTREAM_NAMEOptional Arguments:
--project PROJECT_NAME: Override the Galileo project in .env--logstream LOGSTREAM_NAME: Override the Galileo logstream name in .env
Features of the Healthcare Agent:
- Interactive Terminal Interface: Chat directly in your terminal
- Advanced Workflow: Uses LangGraph for intelligent request routing
- Multi-Tool Integration: Combines RAG, claim approval, and prior authorization
- Intent Classification: Automatically determines what type of help you need
- Galileo Logging: Optional integration for monitoring and analytics
Extra .env options:
INDUCE_PRIOR_AUTH_ERROR=True
SIMULATE_SLOW_CLAIM_PROCESSING=TrueThe healthcare agent provides medical advice with safety features, insurance claim processing, and prior authorization capabilities.
- Run the agent with
python healthcare_agent.py --project PROJECT --logstream LOGSTREAM - Wait for initialization - embeddings and models will load
- Ask questions about symptoms, medications, claims, or prior authorization
- Review the personalized advice and any safety warnings
- "I am Atin Sanyal. I need approval for a $15,000 heart surgery due to heart disease."
- "Sarah Johnson needs medication coverage for asthma treatment costing $500."
- "Can you check if Michael Chen's imaging procedure requires prior authorization?"
- "I'm Emily Rodriguez. I have depression symptoms and need therapy coverage."
The application includes comprehensive mock data:
- Atin Sanyal: 35-year-old male with diabetes, hypertension, and allergies
- Sarah Johnson: 28-year-old female with asthma, migraines, and anxiety
- Michael Chen: 45-year-old male with heart disease and sleep apnea
- Emily Rodriguez: 32-year-old female with hypothyroidism and depression
- Common medications with contraindications and interactions
- Examples: Aspirin, Ibuprofen, Acetaminophen, Amoxicillin, etc.
- Common symptoms with causes and recommended actions
- Examples: Runny nose, fever, headache, cough
- Data Loading: On startup, creates embeddings for all patient records, medications, and symptoms
- Query Processing: Extracts patient name, symptoms, and medications from user input
- Similarity Search: Uses OpenAI embeddings and cosine similarity to find relevant information
- Contraindication Analysis: Uses OpenAI to analyze potential drug interactions
- Personalized Response: Generates tailored medical advice with safety warnings
The system follows a similar pattern to pdf_reader.py:
- PatientDataProcessor: Handles document creation, embedding generation, and similarity search
- In-Memory Storage: All embeddings and documents stored in memory for fast access
- Cosine Similarity: Uses numpy for efficient similarity calculations
- OpenAI Embeddings: Leverages text-embedding-ada-002 for semantic search
- Contraindication Detection: Automatically identifies potential drug interactions
- Medical Disclaimers: Always recommends consulting healthcare providers
- Safety Warnings: Prominent warnings for potentially dangerous combinations
- Evidence-Based: Uses established medical databases and guidelines
- Integration with mock insurance claims API
- Automatic claim submission and approval/denial responses
- Real-time benefit verification
- Prior authorization workflows
- Multi-language support
- Voice interface
- Integration with EHR systems
- Advanced symptom analysis
- Prescription refill requests
- Persistent storage for embeddings (optional)
- Initial Load Time: Creating embeddings for all documents takes ~30-60 seconds on first startup
- Memory Usage: All embeddings stored in memory for fast similarity search
- Scalability: For production use, consider persistent storage solutions
- Fork the repository
- Create a feature branch
- Make your changes
- Add tests if applicable
- Submit a pull request
This project is for educational and demonstration purposes only. Medical advice should always be obtained from qualified healthcare providers.