-
-
System Design
-
Voice Brief Flow & Redis Database
-
Care Plan Generation Request Flow
-
Login Page
-
Appointment Dashboard
-
Brief Generation and Chat
-
Brief audio can be replayed
-
Care-Giver can chat with the Brief Generation Agent to find out more details
-
Notes added by doctor via Text/ Audio
-
We start generating Care Plan for the Patient based on Care-Giver's notes.
-
Care plan generated with supporting ICD-10 and CPT codes on the left, including estimated billing cost.
-
The status of appointment changes to Done after appointment.
Inspiration
Independent physicians running small practices carry a weight most people never see. Every patient visit generates hours of work before and after the appointment itself, work that pulls them away from the reason they went to medical school in the first place.
There are tools today that listen to the appointment and write the clinical note automatically. That problem is largely solved. Nobody has built what happens before the patient walks in, and after they leave. Before: the physician scrambles through a chart trying to remember who this patient is, what has changed, and what is urgent. They walk in underprepared. After: they have to convert everything discussed into a document the patient can actually use. Most patients leave without one. They forget 80% of what was said. They miss follow-ups. They come back to the emergency room.
We wanted to know: what if the AI read the chart for you, spoke the key points as you walked in the room, and drafted the care plan while you were still in the conversation? Thus, Margin was born.
What it does
Margin is a real-time clinical AI copilot for independent physicians. For this demo it is configured for an endocrinologist managing diabetes patients. If Margin works here, it works anywhere.
- Before the visit, Margin reads the full patient chart and speaks a clinical brief aloud through Deepgram Aura 2 before the physician enters the room. Hands-free. Eyes-free.
- The physician can ask follow-up questions by voice. Deepgram nova-2-medical transcribes in real time with clinical keyword boosting and answers come back spoken in under two seconds.
- Three Fetch.ai uAgents coordinate the pipeline. The Orchestrator receives requests from ASI:One, the Knowledge Agent runs RAG, and the Brief Agent generates the response via Claude.
- After the appointment the physician types their note. Margin runs parallel RAG queries against 227 chunks of ADA 2025 guidelines, KDIGO protocols, and FDA DailyMed, then generates a five-section evidence-grounded care plan.
- A two-layer safety check verifies every medication against the patient's allergy list, checks CKD dose contraindications, and validates recommendations against clinical guidelines before the physician sees anything.
- Eight parallel Claude Haiku evaluators score every care plan and brief from 0 to 100 across medication accuracy, guideline adherence, completeness, billing support, and readability.
CMS-validated billing codes appear automatically with reimbursement estimates. At end of day the physician sees a quality scorecard and tomorrow's schedule already prepared.
How we built it
Three Fetch.ai uAgents all mailbox-enabled, communicating over the Agentverse ACP protocol with deterministic seed-phrase addresses that stay stable across restarts.
Claude Sonnet 4.6 for all clinical reasoning and Claude Haiku for all parallel tasks like billing and the eight evaluators, cutting evaluation latency roughly 70%.
Redis Cloud as the sole database with no SQL and no object storage. The Redis 8.0 native vectorset powers ANN search at 1024 dimensions under 10ms, built entirely from scratch with no existing library.
227 medical guideline chunks embedded with Voyage AI voyage-3, retrieved via four parallel VSIM queries through an 8-worker thread pool in under 200ms.
Deepgram nova-2-medical for WebSocket STT and Aura 2 luna-en for TTS. The full voice loop completes in under two seconds.
Arize Phoenix with AnthropicInstrumentor auto-tracing every Claude call, RAG spans, and eight evaluator spans logging PASS or FAIL per dimension.
Sentry initialized before FastAPI mounts with a custom tunnel endpoint to bypass hospital firewalls, session replay, and care plan quality wired as a custom measurement with alerts firing below 60.
Challenges we ran into
Redis 8.0 native vectorset had no Python library and no documentation at build time. We reverse-engineered the command syntax and discovered RESP3 protocol was required for correct type handling.
Making Claude clinically safe was harder than expected. A patient with an Aspirin allergy prescribed Aspirin by her cardiologist post-heart attack broke simple allergy checking entirely. Real medical safety needs explicit exception logic.
Layer 2 verification had to be specific to be useful. Generic guideline checks meant nothing. Precise rules like checking statin dose against LDL and CV risk actually caught real problems.
Sentry is blocked by hospital IT and ad blockers. We built a tunnel endpoint that validates the DSN and proxies envelopes through our own domain.
Coordinating three mailbox-enabled uAgents without deadlock required preserving the original sender address across two agent hops and isolating timeouts per agent.
Running eight evaluators in parallel while keeping the HTTP response unblocked required per-evaluator exception isolation so one timeout never kills the whole response.
Accomplishments that we're proud of
Zero drug-allergy false negatives across all three demo patients and more than fifteen test scenarios including physician-approved exceptions correctly bypassed.
Redis 8.0 vectorset RAG built entirely from scratch with ANN search under 10ms at 1024 dimensions and no separate vector database needed.
Full voice loop in under two seconds from Deepgram STT through Claude to Deepgram TTS, fast enough for real clinical conversation.
Quality scores consistently above 80 out of 100 on ADA 2025-grounded care plans with a self-correction loop logging both versions to a Redis fine-tuning dataset.
All three Fetch.ai agents mailbox-enabled with the full ACP ChatMessage pipeline working end-to-end from ASI:One to Brief Agent and back.
Production-quality observability with Sentry traces, Arize Phoenix LLM traces, and a care plan quality SLO treating AI output with the same rigour as API latency.
What we learned
Redis 8.0 is production-ready as a vector database. VSIM at 1024 dimensions under 10ms eliminates the need for any dedicated vector infrastructure.
Parallel evaluation is nearly free. Eight evaluators via ThreadPoolExecutor costs almost no additional wall-clock time. Build quality signals in from day one.
Medical voice is a different domain. General-purpose ASR misses HbA1c, eGFR, semaglutide, and tirzepatide. Deepgram nova-2-medical was better from the very first test.
Clinical AI is a verification problem not a language problem. Claude writes fluent prose immediately. Grounding, checking, and scoring the output is 80% of the work.
The physician's workflow is sacred. Every prototype that added an AI step got cut. The product inserts into the existing workflow without changing it.
What's next for Margin
The next step is a pilot with three independent physician practices, live within 48 hours of onboarding. After that a cardiology configuration with ACC/AHA guidelines and cardiac medication formulary. On the infrastructure side HIPAA-compliant deployment with AWS HIPAA-eligible regions, encryption at rest, and Business Associate Agreements with all vendors. Real FHIR EHR integration and live Dexcom and LibreView CGM APIs are on the roadmap. The simulator already matches their output format exactly so swapping in the real APIs is a single function call. Finally multi-specialty tenant support with Redis key namespacing will let Margin scale to any independent practice.
Links
- Margin Orchestrator Agent The entry-point Fetch.ai uAgent for the Margin Clinical AI system. Accepts ACP ChatMessage requests from ASI:One / Agentverse, routes them through the Knowledge and Brief agents, and returns a spoken clinical brief. Runs as a mailbox agent connected to Agentverse. -Margin Brief Agent A Fetch.ai uAgent that generates AI-powered pre-visit clinical briefs using Claude. Runs as a mailbox agent connected to Agentverse.
- Margin Knowledge Agent A Fetch.ai uAgent that performs RAG (Retrieval-Augmented Generation) over clinical guidelines using LangChain + FAISS + HuggingFace embeddings. Runs as a mailbox agent connected to Agentverse.
- ASI:One CHAT Link
Built With
- arize
- asi:one
- claude
- cloudflare
- deepgram
- faiss
- fastapi
- fetch.ai
- langchain
- python
- redis
- sentence-transformers
- sentry
- typescript
- uagents
- voyage
Log in or sign up for Devpost to join the conversation.