Inspiration for MedFlow

The genesis of MedFlow lies in a severe operational bottleneck in emergency medicine:

  • Nearly 5% of emergency department (ED) patients now wait 24+ hours for a hospital bed (University of Michigan, 2024).
  • During mass casualty events, manual triage takes 60–110 minutes with only 65% accuracy under stress.

"What if AI could make these life-or-death decisions in minutes, with transparent medical ethics and zero human bias?"

With 139.8 million ED visits in 2024 and a projected 28% increase in elderly patient volume over the next decade, emergency departments desperately need intelligent automation. MedFlow was born from the belief that AI should handle the impossible: simultaneous triage of multiple critical patients with instant, ethical resource conflict resolution.


What MedFlow Does: Core Capabilities

MedFlow is a multi-agent AI system that orchestrates emergency department admissions at superhuman speed.

1. Batch Triage Intelligence

  • Simultaneously assesses unlimited patients using APACHE-like clinical scoring.
  • Evaluates vital signs, symptoms, and medical history in parallel.
  • Assigns priority levels (CRITICAL vs NON_URGENT) with survival probabilities.
  • Recommends departments, required specialists, and safe wait times.

2. Automated Conflict Resolution

  • Detects resource shortages (ICU beds, ventilators, specialists).
  • Applies medical ethics principles: "greatest good for greatest number."
  • Prioritizes patients based on clinical severity, survival probability, and time sensitivity.
  • Documents every decision with transparent medical reasoning.

3. Intelligent Resource Allocation

  • Processes patients in priority order (highest first).
  • Reserves beds, assigns least-busy staff, and allocates equipment.
  • Updates hospital state in real-time.
  • Prevents double-booking and resource conflicts.

4. Executive Summaries & Hospital State Queries

  • Executive Summaries: Generates leadership reports for rapid decision-making, tracking admitted vs. waiting patients and providing next actions for care teams.
  • Hospital State Queries: Real-time capacity monitoring. Examples: "Which ICU beds are free?", "Who are the least busy physicians?", "What's our current equipment availability?"

How MedFlow Was Built

Tech Stack:

  • Google Agent Development Kit (ADK): Multi-agent orchestration framework.
  • Gemini 2.5 Pro: Used by specialized AI agents for complex medical reasoning.
  • Gemini 2.5 Flash: Used as a Fast Query Agent for hospital state monitoring.
  • Python + Pydantic: For type-safe schemas and data validation.
  • Custom Medical Tools: Clinical scoring algorithms, resource management.

Key Implementation Decisions:

  • Batch Processing Over Sequential: Designed agents to handle entire patient arrays simultaneously for true parallel triage.
  • Separation of Concerns: Each agent has one job.
  • Context Passing: Agent outputs (e.g., {batch_triage}, {conflict_resolution}) explicitly become the next agent's input, forming a data pipeline.
  • Real-time State Management: Built an in-memory hospital state database that tracks bed status, staff workload, and equipment availability, updated atomically by resource tools.
  • Medical Ethics as Code: Conflict resolution is implemented using established triage principles.

Tools Built:

  • calculate_clinical_score(): APACHE-II inspired severity scoring.
  • check_bed_availability(): Real-time capacity queries.
  • reserve_bed(): Atomic resource locking.
  • assign_staff(): Workload-optimized staff allocation.
  • get_hospital_state(): Full system state snapshots.

Challenges Encountered & Solutions

Challenge Problem Description Solution/Learning
Agent Context Management Agents "forgot" previous decisions; the resource orchestrator couldn't see triage results. Implemented strict output_key naming and explicit context passing in agent instructions. Multi-agent systems need explicit data contracts.
Conflict Detection Logic Initial resolver only checked availability, missing cases where beds were reserved by higher-priority patients. Added reservation status tracking (available, occupied, reserved). Resolver checks both availability AND reservation status.
Race Conditions Double-booking of resources when processing multiple patients in parallel. Implemented strict sequential processing based on the allocation_order from the conflict resolver.
Speed vs. Reasoning Quality Gemini Flash was fast (1 sec) but poor medically; Gemini Pro was slower (3-4 sec) but clinically sound. Hybrid Approach: Flash for simple queries (state), Pro for critical decisions (triage, conflict resolution). Accepted 50-90 seconds, still 60x faster than humans.
Prompt Engineering for Medical Ethics Initial prompts produced ethically questionable prioritizations (e.g., always prioritizing younger patients). Embedded explicit medical ethics principles in prompts: "Apply greatest good for greatest number," "Prioritize survival probability WITH intervention."
Testing Mass Casualty Hard to validate correctness without "ground truth." Created test cases based on published mass casualty case studies. Built audit trails showing full decision reasoning for human review.

Accomplishments & Learnings

Accomplishments We're Proud Of

  1. Real-World Impact Potential: Built a production-ready system with 90% time savings over manual triage. MedFlow could process an 8-patient bus crash faster than a human could triage the first patient.
  2. Solved an "Impossible" Problem: Successfully automated resource conflict resolution, a problem requiring medical expertise, ethical reasoning, and real-time data, with transparent, auditable decision-making.
  3. Multi-Agent Architecture Mastery: Successfully implemented a 4-agent sequential pipeline, requiring deep understanding of context management and agent orchestration.
  4. Medical Ethics in Code: Translated abstract principles into concrete algorithms, ensuring the conflict resolver explains WHY each decision was made, creating accountability.

Key Learnings

  1. Multi-agent systems need explicit data contracts and careful context management.
  2. LLMs can do medical reasoning with the right scaffolding: Structured outputs (Pydantic), Tool calling, and focused Prompt Engineering.
  3. Google ADK requires discipline regarding output_key, context variables, and explicit agent instructions.

What's Next for MedFlow

Immediate Next Steps (3 months):

  1. Clinical Validation Study: Partner with EDs to compare MedFlow decisions vs. experienced triage nurses.
  2. EHR Integration: HL7 FHIR API for real-time patient data ingestion and bidirectional sync with Epic, Cerner, etc.
  3. Real-time Dashboard: Web UI for hospital administrators with live capacity monitoring and patient flow visualization.

Mid-term Goals (6-12 months):

  1. Predictive Capacity Planning: ML models to forecast ED surge times ("You'll run out of ICU beds in 2 hours") and recommend proactive staff scheduling.
  2. Inter-hospital Coordination: Multi-facility resource sharing and regional disaster response coordination.

Long-term Vision (1-3 years):

  1. Autonomous Emergency Department: Full workflow automation from admission to discharge.
  2. Global Disaster Response Network: Deploy MedFlow to humanitarian crises in partnership with organizations like the WHO and Red Cross.
  3. Continuous Learning System: Learn from outcomes to adapt scoring algorithms based on regional disease patterns.
  4. Regulatory Approval: Seek FDA 510(k) clearance as clinical decision support software and obtain HIPAA/SOC 2 compliance.

Built With

Share this project:

Updates