Inspiration Every time you pick up a prescription and the pharmacist says "your insurance needs prior authorization," what's actually happening is a 30-minute paperwork dance: the pharmacy faxes a form, the insurer sits on it, the doctor's office gets a callback, lab values get rekeyed, and somewhere in that loop a patient walks away without their medication. The numbers are stark:
94% of patients face delays from prior authorization (American Medical Association) 78% abandon treatment because of these delays 19% of pharmacists report a PA delay has caused a patient to suffer a serious adverse event (Surescripts 2025) Physicians complete an average of 39 prior authorizations per week, spending 13 hours on it
Most "AI for PA" tools handle paperwork. We wanted to build something that does what a senior clinical pharmacist does β recognize when a patient's comorbidities qualify them for a step-therapy override, escalate Tier 1 patient-safety risks, and produce a complete handoff package the pharmacy team can act on in under 90 seconds. The hardest part of healthcare AI isn't intelligence. It's the last mile. ScriptFlow is one tile of that mile. What it does Given a rejected pharmacy claim, ScriptFlow produces a complete 5T deliverable:
π¨ Patient Safety Banner (Tier 1 only) β bridge-supply recommendation when delay risks harm π£οΈ Talk β pharmacist briefing in plain language, expected approval time π Table β markdown case snapshot with diagnoses, ICD-10 codes, prior therapies π Template β pre-filled PA form with auto-filled clinical justification β‘ Transaction β simulated payer submission with case ID β Task β follow-up work item with assignee, SLA, and specific action
The differentiator: clinical urgency triage and override recognition Two things rule-based PA tools can't do: Patient-safety urgency triage. Tier 1 / Tier 2 / Tier 3 scoring based on drug class plus comorbidities. Tier 1 cases trigger an immediate Patient Safety Banner with bridge-supply recommendation citing MACE risk. Step-therapy override recognition. When a patient with established ASCVD is prescribed a GLP-1 receptor agonist like semaglutide, ScriptFlow recognizes the ADA/ESC guideline override path β meaning a step-therapy reject can be appealed immediately based on cardiovascular benefit, not after sequential trials of preferred agents. This is the doctor-thinking that saves days. Demo case We tested with a synthetic Maria Garcia case: 63-year-old, Type 2 Diabetes, status post NSTEMI 2023 with stent (established ASCVD), HbA1c 8.7% on max metformin and glipizide. Aetna rejected semaglutide (Ozempic) with reject code 75-A β STEP THERAPY EDIT. ScriptFlow produced:
Tier 1 CRITICAL urgency, correctly escalated due to ASCVD and GLP-1 RA delay Patient Safety Banner with 14-day bridge-supply recommendation citing MACE risk Step Therapy Override identified with ADA/ESC guideline citation ICD-10 codes auto-filled (E11.9 for T2DM, I25.10 for ASCVD) Pre-filled PA form with prior therapy dates/doses, supporting labs (HbA1c 8.7%, eGFR 72) Simulated submission to Aetna ePA portal with case ID Follow-up task: Pharmacy Tech, 4-hour SLA, with phone number to expedite
End-to-end runtime: 60 to 90 seconds. 15+ Gemini LLM calls and 8+ MCP tool calls per case. How we built it Three layers, each using a different open standard. Layer 1: MCP server with five domain tools Built a custom Model Context Protocol server in Python with FastAPI. Five tools encoding pharmacy domain logic:
classify_rejection β categorizes rejection text into nine categories (PA_REQUIRED, STEP_THERAPY, FORMULARY_EXCLUSION, QUANTITY_LIMIT, and others) assess_clinical_urgency β Tier 1/2/3 scoring with SLA and bridge-supply logic. The doctor lens. identify_missing_documentation β payer-specific document checklist extract_pa_evidence β FHIR pull of Conditions, MedicationRequests, and Observations using SHARP context headers draft_appeal_letter β payer-agnostic appeal generator
The MCP server declares the official Prompt Opinion FHIR context extension (ai.promptopinion/fhir-context) with SMART scopes for Patient, Condition, MedicationRequest, and Observation. This declaration enables SHARP context headers (X-FHIR-Server-URL, X-Patient-ID, X-FHIR-Access-Token) to flow from Prompt Opinion into our tool calls. Layer 2: Multi-agent orchestrator with Google ADK Built a root LlmAgent with four sub-agents using Google's Agent Development Kit:
Triage Agent β calls classify_rejection, assess_clinical_urgency, identify_missing_documentation Evidence Agent β calls extract_pa_evidence with FHIR fallback to intake message Planner Agent β reasons over outputs to draft the workflow Form Filler Agent β produces the pre-filled PA form
The orchestrator synthesizes everything into the 5T format using Gemini 2.5 Flash. Layer 3: Two deployment paths We built both an External Agent and a BYO Agent for Prompt Opinion's marketplace, exposing ScriptFlow at two layers of integration: External Agent β the ADK-built multi-agent orchestrator running on a Mac, exposed via ngrok tunnel, with a custom FastAPI proxy that translates ADK's older A2A spec to A2A v0.3.0 (supportedInterfaces, protocolBinding, protocolVersion fields). Streaming method translation handled in the proxy. BYO Agent β same five MCP tools, orchestrated entirely inside Prompt Opinion via a carefully-written 800-word system prompt encoding the workflow, ICD-10 auto-fill rules, and override-recognition logic. Both invoke the same MCP tools. Different runtimes, identical clinical intelligence. Challenges we ran into Module restructuring in a2a-sdk. ADK 1.31.1 was built against an older a2a-sdk (pre-1.0) that had a2a.server.apps.A2AStarletteApplication. The current PyPI release (v1.0.2) restructured the package and that module no longer existed. Workaround: skip the custom A2A server entirely and use ADK's built-in adk api_server --a2a command. A2A spec mismatch with Prompt Opinion. Prompt Opinion's parser rejected ADK's auto-generated agent card with three sequential errors:
Missing supportedInterfaces field (A2A v0.3 requirement) Missing protocolBinding and protocolVersion inside each interface "Streaming is not supported" β Prompt Opinion calls message/stream but ADK's A2A layer only supports message/send
Fix: a 50-line FastAPI proxy that intercepts the well-known agent card URL with a spec-compliant card, declares streaming support, and translates message/stream to message/send for incoming requests before forwarding to ADK. ngrok one-tunnel limit. Free ngrok plan only allowed one simultaneous tunnel, but we needed two (MCP server on port 8080 and A2A agent on port 8000). Solution: reserve a second free dev domain and start a named tunnel. ADK template-variable parsing in prompts. ADK interprets curly-brace variables in instruction text as session state injection. Our example sentences had literal placeholders like {name}, {drug}, and {category}, which ADK tried to resolve at runtime and threw KeyError. Fix: rewrite example sentences in plain text (PATIENT_NAME, DRUG_NAME) without curly braces. FHIR fallback handling. When extract_pa_evidence failed because synthetic patients have no real FHIR backing, the agent initially exposed "FHIR error" in the user-facing output. Fix: hard-coded fallback rule in the orchestrator prompt β extract evidence from the intake message itself when FHIR returns empty, and never expose tool errors to the end user. Accomplishments that we're proud of Clinical accuracy. The ASCVD override reasoning is the path a real clinical pharmacist would actually take. The 5T structure mirrors how real pharmacy teams already document handoffs. Standards compliance, end-to-end. MCP for tools. A2A for agent communication. FHIR for clinical data. SHARP context for credentials. We don't just claim standards adherence β we publish the agent card, the MCP extension declaration, and the FHIR scope manifest. Two parallel deployment architectures. Building both an External Agent and a BYO Agent demonstrates the same clinical intelligence at two layers of the stack. Either can be picked up by another healthcare AI builder from the marketplace. Synthetic data discipline throughout. Maria Garcia and every test patient is clearly synthetic. The clinical reasoning is grounded in real ADA/ESC guidelines, but no PHI was ever used. What we learned Standards have versions. A2A v0.2 vs v0.3 had real schema differences. MCP's tool schema and extension declarations are still stabilizing. Always inspect what the receiving platform expects, not just what your library generates. Local works does not equal remote works. Our agent worked perfectly in adk web for hours before we ever exposed it over A2A. The protocol layer adds an entirely different debugging surface. Proxies are underrated. A 50-line FastAPI proxy resolved three different protocol mismatches without modifying ADK source. When two systems disagree on spec, sit a translator in the middle. The instruction manual is most of the work. The 800-word ScriptFlow system prompt β encoding the workflow, ICD-10 codes, and override-recognition rules β is what made the demo land. Code was 30% of the project. Domain knowledge plus careful prompt engineering was the other 70%. What's next for ScriptFlow More urgency rules. Current Tier 1/2/3 logic covers GLP-1 RA plus ASCVD, anticoagulants, antibiotics, and insulin. A production version would include 100+ drug-comorbidity pairings co-authored with clinical pharmacists. Real payer integration. The current Transaction step is simulated. A real version would integrate with ePA portals like CoverMyMeds or Surescripts CompletEPA. Outcome tracking. Each PA case generates a Task. The system could close the loop by tracking which appeals get approved, which override paths work for which payers, and feed that back into the urgency tool. Other use cases. The same MCP and A2A architecture works for any structured medical decision: clinical trial matching, infusion scheduling, durable medical equipment authorization, medication reconciliation at hospital discharge. Pharmacist co-design pilot. The next version should be co-built with 3 to 5 working pharmacists evaluating output quality on real (de-identified) historical cases.
Log in or sign up for Devpost to join the conversation.