-
-
Patient intake with raw discharge summary and FHIR-aware intake connector.
-
Before-and-after clinical parsing: raw discharge text transformed into a structured Care Brief.
-
Operational care plan generated from discharge context with priorities, appointments, labs, and referrals.
-
Follow-up analysis of free-text patient response to detect adherence issues, missed task, and symptoms.
-
Escalation triggered after red flags, missed labs, and worsening follow-up symptoms were detected.
-
Workflow timeline showing multi-agent orchestration from intake to escalation.
## Inspiration
Every year, nearly 3.8 million patients are readmitted to U.S. hospitals within 30 days of discharge — at a cost exceeding $26 billion. The root cause isn't medical complexity alone; it's the "last mile" of care: the chaotic gap between when a patient leaves the hospital and when they actually complete their follow-up appointments, fill prescriptions, and recognize warning signs.
Discharge summaries — the critical handoff documents — are dense, unstructured clinical narratives written for physicians, not for the community health workers, care navigators, and patients who need to act on them. Information gets lost. Appointments get missed. Warning signs go unnoticed until it's too late.
We built Last Mile Care (LMC) because we believe AI agents can close this gap — not by replacing human caregivers, but by giving them structured, actionable intelligence from the moment a patient walks out the hospital door. And with protocols like A2A and MCP, these agents don't have to work in isolation. They can plug into existing health platforms and share structured clinical data across organizational boundaries.
What it does
Last Mile Care is a multi-agent system that transforms unstructured clinical discharge summaries into structured, actionable care continuity workflows. It operates through 6 Care Contracts and 3 specialized AI agents orchestrated by a state-machine engine called CareFlow.
The 6 LMC Care Contracts define the structured data that flows between agents:
PatientContext — Standardized patient demographics, diagnoses, and discharge details
CareBrief — AI-extracted clinical entities with priority classification (LOW → CRITICAL)
CarePlan — Actionable task lists: appointments, labs, referrals, and medications with deadlines
ContinuityStatus — Real-time adherence tracking from patient follow-up responses
EscalationEvent — Triggered alerts when red flags or non-adherence patterns are detected
WorkflowState — The current stage in the 6-step care pipeline
The 3 AI Agents, each powered by Claude Sonnet 4 via Abacus.AI:
Summary & Handoff Agent — Parses raw discharge text, extracts clinical entities (diagnoses, medications, pending labs, warning signs), and generates a prioritized CareBrief
Care Navigation Agent — Takes the CareBrief and generates a detailed CarePlan with specific tasks, responsible parties, and follow-up windows
Follow-Up Agent — Analyzes free-text patient responses against the CarePlan, identifies adherence gaps and concerning symptoms, and triggers escalations when warranted
CareFlow Engine orchestrates the full pipeline through 6 stages: INTAKE_RECEIVED → BRIEF_GENERATED → PLAN_ACTIVE → FOLLOW_UP_MONITORING → ESCALATED → COMPLETED, with validated transitions and an event bus for real-time tracking.
Interoperability: LMC exposes its capabilities through both Google A2A Protocol (JSON-RPC 2.0 with Agent Cards) and Model Context Protocol (MCP) (SSE + Streamable HTTP transports), making it discoverable and callable by any compatible platform — including Prompt Opinion by Darena Health.
How we built it
Architecture: LMC follows a contract-first design. We defined the 6 Care Contracts as TypeScript interfaces before writing any agent logic, ensuring every piece of clinical data flowing through the system has a defined shape and validation.
Tech Stack:
Frontend: Next.js 14 with Tailwind CSS and Framer Motion — a responsive dashboard with 5 views (Intake, Brief, Plan, Follow-Up, Timeline)
Backend: Next.js API routes handling agent orchestration, A2A protocol, and MCP server
Database: PostgreSQL with Prisma ORM — 7 models (PatientCase, CareBrief, CarePlan, ContinuityStatus, WorkflowState, Escalation, TimelineEvent)
AI: Claude Sonnet 4 via Abacus.AI RouteLLM API — structured JSON output with clinical system prompts
Hosting: Abacus.AI platform with automated deployment
CareFlow Engine: A deterministic state machine with validated transitions, stage labels, color codes, and an event bus that logs every state change with timestamps.
A2A Implementation: Full Google A2A Protocol v0.2.1 compliance:
Agent Card at /.well-known/agent.json with 3 declared skills
JSON-RPC 2.0 endpoint at /api/a2a supporting message/send and tasks/get
Robust message normalization handling diverse client formats
FHIR context extraction from request headers for real EHR integration readiness
MCP Implementation: Dual-transport MCP server:
SSE Transport: GET /api/mcp/sse establishes persistent connections, POST /api/mcp/messages handles tool calls
Streamable HTTP: POST /api/mcp for clients preferring direct HTTP
3 tools exposed: parse_discharge_summary, generate_care_plan, analyze_patient_followup
Each tool executes the same LLM pipeline as the A2A skills, ensuring consistent results regardless of protocol
Mock FHIR Layer: Simulated FHIR R4 connectors (Patient, Encounter, Condition resources) demonstrate how LMC would interface with real EHR systems, with a FHIRService class ready to accept live FHIR endpoints.
Challenges we ran into
A2A Protocol Maturity: We built a fully spec-compliant A2A endpoint validated with Google's official A2A Inspector, but discovered that Prompt Opinion's SendA2AMessage tool handler returned internal errors. After investigating Darena Health's open-source repos, we found they had no A2A client implementations — only MCP servers. This taught us that A2A, while promising, is still early-stage in production adoption.
Pivoting to MCP: After the A2A discovery, we implemented a complete MCP server with both SSE and Streamable HTTP transports in under 24 hours. The challenge was ensuring our SSE endpoint returned correct public URLs in production (behind reverse proxies, x-forwarded-host headers weren't reliable), which required careful URL construction logic.
LLM Output Consistency: Getting Claude to return valid, parseable JSON for structured clinical data required iterative prompt engineering. Discharge summaries contain ambiguous medical terminology, and the LLM needed to distinguish between active diagnoses, historical conditions, and incidental findings reliably.
State Machine Edge Cases: The CareFlow Engine needed to handle cases where patients could move from ESCALATED back to FOLLOW_UP_MONITORING (de-escalation after clinical review), requiring bidirectional transition support without creating infinite loops.
Real-Time Streaming: Implementing SSE streaming for agent responses while maintaining database consistency (writing the final parsed result after stream completion) required careful orchestration of async operations.
Accomplishments that we're proud of
Dual-Protocol Interoperability: LMC is one of the few hackathon projects that implements both A2A and MCP protocols, making it compatible with the broadest range of agent platforms
Working MCP Integration: Our MCP server is live in production and successfully executes all 3 tools — parse discharge summaries, generate care plans, and analyze follow-ups — with real LLM processing, not mock responses
Contract-First Architecture: The 6 LMC Care Contracts create a clean, auditable data pipeline where every transformation between agents is typed and validated
Clinical Realism: Our demo case (a 67-year-old CHF patient with comorbidities, polypharmacy, and a 48-hour follow-up window) demonstrates real clinical complexity — the kind of case that actually leads to readmissions
End-to-End Pipeline: From unstructured clinical text to prioritized care plan to patient follow-up analysis to automated escalation — the entire care continuity workflow runs in a single system
Production Deployment: The system is live at lastmilecare.abacusai.app with all endpoints publicly accessible and tested
What we learned
Protocol reality vs. specification: A2A has an elegant spec, but production implementations vary wildly. MCP's simpler tool-call pattern proved more practically interoperable today. Both protocols will mature, and supporting both positions LMC for the future.
Structured contracts > free-text prompts: Defining rigid data contracts between agents (rather than letting them communicate in free text) dramatically improved reliability and debuggability. When Agent B fails, you can inspect the exact contract from Agent A.
Healthcare AI needs guardrails, not just capabilities: The Follow-Up Agent doesn't just analyze — it explicitly checks for escalation triggers using the patient's specific warning signs from their discharge summary. Domain-specific safety logic matters more than general LLM intelligence.
SSE in production is tricky: Server-Sent Events behind load balancers, reverse proxies, and serverless platforms require careful URL construction and session management. We implemented an in-memory session store that handles connection lifecycle gracefully.
Agent interop is the real frontier: Building AI agents is solved. Making them discover and communicate with each other across organizational boundaries — that's the hard problem A2A and MCP are trying to solve, and it's worth investing in.
What's next for Last Mile Care A2A
Live FHIR Integration: Replace mock connectors with real FHIR R4 endpoints to pull patient data directly from EHR systems (Epic, Cerner). The FHIRService class is already structured for this.
Patient Communication Agent: A 4th agent that generates plain-language summaries and sends SMS/email reminders to patients in their preferred language, integrated with Twilio or similar services.
Multi-Language Support: Extend the LLM prompts to generate CareBriefs and CarePlans in Spanish, Mandarin, and other languages commonly needed in community health settings.
Longitudinal Tracking: Expand beyond single-discharge episodes to track patients across multiple encounters, building a continuity score over time.
Deeper Prompt Opinion Integration: As MCP tooling matures on the Darena Health platform, build bidirectional workflows where Prompt Opinion can not only call LMC tools but also push clinical updates back into our CareFlow Engine.
HIPAA Compliance Layer: Add audit logging, data encryption at rest, and role-based access controls to prepare LMC for real clinical deployment.
Agent Marketplace Listing: Publish LMC as a discoverable agent on A2A directories and MCP registries so any health platform can find and integrate our capabilities without custom configuration.
Built With
- a2a
- abacusai
- claude
- css
- fhir
- fhirr4
- hl7
- html
- jsonrpc
- nextjs
- postgresql
- prisma
- promptopinion
- react
- routellm
- snomedct
- sonnet4
- sse
- typescript
Log in or sign up for Devpost to join the conversation.