The Problem
Every day, patients leave hospitals with prescription lists that nobody has fully checked. A clinical pharmacist performing medication reconciliation manually takes 30–60 minutes per patient, cross-referencing pre-admission medications, inpatient orders, and discharge prescriptions against interaction databases, recall notices, and renal dosing tables. At high-volume wards, this simply doesn't happen thoroughly. The result: 1.5 million preventable adverse drug events annually in the US alone.
Standard AI doesn't solve this. A general-purpose LLM hallucinates drug interactions, works from training data that is months old, and has no idea whether a medication was recalled last Tuesday or whether a drug is currently in national shortage.
What SafeTransit Does
SafeTransit is a specialized Clinical AI Agent that automates medication reconciliation at hospital discharge. It is not a language model giving its best guess, it is a clinical pipeline that queries live databases in real time and shows its work.
When a physician initiates a reconciliation, SafeTransit:
- Ingests structured patient context — medications, labs, allergies, demographics — via a FHIR connection through Prompt Opinion's SHARP extension
- Identifies which checks are clinically necessary based on the patient's conditions and lab values
- Fires all checks in parallel — drug-drug interactions, FDA Class I/II recalls, renal dose adjustments (Cockcroft-Gault + CKD-EPI), shortage status, PubMed guideline citations — simultaneously against live external databases
- Synthesizes findings via OpenRouter's model pool into a structured clinical report
- Delivers an interactive live dashboard, a downloadable PDF, and a shareable private link — all within the physician's Prompt Opinion workspace
How We Built It
Architecture
SafeTransit runs as two independent surfaces on the Prompt Opinion platform:
MCP Server (FastAPI + Python) Five clinical intelligence tools exposed via MCP SSE transport:
check_drug_interactions— pairwise analysis via OpenFDA drug label APIcheck_drug_recall_status— live FDA enforcement databasecalculate_renal_dose— Cockcroft-Gault + CKD-EPI + FDA label guidancecheck_drug_shortage— FDA drug shortage databasesearch_clinical_evidence— NCBI PubMed E-utilities
A2A Agent Server (FastAPI + Python)
A standards-compliant A2A v1 external agent that Prompt Opinion registers via agent card discovery. It orchestrates the full reconciliation workflow using OpenRouter's model routing, fires all tools in parallel via asyncio.gather, and streams progress to a live report dashboard at /reports/{slug}.
The Performance Architecture
The key engineering insight: the language model should not be the bottleneck. We implemented a Zero-Shot Lean Synthesis pattern:
- Extract patient context from FHIR and message text
- Fire all clinical tool calls in parallel (not sequentially)
- Truncate raw API responses to a lean 5k-token context (from ~50k raw)
- Make a single LLM synthesis call with all pre-gathered data already in context
This collapsed what was originally 7 sequential LLM rounds (5+ minutes) to 2 rounds (~90 seconds).
For complex cases, we use a fire-and-forget pattern: return a completed A2A task immediately with a private report link, process the full reconciliation in background, and let the physician check the live progress dashboard — eliminating PO's SSE connection timeout entirely.
The Report Dashboard
The report page (/reports/{slug}) is a self-contained live progress dashboard with:
- Real-time progress bar polling the server every 3 seconds
- Markdown rendering of the full clinical report via
marked.js - PDF download button when the PDF is ready
- Automatic deletion after 6 hours (no PHI retained)
- Private unguessable URL (128-bit entropy slug)
Challenges
A2A Protocol implementation was the hardest part. The Prompt Opinion platform uses a C# A2A parser with specific enum casing requirements that differ from the published spec — TASK_STATE_COMPLETED instead of completed, ROLE_AGENT instead of agent. Each mismatch produced a cryptic .NET deserialization error. We resolved 12 distinct protocol conformance issues over the development period.
SSE connection timeouts were the second major challenge. Prompt Opinion closes idle SSE connections after ~60 seconds. Our full reconciliation takes 90–360 seconds. The solution was the fire-and-forget background architecture: return a completed task with the report link in under 10 seconds, process everything in the background.
OpenFDA rate limits required round-robin API key rotation with exponential backoff (10s, 20s, 40s) and parallel batched queries instead of per-drug sequential calls.
What We Learned
- A2A v1 and the Prompt Opinion implementation are subtly different — always test against the actual platform, not just the spec
- Pre-executing tools before the LLM and passing lean context produces better, faster synthesis than sequential tool-calling
- Fire-and-forget with a live dashboard is a better UX pattern than long-running SSE streams for clinical workflows
- Real clinical APIs (FDA, NCBI) have enough latency that parallel execution is not just an optimization — it is a requirement
What's Next
- FHIR write-back: automatically filing the reconciliation report as a FHIR
DocumentReferencein the patient's record - Allergy cross-reactivity engine using the RXCUI allergen graph
- Formulary checking against hospital-specific PDL APIs
- Audit trail export for compliance documentation
Built With
- a2a-protocol-v1
- fastapi
- fastmcp
- fda-drug-shortage-database
- fhir-r4
- firebase
- framer-motion
- model-context-protocol-(mcp)
- ncbi-e-utilities-(pubmed)
- nvidia-nim
- openfda-api
- openrouter
- prompt-opinion-platform
- python
- react
- reportlab
- resend
- rxnorm-api
- sharp-context-extension
- tailwind-css
- typescript
- vite
Log in or sign up for Devpost to join the conversation.