Consultation Agent
Ed DonnerStreaming consultation agent behind FastAPI. Verifies Clerk JWT, then streams a frontier-model reply over SSE for the clinician form to render as markdown.
FastAPI · Clerk JWT · OpenAI stream · SSE · ReactMarkdown
Overview
Layer 4 on the Mental Model. The Consultation agent is a single streaming path behind FastAPI: verify Clerk JWT, then stream a frontier-model reply over SSE for the clinician form.
Behavior
- Auth before inference. No consultation stream without a verified JWT (
ClerkHTTPBearer+ JWKS). - Server-side model only. The UI posts notes; FastAPI owns the OpenAI call and SSE deltas.
- Fixed three-section reply. System prompt asks for visit summary, next steps for the doctor, and a patient-friendly draft email.
- Stream then render. Tokens arrive as SSE; the client renders markdown as they land.
- Prompt Chaining. Visit fields → structured sections in one streamed completion. See Building effective agents.
Consultation flow
One signed-in clinician consultation. Diagram key: ✦ AI agent · second line = Anthropic workflow · purple = actor · white = service.
---
config:
theme: default
themeVariables:
background: "#ffffff"
fontSize: "14px"
---
flowchart TB
person[Clinician]
form[Product form]
api["POST /api/consultation"]
clerk[Clerk JWKS verify]
consultation["✦ Consultation
Prompt Chaining"]
model["OpenAI stream
gpt-5-nano"]
sse[SSE deltas]
md[ReactMarkdown reply]
person -->|submit notes| form -->|Bearer JWT| api
api --> clerk --> consultation
consultation --> model --> sse --> md --> person
classDef agent fill:#e8f0ee,stroke:#0f3d36,stroke-width:2px,color:#0d0d0d
classDef service fill:#fafaf8,stroke:#c8c8c2,stroke-width:1px,color:#0d0d0d
classDef actor fill:#f3eef8,stroke:#6b4f9a,stroke-width:2px,color:#0d0d0d
class consultation agent
class form,api,clerk,model,sse,md service
class person actor
Route: POST /api/consultation. Delivery: SSE to the form page. Research deployment only — not a licensed clinical product.
Research deployment only. Layer map on Mental Model. Part of Project.