Inspiration
Care transitions — the handoff from hospital to home — are the most dangerous moment in a patient's healthcare journey. Research shows that 20% of patients experience an adverse event within 3 weeks of discharge, and 30-day hospital readmissions cost the US healthcare system over $26 billion annually. The root cause is almost always the same: critical information falls through the cracks during discharge.
A medication gets stopped during hospitalization but never restarted. A concerning lab value gets overlooked. A specialist referral gets mentioned in the discharge note but never actually scheduled. A patient with a positive depression screening walks out the door without a mental health referral. These aren't rare edge cases — they happen every day, in every hospital.
What makes this problem so persistent is that discharge planning requires cross-domain clinical reasoning — simultaneously analyzing medications against lab values against follow-up appointments against patient social factors. No single clinician can hold all of this in their head during a busy discharge day, and traditional rule-based systems can only flag isolated issues (like a single drug interaction) without understanding the full clinical picture.
When we saw the Agents Assemble hackathon challenging builders to create interoperable healthcare agents using MCP, A2A, and FHIR, we knew this was the perfect opportunity to attack this problem. The A2A protocol enables exactly the kind of autonomous agent collaboration needed — a specialized safety agent that can be consulted by any clinician-facing agent to perform a comprehensive discharge review before the patient walks out the door.
We were also personally motivated by the statistics: medication errors during care transitions injure 1.3 million people annually in the US alone. If an AI agent could catch even a fraction of these errors, the impact on patient safety would be enormous.
What it does
CareTransition Intelligence is an external A2A (Agent-to-Agent) agent built for the Prompt Opinion platform that performs comprehensive discharge safety assessments for hospitalized patients. When a clinician is preparing to discharge a patient, they can consult the Discharge Guardian through the General Chat agent — and the agent autonomously conducts a multi-layered safety review.
The Discharge Safety Workflow
When consulted, the Discharge Guardian performs a structured 4-step analysis:
Step 1 — Patient Data Gathering: The agent uses FHIR context (patient ID, FHIR server URL, and bearer token) passed through the A2A protocol to query the patient's record. It retrieves demographics, active medications, active conditions, and recent lab observations directly from the FHIR server. It also analyzes any clinical documents uploaded to the patient's record (admission notes, progress notes, discharge summaries).
Step 2 — Medication Change Analysis: The agent compares the patient's pre-admission medication list against their discharge medications. For each change, it evaluates:
- Is the new medication appropriate given the patient's conditions and current lab values?
- Are there dangerous drug-drug interactions?
- Are there drug-disease contraindications (e.g., metformin with impaired renal function)?
- Were any critical home medications inappropriately discontinued?
- Are doses appropriate given organ function?
- Are there therapeutic duplications?
Step 3 — Lab Safety Assessment: The agent cross-references the patient's most recent laboratory values against their discharge medication regimen:
- Are required monitoring labs missing or too old? (e.g., INR for warfarin, creatinine for metformin)
- Are any lab values dangerously out of range for the prescribed medications?
- Do trending values suggest ongoing deterioration?
- Are there critical labs that were never checked?
Step 4 — Follow-up Completeness Evaluation: The agent checks whether the discharge plan includes all necessary outpatient follow-up:
- Is a PCP follow-up scheduled within 7 days?
- Are specialist follow-ups arranged for each active condition?
- Are pending diagnostic tests (colonoscopy, stress test, etc.) actually scheduled or just "recommended"?
- Are standard screenings ordered (ophthalmology for new diabetes, etc.)?
- Is mental health follow-up arranged if screening was positive?
- Are incomplete treatments addressed (e.g., remaining IV iron doses)?
The Discharge Safety Report
The agent synthesizes all findings into a structured Discharge Safety Report that includes:
- Patient Overview — Brief clinical summary
- Overall Readmission Risk Score — HIGH / MODERATE / LOW with clinical justification
- Critical Findings (RED Flags) — Issues that must be addressed before discharge
- Important Findings (YELLOW Flags) — Issues that need attention within 1-2 weeks
- Medication Safety Summary — Key medication concerns in plain language
- Follow-up Gap Summary — Missing appointments and referrals
- Recommended Actions — Numbered, prioritized list of specific actions ordered by urgency
- Safe Discharge Checklist — A concrete checklist for the care team to complete
Example: What the Agent Catches
In our demo patient (Lincoln Bednar, 31-year-old with new-onset diabetes, AKI, hypertension, and severe anemia), the Discharge Guardian identified:
- RED: Metformin prescribed despite recent acute kidney injury — requires eGFR verification before discharge
- RED: New complex insulin regimen with no documented patient education completion
- RED: No PCP follow-up scheduled within 7 days
- RED: Positive stool guaiac with no colonoscopy scheduled — potential occult GI bleeding
- YELLOW: Only 4 of 5 IV iron doses completed — patient left early
- YELLOW: Elevated PHQ-9 with history of domestic violence — no mental health referral initiated
- YELLOW: No nephrology follow-up despite recent AKI
- YELLOW: No ophthalmology screening for newly diagnosed diabetes
A manual pharmacist and care coordinator review to catch all of these issues takes 45-60 minutes. The Discharge Guardian does it in under 60 seconds.
How we built it
Architecture
CareTransition Intelligence is built as an external A2A agent using the Google Agent Development Kit (ADK) in Python, following the architecture of the official po-adk-python starter repository provided by Prompt Opinion.
Core Components:
discharge_guardian/agent.py— The agent definition with a comprehensive clinical reasoning system prompt that encodes discharge safety knowledge (Beers Criteria reasoning, medication safety thresholds, follow-up standards, lab safety ranges)discharge_guardian/app.py— The A2A application entry point that configures the agent card with FHIR extension support, SMART-on-FHIR scopes, security schemes, and skill definitionsdischarge_guardian/tools/discharge_tools.py— Four specialized discharge safety analysis toolsshared/— The shared infrastructure library from the starter repo (FHIR hook, middleware, app factory, FHIR query tools)
The 8 Tools:
The agent has access to 8 tools — 4 FHIR data tools inherited from the shared library, and 4 custom discharge safety analysis tools:
FHIR Data Tools:
get_patient_demographics— Queries FHIR Patient resourceget_active_medications— Queries FHIR MedicationRequest resourcesget_active_conditions— Queries FHIR Condition resourcesget_recent_observations— Queries FHIR Observation resources (labs, vitals)
Discharge Safety Tools:
analyze_medication_changes— Compares pre-admission vs discharge medications for safetyassess_lab_safety— Cross-references labs against medication requirementsevaluate_followup_completeness— Identifies missing follow-up appointments and referralsgenerate_discharge_safety_report— Synthesizes all findings into the final structured report
Technology Stack:
- Python 3.11+ with Google ADK
- A2A Protocol v1 (JSON-RPC) for agent communication
- FHIR R4 for clinical data queries
- SHARP Extension Specs for secure FHIR context propagation
- LiteLLM for model routing (supporting Gemini, OpenAI, Anthropic)
- Deployed on Render with a permanent public URL
- Published to the Prompt Opinion Marketplace
FHIR Integration:
The agent receives FHIR credentials (server URL, bearer token, patient ID) through the A2A message metadata, following the SHARP specification. The extract_fhir_context callback intercepts these credentials before every LLM call and stores them in session state — ensuring credentials never appear in the prompt. FHIR tools then use these credentials to make authenticated REST calls to the FHIR R4 server.
A2A Communication Flow:
- Clinician asks General Chat (PO agent): "Is this patient safe to discharge?"
- General Chat consults the Discharge Guardian via A2A protocol
- Prompt Opinion sends a JSON-RPC
message/sendrequest with FHIR context in metadata - Middleware validates the API key and bridges FHIR metadata
- The FHIR hook extracts credentials into session state
- The agent queries FHIR for patient data, then calls its analysis tools
- The agent returns a structured Discharge Safety Report
- General Chat presents the findings to the clinician
Clinical Document Design
We created realistic synthetic clinical documents for our demo patient (Lincoln Bednar) including:
- A detailed hospital admission note with presenting symptoms, exam findings, and lab values
- Inpatient progress notes covering a 7-day hospitalization
- A discharge summary with medication changes, pending follow-ups, and instructions
These documents were designed to contain realistic clinical safety gaps that the agent would need to identify — medication appropriateness issues, lab monitoring gaps, incomplete follow-up arrangements, and psychosocial risk factors.
Challenges we ran into
1. Gemini API Rate Limits: The free tier of Google AI Studio has strict rate limits (5 RPM, 20 RPD for some models). Our agent makes multiple LLM calls per discharge assessment (one for each tool invocation plus the synthesis step). During development and testing, we frequently hit rate limits, causing 503 and 429 errors. We solved this by switching between models (Gemini 2.5 Flash, 2.0 Flash, 3.1 Flash Lite) and creating fresh API keys to get clean quotas.
2. A2A Protocol Compatibility: The A2A specification recently moved to v1, but the Python a2a-sdk library hasn't fully updated yet. The starter repo included compatibility shims (AgentCardV1, AgentExtensionV1) to bridge the gap, but we still encountered issues with method name aliases (the platform sends SendMessage while the SDK expects message/send) and role format differences (ROLE_USER vs user). The middleware handles these translations automatically.
3. Environment Variable Management on Windows: Running the agent locally on Windows PowerShell required careful management of environment variables. The .env file didn't load automatically in all contexts, requiring us to set variables explicitly in the PowerShell session before starting the server.
4. FHIR Data Sparsity: The synthetic patients provided by the Prompt Opinion platform had limited clinical data (mostly demographics and basic dental/pediatric records). We needed to create and upload our own rich clinical documents to demonstrate the agent's full capabilities with a complex discharge scenario.
5. Balancing Agent Complexity vs. Reliability: We initially considered building both an MCP server and an A2A agent (dual submission). However, ensuring reliability of the A2A flow — which involves multiple tool calls, FHIR queries, and LLM reasoning steps in sequence — required focused testing and debugging. We chose to invest in one robust, well-tested A2A agent rather than two potentially fragile submissions.
Accomplishments that we're proud of
1. End-to-End A2A Integration: Our agent successfully communicates with the Prompt Opinion platform via the A2A protocol, receives FHIR context through SHARP headers, queries a live FHIR server, and returns structured clinical assessments. This is the full interoperability stack — A2A + FHIR + SHARP — working together.
2. Real FHIR Queries: Unlike agents that only reason over uploaded documents, our agent actually queries the FHIR server for structured patient data (demographics, medications, conditions, lab observations) using the bearer token provided in the A2A metadata. The logs show real tool_get_patient_demographics, tool_get_active_medications, tool_get_active_conditions, and tool_get_recent_observations calls hitting the FHIR endpoint.
3. Clinically Accurate Reasoning: The agent correctly identifies clinically significant safety issues — metformin contraindication with impaired renal function, missing INR monitoring for anticoagulants, polypharmacy risks in elderly patients, standard-of-care screening gaps for new diagnoses. These are not generic observations but specific, actionable clinical findings.
4. Structured, Actionable Output: The Discharge Safety Report follows a consistent format with RED/YELLOW/GREEN severity coding, numbered priority actions, and a concrete checklist. This mirrors how real clinical decision support systems present information to clinicians — familiar, scannable, and actionable.
5. Built and Deployed in Under 24 Hours: From idea to working, deployed A2A agent connected to the Prompt Opinion platform, published on the Marketplace, and submitted — all within a single day. This demonstrates the power of the Prompt Opinion platform and Google ADK in enabling rapid healthcare agent development.
What we learned
1. A2A is the Future of Healthcare Interoperability: The ability to have specialized agents communicate autonomously — each with its own expertise, its own model, its own data access — is a fundamentally different paradigm from monolithic healthcare IT systems. A discharge safety agent shouldn't need to be built into the EHR; it should be a specialized service that any clinical system can consult.
2. FHIR + A2A + SHARP = Real Interoperability: The combination of these three standards creates a genuinely interoperable ecosystem. FHIR provides the data layer, A2A provides the communication protocol, and SHARP provides the security context. Together, they enable agents to work across organizational boundaries while respecting patient privacy.
3. The "Language First" Approach Works: Prompt Opinion's emphasis on "language-first interoperability" — where agents reason over unstructured clinical notes, not just structured FHIR resources — is crucial. In real healthcare, the richest clinical information often lives in free-text notes, not coded data. Our agent's ability to reason across both structured FHIR data and unstructured clinical documents is what makes it clinically useful.
4. The Platform Handles the Hard Parts: The Prompt Opinion platform's handling of authentication, FHIR token propagation, A2A routing, and marketplace publishing allowed us to focus entirely on the clinical use case and agent logic. Without this infrastructure, building a secure, interoperable healthcare agent from scratch would have taken weeks, not hours.
5. Rate Limits Matter in Production: Free-tier API limits that seem generous for a single chatbot become restrictive when an agent needs to make 5-8 LLM calls per assessment. For production healthcare AI, reliable model access with appropriate rate limits is a critical infrastructure requirement.
What's next for CareTransition Intelligence - Discharge Safety Agent
1. Multi-Agent Orchestration: Expand from a single Discharge Guardian to a team of specialized agents — a Medication Safety Agent, a Lab Trend Analyzer, a Follow-up Coordinator, and a Patient Education Agent — orchestrated through an A2A hub. Each agent would be a deep specialist, and the orchestrator would coordinate them into a comprehensive discharge workflow.
2. Real-Time Monitoring: Instead of being consulted on-demand, the agent could continuously monitor patients approaching discharge and proactively alert care teams when safety gaps are detected — before anyone asks.
3. FHIR Write-Back: Currently, the agent produces advisory reports. The next step is enabling it to write resources back to the FHIR server — creating Task resources for missing follow-ups, generating ServiceRequest resources for needed referrals, and updating the CarePlan with safety-verified discharge instructions.
4. Clinical Guideline Grounding: Integrate evidence-based clinical guidelines (CMS Readmission Reduction Program criteria, AHRQ discharge planning toolkit, society-specific guidelines) as grounding collections, so the agent's recommendations are explicitly tied to published evidence rather than general LLM knowledge.
5. EHR Integration: Leverage Prompt Opinion's EHR launch capability (demonstrated with Epic and Practice Fusion) to embed the Discharge Guardian directly into the clinician's workflow — appearing as a SMART-on-FHIR app within the EHR at the point of care.
6. Outcome Tracking: Build a feedback loop that tracks whether flagged patients actually experience adverse events or readmissions, enabling continuous improvement of the agent's risk scoring and recommendation algorithms.
7. Multi-Language Support: Extend the patient-facing components (discharge instructions, medication guides) to support multiple languages, improving health equity for non-English-speaking patients.
Log in or sign up for Devpost to join the conversation.