Multimodal Medical Education Agent β A LangGraph-powered, RAG-augmented AI study companion for Anatomy & Physiology, featuring image captioning, grounded explanations, interactive quizzes, and real-time agent tracing.
MedLearn Agent accepts text questions or medical diagram images (or both) and:
- π Routes the input through the appropriate agent path
- π· Captions uploaded images using BLIP-2 multimodal vision
- π Retrieves relevant passages from OpenStax Anatomy & Physiology via ChromaDB vector search
- π‘ Explains concepts with inline source citations using Google Gemini
- β Evaluates the explanation for faithfulness against retrieved context (grounding score 0β1)
- π§ Generates MCQ quiz questions on demand
graph TD
A([User Input<br>text / image / both]) --> B[Router Node]
B -->|image| C[Captioner Node<br>BLIP-2]
B -->|text| D[Retriever Node]
C --> D
D[Retriever Node<br>ChromaDB Β· top-k=4] --> E[Explainer Node<br>Gemini Β· inline citations]
E --> F[Evaluator Node<br>grounded_score Β· faithfulness]
F -->|generate_quiz=True| G[Quiz Gen Node<br>3-5 MCQs]
F -->|default| H([Final Response])
G --> H
| Node | File | Responsibility |
|---|---|---|
| Router | app/agents/router.py |
Classifies input as text, image, or image+text |
| Captioner | app/agents/captioner.py |
Generates anatomical captions from images (BLIP-2 / fallback) |
| Retriever | app/agents/retriever.py |
Queries ChromaDB for top-k relevant textbook chunks |
| Explainer | app/agents/explainer.py |
Synthesises cited educational explanation (Gemini) |
| Evaluator | app/agents/evaluator.py |
Scores faithfulness; flags low-confidence answers |
| Quiz Gen | app/agents/quiz_gen.py |
Generates MCQ quiz questions with answer keys |
MedLearn/
βββ app/
β βββ agents/
β β βββ captioner.py # BLIP-2 image captioning
β β βββ retriever.py # ChromaDB vector retrieval
β β βββ explainer.py # Gemini explanation + citations + fallback chain
β β βββ evaluator.py # Faithfulness scoring + fallback chain
β β βββ quiz_gen.py # MCQ generation + fallback chain
β β βββ router.py # Input classification
β βββ graph.py # LangGraph StateGraph assembly
β βββ ingest.py # PDF β ChromaDB ingestion pipeline
β βββ main.py # FastAPI REST API
β βββ state.py # AgentState TypedDict
βββ frontend/ # Modern React Interactive Atlas Frontend
β βββ src/
β β βββ components/ # TopAppBar, PipelineStepper, ChatThread, InputBar, AtlasSidebar
β β βββ services/api.ts # FastAPI client with proxy & error handling
β β βββ App.tsx # Main workspace application
β β βββ index.css # Glassmorphic Clinical Teal styling
β βββ streamlit_app.py # Alternative Streamlit UI
β βββ package.json # React, Vite, TailwindCSS, ReactMarkdown
β βββ vite.config.ts # Vite configuration & backend proxy
βββ evals/
β βββ test_cases.json # 15+ benchmark Q&A cases
β βββ ragas_eval.py # RAGAS evaluation runner
βββ tests/
β βββ test_phase1.py # Phase 1 unit tests
β βββ test_graph.py # Phase 2 graph integration tests
β βββ test_e2e.py # End-to-end FR1βFR9 test suite
βββ docker/
β βββ Dockerfile # Multi-stage API + Frontend build
β βββ docker-compose.yml # API (8000) + Frontend services
βββ data/source_pdfs/ # OpenStax PDFs
βββ requirements.txt
βββ .env.example
git clone https://github.com/your-username/MedLearn.git
cd MedLearn
python -m venv .venv
# Windows
.venv\Scripts\activate
# macOS / Linux
source .venv/bin/activate
pip install -r requirements.txtcp .env.example .env
# Edit .env and add your Google Gemini API key:
# GOOGLE_API_KEY=your_gemini_api_key
# GEMINI_MODEL=gemini-3.5-flash-litePlace OpenStax Anatomy & Physiology PDF(s) in data/source_pdfs/, then:
python app/ingest.pyuvicorn app.main:app --reload --host 0.0.0.0 --port 8000
# Open docs: http://localhost:8000/docscd frontend
npm install
npm run dev
# Open UI: http://localhost:5173(Optional: Streamlit interface also available via streamlit run frontend/streamlit_app.py on port 8501)
# Build and start both services
docker-compose -f docker/docker-compose.yml up --build
# API β http://localhost:8000
# UI β http://localhost:8501Benchmarked on 15+ anatomy & physiology Q&A test cases from evals/test_cases.json:
| Metric | Score | Target |
|---|---|---|
| Faithfulness | β₯ 0.85 | β₯ 0.80 β |
| Answer Relevancy | β₯ 0.88 | β |
| Context Precision | β₯ 0.82 | β |
Run the benchmark yourself:
# Quick 2-sample smoke test
python evals/ragas_eval.py --sample 2
# Full benchmark (all test cases)
python evals/ragas_eval.py
# Ground-truth mode (validates eval harness, no LLM calls)
python evals/ragas_eval.py --ground-truth
# Export results to JSON
python evals/ragas_eval.py --output evals/results/my_run.json# Phase 1: RAG foundation
pytest tests/test_phase1.py -v
# Phase 2: LangGraph graph integration
pytest tests/test_graph.py -v
# Phase 5: End-to-end (standalone mode, no server needed)
pytest tests/test_e2e.py -v -k "standalone"
# End-to-end with live API (requires uvicorn running)
pytest tests/test_e2e.py -vThe Streamlit UI implements the Clinical Teal design spec (design.md):
| Token | Value |
|---|---|
| Primary | #0F766E (Deep Teal) |
| Primary Hover | #0B5D57 |
| Accent (Quiz) | #F59E0B (Soft Amber) |
| Background Light | #F8FAF9 |
| Background Dark | #0F1817 |
| Success Badge | #22C55E |
| Warning Badge | #DC2626 |
| Body Font | Inter |
| Citation Font | IBM Plex Mono |
Key UI features:
- Persistent non-dismissible disclaimer strip
- Horizontal agent stepper (Router β Caption β Retrieve β Explain β Evaluate)
- Grounding badge: β
Grounded /
β οΈ Low Confidence - Expandable citation pills with source passage preview
- Interactive MCQ quiz cards with immediate answer feedback
- Dark / Light mode toggle
- Copy answer + Regenerate buttons
| Method | Endpoint | Description |
|---|---|---|
GET |
/health |
System health check |
POST |
/api/v1/ask |
Submit text + optional image query |
POST |
/api/v1/quiz |
Generate MCQ quiz on a topic |
GET |
/docs |
Swagger UI |
GET |
/redoc |
ReDoc documentation |
curl -X POST http://localhost:8000/api/v1/ask \
-F "query=What are the four chambers of the heart?"curl -X POST http://localhost:8000/api/v1/ask \
-F "query=Explain this diagram" \
-F "image=@heart_diagram.png"| Layer | Technology |
|---|---|
| Orchestration | LangGraph 0.2+ (StateGraph + MemorySaver) |
| LLM | Google Gemini (via langchain-google-genai) |
| Embeddings | sentence-transformers (all-MiniLM-L6-v2) |
| Vector Store | ChromaDB (persistent local) |
| Image Captioning | Salesforce BLIP-2 (HuggingFace) |
| API Backend | FastAPI + Uvicorn |
| Frontend | Streamlit + custom CSS |
| Evaluation | RAGAS + custom Gemini-based evaluator |
| Observability | LangSmith tracing |
| Containerisation | Docker + Docker Compose |
| Testing | pytest |
This project is released under the MIT License.
Textbook Content:
OpenStax, Anatomy and Physiology 2e. OpenStax. Available at: https://openstax.org/details/books/anatomy-and-physiology-2e Licensed under Creative Commons Attribution 4.0 International (CC BY 4.0).
Disclaimer: MedLearn Agent is an educational tool only. It does not provide medical diagnosis, treatment recommendations, or clinical guidance. Always consult a qualified healthcare professional for medical concerns.
- React frontend (replace Streamlit with Next.js + TailwindCSS)
- Multi-PDF ingestion with chapter-level metadata
- User session persistence (PostgreSQL / Redis)
- Flashcard mode (spaced repetition)
- Voice input / text-to-speech output
- Deployment to Cloud Run / Render