One picture of the whole system — from questionnaire and uploaded documents, through the LLM readers, the rules, the Mayo ML models and the guideline knowledge base, to the two reports the platform hands back — followed by the decisions that are still open and what each option costs.
Read left to right. Intake produces a structured preoperative record; three engines read that record; their outputs are assembled into modules; a clinician approves; two reports go out. Colour encodes which engine produced a thing — that encoding is used everywhere on this page.
The architecture works because each engine is asked only the question it can answer well — and because one boundary is never crossed: the LLM does not adjust a validated number.
| Engine | Nature | Trusted for | Not trusted for | How it is validated | Where it lives |
|---|---|---|---|---|---|
| Rules | Deterministic code and lookup tables: guideline criteria coded as logic, medication hold/continue tables, CMS ASC and NSQIP list checks, risk bands. | Anything a guideline states as a criterion; anything that must be identical for two identical inputs; gating (eligibility, contraindications). | Estimating a probability; weighing many soft factors at once. | Unit tests against worked examples; each rule cites its source and version. | Your repo, versioned. Runs inside the API. |
| ML (Mayo) | Gradient-boosted trees released from the enclave as native LightGBM text: postop-complication bundle (80 models), RBC transfusion bundle (126), OR-time / LoS / ICU models, the four-axis acuity card. Calibrated, thresholded, with SHAP drivers. | Calibrated risk per outcome; expected blood units and an order-to-cover bound; time and length-of-stay estimates; ranking patients for triage. | Producing text; explaining why beyond feature contributions; anything outside its training population or the configuration's input set. | Golden test cases reproduce to documented tolerance (5e-7 / 5e-11) under pinned LightGBM 4.6; per-model leaf audit ≥ 10 patients; drift vs shipped reference distributions. | Scoring service in your container; artifacts in Blob Storage under versioned, hashed prefixes. |
| LLM + KB | Reads documents into schema-checked JSON; retrieves from versioned knowledge bases and drafts cited text; runs a consistency critic over the assembled result. | Extraction from unstructured text; turning a decision the rules or model already made into clear provider and patient wording; surfacing open questions; catching contradictions. | Changing a score. Deciding eligibility on its own. Uncited recommendations. | Extraction evals against gold labels; schema validation on every output; citation check; human confirmation of extracted fields. | Orchestrated by code in your repo (§4.2); provider behind a BAA in production. |
| Human | The clinician. | Confirming extracted fields; overriding any module with a reason; final approval. | — | Override reasons are logged and reviewed; they are the best signal for what to fix next. | Two interrupts in the flow: after extraction, before delivery. |
These mirror the bottom row of the working sketch. Each card names the engine mix — the same colours as the picture — and the honest state of the piece today.
Rules over the record propose a class; the LLM explains the drivers in prose. Clinician confirms.
Four LLM-extracted acuity axes → integer points → band. Validated against ASA and the UCLA grid; behaves as a rule once fitted.
CPT → wRVU, CMS ASC list, NSQIP list, procedure family. Deterministic from reference lists shipped with the bundle.
Postop-complication bundle: probability, reference rate, band, top drivers per outcome, per selected configuration.
RBC bundle: full unit distribution P(k), expected units, P90 (conformal), gate-then-size order recommendation. Calibration mandatory.
Ops models: median and 80 % interval for durations; expected LoS and ICU time. Resource planning, not risk.
Gate: CMS ASC list × acuity band × rules exclusions. The card supplies the patient side; the list supplies the procedure side.
Guideline criteria coded as rules decide which tests are indicated; the LLM retrieves the citation and writes the rationale.
Rules flag triggers (cardiology, sleep, anaesthesia clinic); the LLM drafts the referral question with the relevant findings.
Anaemia / iron, glycaemia, smoking, nutrition, prehab. Rules detect; KB supplies the pathway; LLM words it. Never subtracted from a risk number in the headline.
Hold / continue / bridge tables from the KB applied by rules to the reconciled list; LLM produces the patient-facing schedule.
Airway, access, monitoring and technique considerations retrieved from protocols and drafted for the anaesthesia team; cited.
Fasting, arrival, what to bring, what to stop — assembled from a versioned instruction library, EN / FR, reading level checked.
Open items the record cannot resolve (staging, planned approach, expected blood loss). Drafted by the LLM, listed for the clinician.
A critic pass over the assembled result: contradictions, missing confirmations, out-of-range inputs, uncited claims. Rules assert; the LLM explains.
Dated tasks for patient and team derived from the plan (repeat labs, stop smoking date, prehab sessions).
Seven choices shape the build. Each is drawn or tabled as a difference, with a recommendation. Tags: decided already settled in the 2026-07-30 plan · recommended · not advised.
| Option | Portable to Azure / AWS | PHI exposure | Human-in-the-loop & state | Effort | Lock-in |
|---|---|---|---|---|---|
| A · Plain services | Fully — a container | Stays in your cloud | Hand-built | Low for scoring, medium for the agent flow | None |
| B · LangGraph code + LangSmith | Fully — the graph is Python in your repo; LangSmith is an environment variable | Traces leave unless redacted or self-hosted; synthetic-only in staging | Built in (interrupts, checkpoints) | Medium | Low; observability is optional |
| C · Vendor-hosted / no-code builder | Only by self-hosting their runtime (enterprise terms) or rewriting | All payloads cross the boundary | Built in | Lowest to start | High |
| Component | Azure (chosen tenant) | AWS equivalent | Status |
|---|---|---|---|
| Front-end | Static Web Apps (Next.js static export, Entra ID gate, linked /api/*) | Amplify Hosting / S3 + CloudFront + Cognito | decided 2026-07-30 |
| API + engines | Container Apps (scale-to-zero, HTTPS) | App Runner / ECS Fargate | decided |
| Model artifacts | Blob Storage, versioned prefixes, immutable | S3 with object lock | decided |
| LLM | Azure OpenAI in-region (BAA available) — or the training-time model family for the _LLM configurations, see 4.5 | Bedrock | quota requested |
| Knowledge base store | Azure AI Search (hybrid vector + keyword) or Postgres + pgvector on Azure Database | OpenSearch / Aurora pgvector | pgvector first — one database also serves the LangGraph checkpointer |
| Workflow state | Azure Database for PostgreSQL | RDS Postgres | recommended |
| Observability | Application Insights (no payloads) + LangSmith (redacted) | CloudWatch + LangSmith | recommended |
| Later | Front Door + France Central region · AKS or Azure ML endpoints only if traffic or governance demands | Global Accelerator · EKS / SageMaker | deferred |
| Configuration | Inputs it needs | Calculator can supply | Verdict now |
|---|---|---|---|
| light_noICD_noLLM | ~15 NSQIP-style core variables | Nearly all, directly | first target |
| standard_ICD_noLLM | ~50 + 849 ICD presence flags | Core yes; ICD flags only if checkbox→ICD mapping is documented and validated | second, after the mapping audit |
| light_ICD_LLM · standard_ICD_LLM | + LLM acuity axes | Only via the note drop-zone, and only with the training-time extractor (4.5) | after extractor parity |
| full_ICD_LLM | ~1,700 features, most EHR-only | No — imputing ~1,300 unobserved axes misrepresents the model | not a calculator model · EHR phase |
| SUPER LIGHT (21) · WEB-BASED (42) | Form-sized tiers already defined in the feature file | Yes, by construction | train them (2026-07-30 plan, Option A); SUPER LIGHT = NSQIP's 21-input budget, a like-for-like comparison |
The llm_* features the models were trained on were produced by one specific instrument — the NB01b decomposed-acuity prompt on Gemini 2.5. An extractor that is a different model or a paraphrased prompt yields axes from a different distribution: no error, wrong risks. Two safe positions:
noLLM configurations._LLM configurationsThe question behind this one: should the combined logic — sources, rules, prompts, model calls, integration options — be authored on a visual canvas such as Langflow, with a Hoopcare UI on top, and LangSmith kept only for testing models and collecting metrics? It can. Whether it should depends on which part of the brain you mean.
| Option | What it is | Good at | Weak at | Portable | Verdict |
|---|---|---|---|---|---|
| Langflow canvas as the system of record | Open-source visual flow builder (MIT, self-hostable in Docker); flows export as JSON; custom components are Python; flows run behind Langflow's own API. | Prototyping a reader prompt or a RAG chain in minutes; letting non-engineers see the flow; swapping models to compare. | Diffing and code-reviewing a JSON canvas; unit-testing branches; expressing deterministic clinical rules; versioning tied to the model contract; a Hoopcare UI on top inherits Langflow's API and component model. Its server has had a critical unauthenticated code-execution vulnerability (2025) — self-host internal-only, authenticated, patched. | Yes — Docker on Azure or AWS; JSON + Python travel | not as the source of truth |
| LangGraph code + LangGraph Studio + your own console | The graph is Python in your repo (§4.2 B); Studio renders that graph visually from the code; a thin internal console (the same Next.js stack as the calculator) shows registry, versions, KB snapshots, prompt hashes, eval results. | Testable, reviewable, versioned with the models; the picture is generated from the code so it can never drift from it; human-in-the-loop built in. | Editing requires a developer; the console is something you build. | Yes — the graph moves with the container | recommended for the brain |
| Hybrid: Langflow to prototype, code to ship | Explore reader prompts, retrieval settings and model choices on the canvas; once a chain is right, promote it into the repo as a graph node with tests and a golden set. | Speed of iteration where it helps; rigour where it matters. | Two places to look during the transition; needs a rule for what "promoted" means. | Yes | practical middle |
| LangSmith for evals and metrics | Datasets, model-versus-model comparisons, standard metrics, tracing — for any of the three above. | Exactly the "test different models and get standard metrics" job. | Traces leave your cloud unless redacted or self-hosted (§5). | Datasets and results export | yes, as a side channel |
| Staging (now) | Production (later) | |
|---|---|---|
| Patients | Synthetic only — the schema has no identifier fields, so there is nowhere to put one decided | Real, under BAA-covered services and a private network |
| Pasted notes | Processed in memory, never persisted; no note text in logs or traces; click-through acknowledgement before the panel opens | Same, plus retention rules and audit |
| LLM calls | Azure OpenAI in-region | Provider under BAA; the _LLM configurations require extractor parity (4.5) |
| Traces / evals | LangSmith with hide_inputs / hide_outputs or an anonymiser, or App Insights without payloads | Self-hosted observability inside the tenant, or BAA |
| Access | Entra ID + e-mail allowlist; "research use only — not for clinical decision-making" on every output | Institution SSO; role-based; audit log |
| Regulatory posture | Authenticated research tool for named collaborators | Confirm SaMD / MDR position before any patient-facing use; confirm the export approval covers external hosting |
Every report prints one version string. It resolves to a manifest that pins everything that could change the answer:
| Component | Versioned as | Lives in |
|---|---|---|
| Model bundles | content hash per (bundle, configuration, outcome); manifest with feature order, calibrator, thresholds, reference rates, golden cases, LightGBM version | Blob, immutable prefix; registry.json in the repo |
| Field schema | field_schema.json — the form, the validation and the API contract are generated from it decided | bundle |
| Rules | semantic version; each rule cites its source and effective date | repo |
| Prompts | hash + name per reader and per drafting task; the training-time extractor prompt is pinned separately | repo (LangSmith prompt hub optional, exported) |
| Knowledge bases | snapshot id per KB with document list and dates | Blob + vector store |
| Thresholds & bands | per outcome, per configuration; derived on the test split at training, re-derived per site later | bundle |
The bundle layout from the 2026-07-30 plan — MANIFEST.json · models/{outcome}.txt · imputation.json · calibration.json · metrics.json · reference_rates.json · field_schema.json — is the unit that moves. Adding a configuration is a second bundle, not a second front-end.
| Phase | What ships | Engines live | Depends on |
|---|---|---|---|
| 0 · Artifact | Inventory the released bundle; reproduce golden cases under pinned LightGBM 4.6; per-configuration feature-availability table; locate calibrators and thresholds | — | the bundle files (deployment prompt, §2) |
| 1 · Skeleton | SWA + Container Apps + domain + Entra gate; stub predictor; CI with golden cases; API contract v1 with version selection | Rules (schema, bands) | nothing — start now |
| 2 · Scoring | Real bundle behind /predict; schema-driven form; results with reference rates, drivers, named imputations; version selector | Rules · ML | 0 + 1 |
| 3 · Reading | Note drop-zone → /extract → visible pre-fill → clinician confirm; document readers one type at a time (ECG, labs first); extraction evals | + LLM (upstream) | 2 |
| 4 · Modules & reports | KB snapshots + retrieval; testing / referral / medication / instruction modules; consistency check; provider report then patient report; sign-off flow | + KB | 3 |
| 5 · Reach | France Central + Front Door; SUPER LIGHT / WEB-BASED tiers if trained; FHIR adapter design; SaMD position confirmed before any patient-facing use | all | demand |
Sources: working sketch "Hoopcare Preop AI-Agent, August 2026"; ai.hoopcare.com architecture plan (2026-07-30) and setup runbook (2026-08-03); NB12 / NB21 / RBC handoffs; deployment prompt for the released bundle.
Today: one personal GitHub account with three private repos. Target: one GitHub organisation, a small number of repos with clear ownership, and one shared brain consumed by every user-facing app as a service with a published contract — never by copying its source.
| Repository | Contains | Publishes | Owner | Note |
|---|---|---|---|---|
| perioperative-ai | contract/ field schema, OpenAPI, FHIR mapping, thresholds, reference rates · rules/ with tests and citations · readers/ prompts + eval sets · graphs/ LangGraph flows · knowledge/ KB pipeline + snapshot manifests · models/ registry, loader, calibration, golden cases · reports/ EN/FR templates · service/ FastAPI · evals/ | container image; @hoopcare/perioperative-ai-client (TS) and a Python client, both generated from the contract; registry.json | clinical-ai team (you) · CODEOWNERS on rules/ and contract/ | The single source of truth for medical logic. Semantic versions; the report's contract version = brain release + bundle hash. |
| surgery-risk-calculator | NSQIP-like calculator, Epic-like browser simulator, demo data; two apps in one small TS workspace if they share components | SWA build | you | Synthetic only, Entra-gated. Pins a brain client version. |
| patient-app (v3) | direct-to-patient app | SWA / mobile build | you | Same brain, patient-report endpoint. Consider whether hoopcare-patients already is this repo. |
| v2 · clinical-dashboard, patient, back-office | as today | their pipeline | platform team | Move into the org unchanged; adopt the brain client when a v2 screen needs a module. |
| infra | Bicep / az scripts per environment; GitHub Environments with required reviewers; OIDC federated credentials to Azure (no long-lived secrets) | — | platform team | dev · stg · prod-us · prod-fr; the calculator demo deploys to stg-like resources. |
| rag-perioperative-guidelines | today: a separate Python repo | — | you | Fold the pipeline code into perioperative-ai/knowledge/; keep the documents and snapshots in Blob (size and licensing), with only manifests in git. |
registry.json; guideline PDFs → Blob; secrets → Key Vault and environment secrets; anything resembling PHI → nowhere.rules/, readers/ and contract/ requires your review; every rule cites its source and effective date.ai.hoopcare.com is the internal workspace: one Next.js shell, one auth realm (Entra ID allowlist), route groups per section, the brain linked at /api/v1. Three ideas organise the menu: /brain is everything that defines an answer; /clinical-review is the evidence about those answers; /demo is where you try it. Nested in the menu, flat and deep-linkable in the URLs. The real patient app is the exception — different identity provider, real PHI, per-region — it gets its own host (patients.hoopcare.com) when it ships.
| Path | Section | What it shows | Reads from |
|---|---|---|---|
| / | Home | members only · environment banner · "research use only" | — |
| /docs/ | Documentation | overview · architecture (this page) · contract · model cards · changelog | repo docs |
| /demo/ | Surgical calculator + Epic-like simulator | synthetic only · version selector · fake patient flow | brain API · /clinical-review/synthetic |
| /brain/ | The brain | map engines map generated from the code · chains LLM readers & drafting flows — the visual builder · rules deterministic logic with citations and effective dates · prompts versions + linked eval sets · models registry: bundles, configurations, hashes, golden status, thresholds, reference distributions, model cards · knowledge KB ingestion, snapshots, coverage, citation checks · reports provider / patient templates EN / FR · playground run any module on a synthetic case | perioperative-ai repo · registry.json · Blob |
| /clinical-review/ | Benchmark & continuous evaluation | metrics model vs model, extraction evals, calibration, drift · queue clinicians grade outputs against a rubric; disagreements feed the next release · cases every run: inputs, version, outputs, overrides and reasons, trace link · synthetic the shared fake-patient library used by demo, evals and playground | API log · evals · LangSmith (redacted) |
| /developer/ | Developer | OpenAPI · client packages · sandbox keys · FHIR mapping · SMART-launch test in the simulator | contract |
| /status/ | Status | deployed version per environment · golden-case checks · ML drift alerts · LLM endpoint health · cost | CI · App Insights · LangSmith |
| /admin/ | Admin | allowlist · roles · environments · feature flags · region | — |
| patients.hoopcare.com | Real patient app (v3), later | separate host: Entra External ID, PHI, per-region; same repo family and pipeline | brain API · patient-report endpoint |
| Need | Where it surfaces | Build or buy |
|---|---|---|
| Tracing — runs, latency, tokens, cost per case | /clinical-review/cases → trace link | LangSmith, redacted; App Insights for the ML/API side |
| Datasets, offline evals, experiment comparison ("test different models") | /clinical-review/metrics | LangSmith; gold sets live in the repo |
| Human grading of outputs against a clinical rubric | /clinical-review/queue | build — PHI-safe, override reasons, inter-rater agreement; push scores to LangSmith optionally |
| Online evaluators on sampled live traces (schema validity, citation present) | metrics · drift | LangSmith |
| Feedback from clinicians attached to the run | queue → metrics | LangSmith feedback API or your own table, kept in sync |
| Prompt versions and playground | /brain/prompts · /brain/playground | repo is the source of truth; hub optional |
| Trace → dataset ("add this case to the gold set") | queue → metrics | LangSmith |
| Regression tests in CI — eval score below threshold blocks the release | CI gate | LangSmith SDK + pytest |
| ML monitoring — LightGBM calibration drift, input drift vs shipped reference distributions, golden checks per configuration | /status · /clinical-review/metrics | build — LangSmith is LLM-centric |
| Rules coverage and audit — which rules fired, source, version | /clinical-review/cases | build |
| Safety evals — prompt injection on readers, out-of-scope inputs, PHI-leak check on the patient report | metrics · CI | build, run in CI |
| Region and retention — prod-fr traces stay in the EU | — | LangSmith EU region or self-hosted; short retention |