Skip to content

Latest commit

Β 

History

13 Commits

Folders and files

NameName
Last commit message
Last commit date
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

πŸ₯ MedTriage – Agentic AI Clinical Decision Support System

⚠️ PROTOTYPE ONLY β€” This is a clinical decision support prototype for research and educational purposes. It is NOT a real medical diagnostic system and must NOT be used for actual medical decisions.


Overview

An Agentic AI-powered medical triage system that orchestrates multiple specialized agents using a hybrid neuro-symbolic architecture to assess symptoms, detect emergencies, assign urgency levels, and generate structured clinical briefings β€” all running locally with Ollama.


Architecture

β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚                        Streamlit Frontend                       β”‚
β”‚   Multi-step card UI β†’ Demographics β†’ Symptoms β†’ History β†’ ...  β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
                                  β”‚ REST API
                                  β–Ό
β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚                        FastAPI Backend                          β”‚
β”‚                  /api/questions  /api/triage                    β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
                                  β”‚
                                  β–Ό
β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚                    LangGraph Workflow Engine                    β”‚
β”‚                                                                 β”‚
β”‚   β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”     β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”     β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”                β”‚
β”‚   β”‚  Intake  │────▢│  Critic  │────▢│  Triage β”‚                β”‚
β”‚   β”‚  Agent   β”‚     β”‚  Agent   β”‚     β”‚  Agent   β”‚                β”‚
β”‚   β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜β—€β”€β”€β”€β”€β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜     β””β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”˜               β”‚
β”‚       β–²  (reflection loop)               β”‚                      β”‚
β”‚       β”‚                                  β–Ό                      β”‚
β”‚   β”Œβ”€β”€β”€β”΄β”€β”€β”€β”€β”€β”€β”                    β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”              β”‚
β”‚   β”‚Escalationβ”‚                    β”‚  Synthesis   β”‚              β”‚
β”‚   β”‚ Handler  β”‚                    β”‚    Agent     β”‚              β”‚
β”‚   β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜                    β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜              β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
                                  β”‚
                                  β–Ό
β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚                    Ollama (Local LLM)                           β”‚
β”‚                  llama3.2 (or any model)                        β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜

🧠 Agentic AI Architecture

This system implements a true multi-agent architecture where independent agents operate with defined roles, shared state, and iterative routing.

Each agent:

  • Operates autonomously within its responsibility boundary
  • Communicates via structured Pydantic state objects
  • Participates in a controlled LangGraph workflow
  • Can trigger routing changes (e.g., escalation, reflection loop)

This design mirrors real-world clinical workflow systems rather than simple prompt-based chatbots.

Agent Roles

Agent Role
Intake Agent Parses demographics, detects red flags via keyword scan, uses LLM to extract structured symptom details
Critic Agent Reviews intake for clinical gaps, detects missed red flags via LLM, drives the reflection loop
Triage Agent Hybrid rule+LLM urgency classification (EMERGENCY β†’ NON_URGENT) + department routing
Synthesis Agent Generates full structured medical briefing with differentials, workup recommendations, and clinician notes

LangGraph Flow

intake β†’ [escalation?] β†’ critic β†’ [approved?] β†’ triage β†’ synthesis β†’ END
              ↑               └── [rejected, loop back] β”€β”€β”˜
              └── (red flags β†’ fast-path EMERGENCY)

Project Structure

medical_triage/
β”œβ”€β”€ main.py                          # API server entrypoint
β”œβ”€β”€ requirements.txt
β”œβ”€β”€ .env.example
β”‚
β”œβ”€β”€ config/
β”‚   β”œβ”€β”€ __init__.py
β”‚   └── settings.py                  # All config, red flags, symptom tree
β”‚
β”œβ”€β”€ backend/
β”‚   β”œβ”€β”€ __init__.py
β”‚   β”œβ”€β”€ agents/
β”‚   β”‚   β”œβ”€β”€ intake_agent.py          # Patient intake + red flag detection
β”‚   β”‚   β”œβ”€β”€ critic_agent.py          # Quality review + reflection loop
β”‚   β”‚   β”œβ”€β”€ triage_agent.py          # Urgency + department classification
β”‚   β”‚   └── synthesis_agent.py       # Clinical briefing generation
β”‚   β”œβ”€β”€ graph/
β”‚   β”‚   └── workflow.py              # LangGraph StateGraph orchestration
β”‚   β”œβ”€β”€ models/
β”‚   β”‚   └── schemas.py               # All Pydantic data models
β”‚   β”œβ”€β”€ api/
β”‚   β”‚   └── server.py                # FastAPI endpoints
β”‚   └── utils/
β”‚       β”œβ”€β”€ logger.py                # Structured logging
β”‚       └── ollama_client.py         # Ollama REST client
β”‚
└── frontend/
    └── app.py                       # Streamlit multi-step card UI

Setup & Installation

Prerequisites

  • Python 3.11+
  • Ollama installed and running
  • 8GB+ RAM recommended

Step 1 β€” Clone & Install

git clone https://github.com/bharath2957s/MedTriage-Agentic-AI
cd medical_triage

python -m venv venv
source venv/bin/activate        # Windows: venv\Scripts\activate

pip install -r requirements.txt

Step 2 β€” Set Up Ollama

# Install Ollama from https://ollama.ai
# Then pull the model:
ollama pull llama3.2

# Start Ollama server (if not already running):
ollama serve

Step 3 β€” Configure Environment

cp .env.example .env
# Edit .env to change model name, ports, etc. if needed

Step 4 β€” Run the API Server

# From project root:
python main.py

# Or with uvicorn directly:
uvicorn backend.api.server:app --host 0.0.0.0 --port 8000 --reload

Verify: Open http://localhost:8000/docs

Step 5 β€” Run the Streamlit Frontend

# In a new terminal, from project root:
streamlit run frontend/app.py --server.port 8501

Open: http://localhost:8501


How to Use

  1. Demographics β€” Enter patient age, sex, and chief complaint
  2. Symptoms β€” Answer dynamically generated follow-up questions
  3. History β€” Enter past medical history, medications, and allergies
  4. Analysis β€” Watch the AI agents process the case in real-time
  5. Results β€” View triage urgency, department routing, and clinical briefing

The Doctor Dashboard tab provides the full structured clinical report including differentials, recommended workup, and clinician notes β€” downloadable as JSON.


Testing Without Ollama

If Ollama is not running, the system gracefully falls back to the /api/demo endpoint, which returns a realistic pre-built cardiac emergency example for UI testing.


Configuration Options

Variable Default Description
OLLAMA_MODEL llama3.2 Any Ollama-compatible model
OLLAMA_TEMP 0.3 Lower = more deterministic
MAX_CRITIC_ITERATIONS 2 Reflection loop depth
API_PORT 8000 Backend API port
DEBUG false Enable hot reload

Recommended models (in order of quality/speed):

  • llama3.2 β€” Fast, good quality (recommended)
  • llama3.1:8b β€” Slightly slower, higher quality
  • mistral β€” Alternative good option
  • phi3 β€” Fastest, lighter quality

Pydantic Data Models

Model Purpose
IntakeState Full patient session state passed through the graph
TriageDecision Urgency level + department + rationale + confidence
MedicalSummary Complete final briefing with all agent outputs
CriticFeedback Critique results from the reflection loop
SymptomDetail Structured individual symptom with severity/duration

Emergency Escalation Logic

The system uses a two-layer neuro-symbolic emergency detection architecture:

  1. Deterministic Pattern-Based Rule Engine (Clinical Rule Layer) β€” Structured, normalized pattern matching for life-threatening presentations (e.g., crushing chest pain, stroke symptoms, uncontrolled bleeding, respiratory failure, suicidal intent). Triggers immediate escalation without relying on LLM output.
  2. LLM Contextual Detection (Critic + Triage Agents) β€” Identifies subtle, progressive, or context-dependent red flags not explicitly captured by deterministic patterns (e.g., concerning severity progression, high-risk comorbidities, neurologic warning signs).

When escalation triggers:

  • LLM reasoning is bypassed (deterministic fast path)
  • Triage Agent returns EMERGENCY immediately
  • Emergency department routing is enforced
  • High-priority actions are generated automatically
  • A prominent emergency alert is displayed in the frontend.

API Reference

Endpoint Method Description
/health GET Health check
/api/questions POST Get dynamic symptom questions
/api/triage POST Run full triage workflow
/api/demo GET Demo result (no LLM needed)
/docs GET Interactive Swagger UI

Disclaimer

This system is a research prototype demonstrating multi-agent AI orchestration patterns. It:

  • Does NOT replace professional medical judgment
  • Should NOT be used for real medical decisions
  • Has NOT been validated clinically
  • Is intended for educational and research purposes only

Always consult a licensed healthcare professional for medical concerns.

About

Agentic AI clinical triage system combining deterministic medical safety rules with transformer-based LLM reasoning using a multi-agent workflow architecture.

Topics

Resources

Stars

2 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages