/ws/analyze WebSocket endpoint provides real-time streaming of the analysis pipeline, allowing clients to receive incremental updates as each agent completes its work.
Endpoint
Connection Flow
- Client connects to the WebSocket endpoint
- Client sends initial JSON payload with patient text
- Server streams progress updates as
statusevents - Server streams agent results as
agent_resultevents - Server sends final
completeevent with SOAP note and debate state - Connection closes
Initial Request
After connecting, send a JSON payload:Clinical text to analyze (patient presentation, symptoms, history)
Example
Event Types
The server sends different event types during the analysis:Status Event
Progress updates during processing.Always
"status"Current pipeline stage:
"parsing", "agents", "debate", "synthesis", "safety_panel"Human-readable description of current operation
Agent Result Event
Streamed when each agent completes.Always
"agent_result"Agent name:
"clinical", "literature", "safety", "critic"Agent-specific output (see Agent Outputs)
Complete Event
Final result with synthesized SOAP note.Always
"complete"Final SOAP note (see SOAP Note model)
Complete debate state with all agent outputs
Medication safety analysis results
Error Event
Sent if analysis fails.Always
"error"Error description
Example Client (JavaScript)
Example Client (Python)
Pipeline Stages
The WebSocket streams through these stages:- parsing - Anonymizes and parses clinical input into structured PatientContext
- agents - Runs Clinical Agent (differential diagnosis, risk scores)
- agents - Runs Literature and Safety Agents in parallel
- debate - Critic Agent reviews all outputs
- synthesis - Generates final SOAP note from debate consensus
- safety_panel - Runs comprehensive medication error prevention checks
Error Handling
- If
textis missing, server sends error and closes connection - If analysis fails mid-stream, server sends error event
- Client should handle
WebSocketDisconnectgracefully - All errors are logged server-side for debugging
The WebSocket endpoint uses the same analysis pipeline as
/api/analyze but provides incremental updates for better UX in interactive applications.