02 · Clinical AI Engine & Shared Context Layer

Med Agent Hub

Med Agent Hub is the shared clinical AI runtime behind ChartSearchAI, Catalyst, and our FHIR R4 interoperability pilots. Instead of coupling each client application to a single vendor SDK or raw prompt template, the Hub manages lossless clinical context assembly, deterministic pre-generation clinical graphs, staged answer rules (R1–R10), claim-level citation verification, and hardware-agnostic model routing.

End-to-End Clinical Request Pipeline

Four architectural layers inside Med Agent Hub

Every clinical question or reporting task flows through four deterministic and model-driven stages so small and mid-sized open-weight models receive high-signal context and produce auditable responses.

Layer 1 · Context Ingestion & Normalization

OpenMRS QueryStore & 5-Tier/9-Budget FHIR Condenser

Raw EHR exports and longitudinal FHIR R4 bundles contain up to 90% administrative noise, duplicate boilerplate notes, and repeated prescription renewals.

  • OpenMRS QueryStore: Normalizes and caches patient encounters, observations, orders, and clinical notes with stable UUID provenance references across multi-turn conversations.
  • Lossless Structural FHIR Condenser: Shrinks multi-decade FHIR R4 bundles across 9 token budgets (256k down to 1k), folding duplicate LOINC labs into initial/min/max/latest trajectories and emitting an explicit [Completeness Manifest].
  • Conditional Tier-0 Recovery: Allows models to expand truncated note narratives or historical lab series on demand only when the condensed budget omits detail.
Layer 2 · Pre-Generation Clinical Intelligence

ClinicalEntityGraph & 4-Layer Knowledge Base

Rather than hoping an LLM notices a cross-clinic drug–disease conflict buried across 1,000 records, Med Agent Hub runs deterministic graph and guideline analysis before prompt construction:

  • ClinicalEntityGraph: Links active medications to conditions (TREATS), renal/lab safety thresholds (CONTRAINDICATED_OR_DOSE_ADJUST_IN), monitoring labs (MONITORED_BY), and note-vs-structured discrepancies.
  • Question-Scoped 4-Layer Clinical KB: Injects only relevant evidence rules from offline clinical libraries (WHO SMART Guidelines, KDIGO, ADA, CDC ACIP, RxNorm, LOINC, and 42 CFR Part 2 privacy rules).
Layer 3 · Streaming Synthesis & Answer Rules

Deterministic Clinical Answer Rules (R1–R10)

Med Agent Hub streams incremental SSE events (answer_delta) for low time-to-first-token (TTFT) while enforcing 10 deterministic clinical answer rules (R1–R10):

  • Temporal Anchoring & Window Filtering: Enforces reference-date anchoring, exact date-window filtering ("last 6 months"), and chronological ordering (oldest → newest) on lab trends.
  • Clinical Guardrails: Prevents silent extrapolation across pregnancy episodes, separates active vs. discontinued regimens, and preserves exact source units and reference ranges.
Layer 4 · Verification & Staged Delivery

Findings-Not-Grades Verification & In-Depth

Instead of displaying opaque numerical confidence scores to clinicians, the Hub emits concrete verification findings alongside each answer:

  • Citation & Provenance Binding: Verifies every bracketed claim citation against retained record UUIDs and highlights any ungrounded statement or date mismatch.
  • System-1 & Reviewer Gating: Pairs fast Layer 1/2 checks (Laya ~0.4B entailment encoder) with conditional review passes and an optional In-Depth clinical elaboration stage.

Stream-Isolated Model Profiles

One engine contract across client apps and hardware tiers

Client applications select named workflow profiles via GET /v1/models?workflow=<name> and stream completions via POST /v1/chat/completions. Profiles isolate prompts, verification policies, and backend routing per workstream.

Profile Namespace Target Workflow Context & Verification Policy Supported Inference Backends
openmrs-* ChartSearchAI point-of-care EHR Q&A QueryStore snapshot + R1–R10 temporal/citation checks + optional In-Depth Local llama-router (Gemma 4 E4B/12B), vLLM, Cloud GPU relay
catalyst-sql-* Catalyst OpenELIS & OpenMRS SQL workbench Schema-linked SQL generation + multi-agent query review + read-only execution check Local llama-router / Ollama (Gemma 4 12B, Qwen 2.5/3), Cloud GPU
wahs-* WA Health Summary (WAHS) FHIR R4 explorer 5-Tier/9-Budget FHIR condenser + ClinicalEntityGraph + 4-Layer KB + Tier-0 recovery Local MLX / LM Studio / llama-router, UW Cloud GPU Auth Relay, OpenRouter
lab-laya-* & lab-exp-* Post-training & System-1 decision-layer lab Pinned Laya (~0.4B) entailment/admission encoders & fine-tuned LoRA/RLVR checkpoints Local Apple Silicon / PyTorch MPS, Linux CUDA / vLLM