๐ค Agentic AI ยท LangChain ยท LangGraph ยท Claude Haiku ยท FastAPI
Patient Follow-Up
Agent
An agentic AI system that autonomously reviews patient records, flags clinical risk using defined medical thresholds, and generates prioritised care plans โ built with LangChain 1.x, LangGraph orchestration, and Claude Haiku.
LangChain 1.x
LangGraph
Claude Haiku
Agentic AI
ReAct Pattern
FastAPI
Python
Healthcare AI
Independent Project ยท Built and Validated Locally
100% tool call accuracy ยท 100% task completion ยท 100-patient synthetic dataset ยท 4 FastAPI REST endpoints tested
100%
Tool Call Sequence Accuracy
15
Missed Appointments Identified
8
High-Risk Patients Flagged
๐ฏ Problem Statement
Clinical teams managing chronic disease patients at scale face a consistent challenge: manually reviewing records to identify who needs urgent follow-up is time-consuming, inconsistent, and reactive. High-risk patients slip through the cracks between appointments.
This project explores how an agentic AI system can automate that triage process โ autonomously pulling patient records, assessing clinical risk against defined medical thresholds, generating prioritised care plans, and surfacing patients who have missed appointments. Built independently to deepen hands-on LangChain and agentic AI expertise, drawing on healthcare domain context from professional experience at Genpact.
๐๏ธ System Architecture
๐
CSV Dataset
100 patients
18 fields each
โ
๐ง
4 Custom Tools
load ยท assess
plan ยท missed
โ
๐ง
LangChain Agent
create_agent
LangGraph
โ
๐ค
Claude Haiku
Reasoning LLM
Anthropic API
โ
โก
FastAPI
4 REST endpoints
HTTP validated
ReAct Loop โ Reason โ Act โ Observe โ Repeat
Reason
โ
Act (call tool)
โ
Observe result
โ
Reason again
โ
Final response
Key design: The agent decides tool call order autonomously โ no hardcoded sequence. Single-agent, tool-calling only. No RAG, no vector databases, no multi-agent orchestration.
๐ง 4 Custom Clinical Tools
โ๏ธ Key Design Decisions
CHALLENGE
Token efficiency: sending full patient records to Claude Haiku for every tool call was expensive and slow at 100-patient scale.
SOLUTION
Compact key-value string format for patient records rather than JSON or prose โ preserves all clinically relevant fields while reducing token count significantly.
CHALLENGE
Evaluation without ground truth: no clinician-labeled dataset existed to validate risk assessments using standard classification metrics.
SOLUTION
Process-level metrics โ tool call sequence accuracy and task completion rate โ plus output grounding spot-checks. A deliberate, defensible design choice given the prototype constraints.
CHALLENGE
Jupyter compatibility: running a FastAPI server in a notebook blocks further cell execution in the standard server startup pattern.
SOLUTION
Background thread pattern โ server started in a daemon thread, cells continue running. Endpoints validated via direct HTTP client calls within the notebook.
CHALLENGE
Agent reliability: ensuring the LLM consistently calls tools in the correct clinical order without a hardcoded sequence.
SOLUTION
System prompt engineering โ explicit workflow in the system prompt (load โ assess โ plan โ summarise) combined with ReAct's observe-and-reason loop. Achieved 100% sequence accuracy across all test scenarios.
๐ Synthetic Dataset
100 synthetic patients across 8 chronic disease categories with 18 fields each. No real patient data was used at any stage.
100
Synthetic patients ยท 18 fields each
15
Patients with missed appointments
57
Patients overdue (>180 days)
211
Avg days since last visit
8
High-risk HF patients (BNP >900)
8
Disease categories covered
Diagnoses: Heart Failure, Type 2 Diabetes, COPD, Hypertension, CKD, Depression (PHQ-9), Hypothyroidism, Osteoarthritis.
โก FastAPI REST Endpoints
Agent exposed via 4 endpoints. Tested locally with server in a background thread, validated via direct HTTP client calls.
POST
/analyse-patient
Full analysis: load record โ assess risk โ generate care plan. Accepts patient_id.
GET
/missed-appointments
Returns all patients with missed appointments. Deterministic โ no LLM call involved.
POST
/agent-query
Open-ended clinical query routed directly to the agent for ad-hoc requests.
GET
/health
System status: agent version, patient count, missed appointment count.
๐ Results and Evaluation
Evaluation used process-level metrics and output grounding spot-checks. No clinician-labeled ground truth was available, so classification metrics were not applicable. This is a deliberate, defensible design choice for a prototype of this nature.
Tool Call Sequence Accuracy
100% โ agent called tools in the correct clinical order across all test scenarios
Task Completion Rate
100% โ all queries returned structured, grounded clinical outputs
Missed Appointments
15 patients correctly identified by the get_missed_appointments tool
High-Risk Patients
8 heart failure patients flagged with BNP > 900 pg/mL threshold
๐ก Key Technical Highlights
๐ ReAct Agent Pattern
- Agent reasons about which tool to call next based on prior observations
- No hardcoded tool call sequence โ fully autonomous orchestration
- LangGraph manages the state graph under the hood via LangChain 1.x create_agent
๐ฅ Clinical Threshold Design
- Risk thresholds based on established clinical guidelines: BNP, HbA1c, eGFR, PHQ-9
- Structured prompts constrain LLM output to HIGH/MEDIUM/LOW + factors + urgency
- Care plans capped at 150 words for real-world clinical usability
โก Token-Efficient Architecture
- Compact key-value string format for patient records reduces LLM token cost
- Deterministic tools bypass LLM entirely where no reasoning is needed
- Claude Haiku chosen for cost efficiency at 100-patient testing scale
๐งช Defensible Evaluation
- Process-level metrics used instead of classification metrics โ no fabricated precision/recall
- Output grounding spot-checks verify care plans reference actual patient data
- Limitations clearly stated: synthetic data, no clinician validation, local prototype
๐ ๏ธ Technical Stack
๐LangChain 1.x
create_agent ยท Tool orchestration
๐LangGraph
State graph ยท Agent orchestration
๐คClaude Haiku
claude-haiku-4-5 ยท Reasoning LLM
โกFastAPI ยท Uvicorn
REST API ยท ASGI server
๐Python ยท Pandas
Data processing ยท Dataset management
๐Jupyter Notebook
Development ยท Background thread testing
โ
Pydantic
Request/response validation
๐Anthropic API
Claude Haiku inference
โ ๏ธ Note: Built independently to deepen hands-on agentic AI and LangChain expertise. Uses a 100-patient synthetic dataset only โ no real patient data at any stage. Not a production deployment. Healthcare domain context drawn from professional experience at Genpact.