๐Ÿค– 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
100%
Task Completion Rate
15
Missed Appointments Identified
8
High-Risk Patients Flagged
4
Custom Clinical Tools

๐ŸŽฏ 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

load_patient(patient_id)

Retrieves a single patient record from the dataset. Always called first before any analysis. Returns all 18 fields: vitals, lab values, diagnosis, medication, and appointment history.

assess_clinical_risk(patient_data)

Uses Claude Haiku to assess risk level HIGH / MEDIUM / LOW against defined clinical thresholds.

HbA1c > 9% โ†’ HIGH
BNP > 900 pg/mL โ†’ HIGH
BNP > 400 pg/mL โ†’ MEDIUM
BP > 160 mmHg โ†’ HIGH
eGFR < 30 โ†’ HIGH
PHQ-9 > 20 โ†’ HIGH
Days since visit > 300 โ†’ HIGH
generate_care_plan(patient_data)

Generates a prioritised follow-up care plan covering immediate actions, follow-up schedule, medication review, and patient communication. Capped at 150 words for clinical usability.

get_missed_appointments(days_threshold)

Returns all patients who missed their last appointment, filtered by minimum days since last visit. Deterministic data retrieval โ€” no LLM call needed for this tool.

โš™๏ธ 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.