-
-
AEGIS Perioperative Copilot- assisted perioperative intelligence for safer surgical decisions
-
Why Surgery Gets Delayed or Cancelled Real clinical gaps, missed risks, and preventable complications
-
What AEGIS Detects in Seconds Risk scoring, safety flags, optimization gaps, and decision support
-
Inside the AEGIS Multi-Agent System FHIR integration, MCP tools, AI orchestration, and safety ratchets
-
AEGIS in Real Clinical Workflow Structured perioperative assessment with actionable recommendations
AEGIS PERIOPERATIVE COPILOT
Project: Aegis Perioperative Copilot
Hackathon: PromptOpinion Agents Assemble Hackathon
Submitted by: Dr. Bhavna Gupta
The AI copilot that turns unstructured preoperative data into a
structured, evidence-based triage decision — in under 30 seconds.
INSPIRATION
Perioperative assessment is one of the most critical yet consistently
underserved moments in surgical care. Before every operation, an
anesthesiologist must synthesize a patient's laboratory results,
airway anatomy, comorbidity burden, medication risks, and surgical
urgency — often in 15 minutes or less, often without a complete
clinical picture, and always under institutional pressure to proceed.
The consequences of this cognitive overload are real and measurable:
Same-day surgical cancellations cost Indian hospitals ₹12,000 to
₹40,000 per theatre slot, with preventable causes accounting for
a significant proportion.Missed hyperkalemia before induction has caused fatal cardiac
arrhythmias. Unrecognised difficult airways have led to
cannot-intubate-cannot-oxygenate crises. Uncontrolled HbA1c
doubles surgical site infection rates.Junior residents and trainees routinely see complex ASA III–IV
patients in pre-operative clinics with no structured decision
support and no reliable way to know what they might have missed.
I am an Associate Professor of Anaesthesiology and Critical Care
at AIIMS Rishikesh, with 237+ publications and over a decade of
perioperative clinical experience. I built Aegis because I know
exactly what happens when preoperative assessment is rushed, fragmented,
or incomplete — and I wanted to build something that could actually
prevent it, rather than document it after the fact.
The name Aegis comes from Greek mythology — the shield of protection
carried before battle. Perioperative anaesthesia is exactly that:
anticipation, vigilance, and protection before surgery begins.
WHAT IT DOES
Aegis Perioperative Copilot is a two-agent AI system built on
PromptOpinion, powered by a FastMCP server deployed via NGROK on local server, and
FHIR R4 native from the ground up.
It accepts patient data in three formats:
- Live EHR patient data via PromptOpinion FHIR context headers
- Raw FHIR R4 bundles (transaction or collection type)
- Canonical patient JSON or natural language summary
And produces a fully structured preoperative assessment in seconds.
AGENT 1 — AEGIS SUPERVISOR (Primary Triage Engine)
Computes four validated clinical risk scores:
- RCRI — Revised Cardiac Risk Index
- STOP-BANG — OSA screening
- Apfel Score — Post-operative nausea/vomiting risk
- ASA Physical Status
Detects 15+ hardcoded clinical safety flags with specific thresholds:
K+ ≥ 6.0 mmol/L → CRITICAL_HYPERKALEMIA → POSTPONE
K+ 5.5–5.9 mmol/L → HYPERKALEMIA → OPTIMIZE
Hb < 7.0 g/dL → SEVERE_ANEMIA → POSTPONE
SBP ≥ 180 mmHg → SEVERE_HYPERTENSION → POSTPONE
HbA1c ≥ 9.5% → UNCONTROLLED_DIABETES → OPTIMIZE
Mallampati 3–4 + OSA + BMI > 40
→ PREDICTED_DIFFICULT_AIRWAY → ESCALATE
Active anticoagulant not held → ESCALATE
Metformin not held day-of-surgery → OPTIMIZE
Retrieves evidence-based guideline recommendations from:
- ESA 2022
- ASA 2022
- DAS 2025
- AIDAA 2024
- ADA 2024
- ASRA 2023
Issues a final recommendation:
PROCEED / OPTIMIZE / ESCALATE / POSTPONE
with clinical reasoning and cancellation risk estimation.
SAFETY REVIEWER
The Safety Reviewer is the architectural innovation that separates
Aegis from other clinical AI systems.
It operates on a ONE-WAY SAFETY RATCHET:
It can ONLY upgrade the Supervisor's recommendation
It can NEVER downgrade it
The Safety Reviewer independently:
- checks a 21-point clinical checklist
- performs medication cross-checks
- counts difficult airway predictors
- adds mandatory safety addendum
If the Supervisor says:
PROCEED
and the Safety Reviewer finds:
K+ 6.1
the final decision becomes:
POSTPONE
No override. No exception.
WHAT AEGIS HANDLES THAT NO OTHER TOOL DOES
- Sparse data mode
- FHIR R4 native support
- Transaction + collection bundle handling
- LOINC-coded and text-coded observations
- valueString parsing
- ServiceRequest fallback
- Unit-tested workflow
- Clinically validated thresholds
HOW I BUILT IT
ARCHITECTURE OVERVIEW
Patient Data (FHIR / JSON / prose)
↓
FastMCP Server (Python 3.11, Railway)
↓ 6 MCP Tools
PromptOpinion Agent Orchestration
↓
Agent 1: Aegis Supervisor
↓ assessment JSON
consult prompt
↓ final assessment + safety addendum
Structured Markdown Report → Clinical Team
MCP SERVER (Python 3.11 + FastMCP 3.x, deployed on Railway)
1. fetch_patient_from_fhir
Fetches live patient data via PromptOpinion FHIR context headers.
2. assess_current_patient
fetch → normalise → score
Primary entry point for live workflows.
3. normalize_fhir
FHIR R4 Bundle → canonical Aegis patient JSON.
4. compute_risk_scores
Deterministic Python scoring engine for:
- RCRI
- STOP-BANG
- Apfel
- ASA
5. fetch_guideline
Hardcoded guideline retrieval from authoritative sources.
6. format_aegis_report
Converts assessment JSON into structured markdown report.
FHIR CONTEXT INTEGRATION
The MCP server declares:
ai.promptopinion/fhir-context
during the MCP initialize handshake.
SMART scopes:
patient/Patient.rs
patient/Condition.rs
patient/Observation.rs
patient/MedicationStatement.rs
Optional scopes:
MedicationRequest
Procedure
AllergyIntolerance
KEY ENGINEERING DECISIONS
Deterministic Scoring
Risk scores are computed by Python functions, never by the LLM.
Operator-Precedence Bug Fix
A Python precedence bug in FHIR procedure extraction was identified and fixed.
One-Way Ratchet
Safety Reviewer can only upgrade risk recommendations.
Graceful Degradation
Sparse data mode prevents crashes and unsafe assumptions.
CHALLENGES I FACED
THE FHIR CONTEXT EXTENSION
PromptOpinion's FHIR context support required declaring:
ai.promptopinion/fhir-context
during MCP initialize handshake.
THE FASTMCP IMPORT BUG
RequestContext import pattern changed in FastMCP 3.x.
THE PROCEDURE EXTRACTION BUG
FHIR procedure extraction returned None due to operator precedence.
CLINICAL SCOPE DISCIPLINE
The hardest design decision was what not to build.
WHAT I LEARNED
1. DETERMINISTIC SCORING IS NOT OPTIONAL
The LLM cannot reliably compute RCRI or other risk scores.
2. SAFETY ARCHITECTURE MUST BE STRUCTURAL
Safety guarantees must exist at architectural level.
3. FHIR IS HARDER THAN IT LOOKS
Real-world FHIR bundles are inconsistent and messy.
4. MISSING DATA IS THE CLINICAL NORM
Sparse-data handling is essential for clinical trustworthiness.
5. THE PROMPT IS THE LAST LINE OF DEFENCE
Architecture matters more than prompting.
FUTURE SCOPE
PHASE 1 — IMMEDIATE EXTENSIONS
- Aegis Consent Intelligence Agent
- Surgical Scheduling Agent
- Resident Teaching Mode
PHASE 2 — REAL-TIME HOSPITAL INTEGRATION
- HIS / OT integration
- Smart alerts
- FHIR subscriptions
PHASE 3 — PREDICTIVE INTELLIGENCE
- Cancellation prediction
- ICU prediction
- Difficult airway prediction
- Postoperative complication prediction
PHASE 4 — NATIONAL PERIOPERATIVE NETWORK
- Regional benchmarking
- ABDM / ABHA integration
- Rural deployment
PHASE 5 — FULL PERIOPERATIVE ECOSYSTEM
- Intraoperative decision support
- ICU monitoring
- Recovery intelligence
- Pain optimisation
- Regional language expansion
WHY "AEGIS"?
In Greek mythology, the Aegis symbolized protection and guidance.
We chose the name because perioperative anesthesia is fundamentally about anticipation, vigilance, preparation, and protecting patients before surgery even begins.
CORE LANGUAGE & RUNTIME
Python 3.11
Core language for:
- clinical scoring logic
- FHIR normalization
- flag detection
- report formatting
Python Standard Library
Used modules:
ast
json
logging
datetime
re
typing
dataclasses
math
MCP FRAMEWORK
FastMCP 3.2.4
MCP framework exposing all 6 clinical tools.
https://github.com/jlowin/fastmcp
MCP Protocol
Underlying protocol standard.
mcp (Python SDK)
Low-level primitives used for FHIR extension declaration.
HTTP & ASYNC
httpx 0.28.1
Async HTTP client for parallel FHIR resource queries.
AI PLATFORM & ORCHESTRATION
PromptOpinion
Healthcare AI orchestration platform.
Claude Sonnet (Anthropic)
Used for:
- orchestration
- clinical reasoning synthesis
- safety addendum generation
A2A Protocol
Agent-to-agent communication protocol.
HEALTHCARE STANDARDS & INTEROPERABILITY
FHIR R4
Healthcare interoperability standard.
LOINC
Supported mappings include:
2823-3 → Potassium
718-7 → Hemoglobin
2160-0 → Creatinine
4548-4 → HbA1c
SMART on FHIR
OAuth-based FHIR access framework.
CLINICAL SCORING SYSTEMS
RCRI — Lee et al. 1999
Perioperative cardiac risk score.
STOP-BANG — Chung et al. 2008
OSA screening tool.
Apfel Score — Apfel et al. 1999
PONV prediction model.
ASA Physical Status Classification
Rule-based ASA estimation.
EVIDENCE-BASED GUIDELINES
- ESC/ESA Perioperative Guidelines 2022
- ASA Practice Guidelines 2022
- DAS Difficult Airway Guidelines
- AIDAA Perioperative Diabetes Guidelines
- ADA Standards of Care 2024
- ASRA / ESAIC Anticoagulation Guidelines
- KDIGO Renal Guidelines
- AAGBI Perioperative Guidelines
DEPLOYMENT & INFRASTRUCTURE
Local server and via NGROK
Docker
Containerization .
GitHub
Source control and deployment trigger.
DEVELOPMENT TOOLS
VS Code
Primary development environment.
PowerShell
Used for development and testing.
Python unittest
9 unit tests covering:
- bundle parsing
- LOINC mapping
- sparse data handling
- procedure extraction
- operator precedence bug fix


Log in or sign up for Devpost to join the conversation.