Inspiration

Medication errors at care transitions cause 30% of hospital readmissions and kill 7,000-9,000 Americans every year. The root cause: fragmented data. A patient's hospital EHR, pharmacy system, and primary care office all maintain separate medication lists that rarely agree.

Today, clinicians reconcile these lists manually, often under time pressure during admissions or discharges. They compare printouts, make phone calls, and hope nothing falls through the cracks. When it does, patients get duplicate doses, dangerous interactions go undetected, and discontinued medications continue.

We built MedRecon because this is exactly the kind of problem where multi-agent AI can make a real difference: multiple data sources that need to be gathered, compared, and analyzed against clinical knowledge, all in a structured workflow.

What It Does

MedRecon automates medication reconciliation using a 3-agent system:

  1. Source Collector Agent queries FHIR R4 endpoints to gather medications from multiple care settings (hospital, pharmacy, primary care), simulating the real-world data silo problem. It merges these lists with source attribution so clinicians can see where each medication came from.

  2. Interaction Checker Agent runs safety analysis on the merged list: drug-drug interactions (from a curated clinical database of 48 known interactions + OpenFDA), allergy cross-references (via FHIR AllergyIntolerance with fuzzy matching and drug class cross-reactivity), dose validation (safe ranges for 18 common drugs), and therapeutic alternatives (via RxNorm ATC classification).

  3. Orchestrator Agent coordinates the workflow via Google's A2A protocol, assembles the final report with severity-tiered alerts (SEVERE/MODERATE/LOW), and generates FHIR R4 MedicationStatement + Provenance bundles for write-back to the clinical system.

All three agents communicate via A2A (JSON-RPC 2.0) and share a common MCP server with 8 clinical tools.

How We Built It

MCP Server (TypeScript): 8 clinical tools built on the Model Context Protocol. Each tool is a focused clinical function: get_medications (FHIR query), check_interactions (curated DB + OpenFDA), lookup_drug_info (RxNorm API), check_allergies (FHIR + fuzzy matching), find_alternatives (RxClass ATC), validate_dose (curated ranges), reconcile_lists (multi-source merging), generate_fhir_output (R4 bundle generation).

A2A Agents (Python): 3 agents built with Google ADK + Gemini 2.5 Flash. Each agent publishes an Agent Card at /.well-known/agent-card.json declaring its capabilities. The Orchestrator routes work to specialist agents via A2A message/send and task/get.

FHIR Integration: Queries real FHIR R4 servers (HAPI FHIR). We generated 281 synthetic patients using Synthea with diverse medication profiles, plus 5 hand-crafted demo patients with known dangerous interactions (metoprolol+verapamil, warfarin+amiodarone, methotrexate+NSAIDs).

Drug Interaction Database: 48 curated clinically-significant interactions with severity levels, mechanisms, and clinical notes. Supplemented by OpenFDA drug label API for broader coverage.

Frontend (Next.js): Dual-mode UI showing either the full 3-agent pipeline with real-time progress visualization, or a quick single-agent scan. Report panel renders markdown with severity highlighting. FHIR R4 bundle download button.

Deployment: 4 services on GCP Cloud Run (auto-scales to zero for cost efficiency) + Vercel for the frontend. All services communicate over HTTPS.

Challenges We Ran Into

Multi-source reconciliation logic. The hardest tool to build was reconcile_lists. Three medication lists from different sources use different naming conventions, codes, and dosing formats. The reconciliation algorithm has to fuzzy-match drug names, handle brand vs. generic equivalents, and flag when the same drug appears at different doses in different sources. We used RxNorm normalization and Levenshtein distance matching to handle this.

Drug interaction completeness. OpenFDA's drug label API is not reliable for interaction checking on its own. Labels mention interactions in free text, not structured data. We built a curated database of 48 clinically significant interactions with severity, mechanism, and clinical notes, then use OpenFDA as a supplementary source.

FHIR data quality at scale. Synthea generates realistic patient data, but not all generated patients have the medication profiles needed for meaningful reconciliation. Of 287 Synthea patients generated, 6 had to be skipped because they had no medication records. We also had to handle 413 errors from the HAPI FHIR server when uploading large bundles by splitting them into individual resource uploads.

A2A orchestration. Getting three independently-deployed agents to coordinate reliably required careful error handling. If the Source Collector can't reach the FHIR server, the Orchestrator needs to handle that gracefully rather than producing an incomplete report. Each agent has its own retry logic and error reporting.

Accomplishments We're Proud Of

  • End-to-end pipeline works on real FHIR data with 281 patients at scale
  • Catches clinically dangerous interactions that could harm patients (metoprolol+verapamil, methotrexate+NSAIDs, warfarin+amiodarone)
  • Generates standard FHIR R4 MedicationStatement + Provenance bundles for clinical system write-back
  • 8 reusable MCP tools that any healthcare AI agent could use independently
  • 3 agents communicating via A2A protocol on Prompt Opinion platform
  • All services auto-scale to zero on Cloud Run (zero cost when idle)

What We Learned

  • FHIR R4 is powerful but the ecosystem is still maturing. Public test servers vary widely in what resources they support and how they handle queries.
  • Drug interaction checking requires curated data. No single API provides complete, structured interaction data. The best approach is a curated core database supplemented by broader but less reliable sources.
  • A2A protocol works well for structured healthcare workflows where each agent has a clear, bounded responsibility. The Agent Card pattern makes it easy to add new specialist agents later (e.g., a Prior Authorization agent).
  • MCP is the right abstraction for clinical tools. Each tool is stateless and reusable, which means the same MCP server supports both the multi-agent pipeline and standalone usage.

What's Next

  • Integration with SMART on FHIR for real EHR system authentication
  • Expand drug interaction database to 200+ interactions using DailyMed and DrugBank
  • Add a Prior Authorization agent that checks if new medications require PA before prescribing
  • Clinical trial matching based on patient conditions and current medications
  • Patient-facing medication summary in plain language

Built With

Share this project:

Updates