Architecture & upgrade
How a backend-only EEG research repo became a deployable, multi-agent, hybrid-inference clinical product — without throwing away the deep-learning engine underneath.
What changed
InterfaceBackend-only Python, no UI Next.js 15 + React 19 web app, deployable to Vercel
InferenceHard-wired Llama 3.1 on a 12 GB GPU Hybrid layer — local GPU (Ollama/vLLM) or any API, per agent
OrchestrationMonolithic request handler 7-agent streaming pipeline with a safety critic
KnowledgeNeo4j + Qdrant (heavy infra) Portable in-memory GraphRAG over the same ontologies
TestabilityRequired full Docker stack Zero-key live demo runs in the browser
Signal stackMNE + CUDA dependencies NumPy/SciPy pipeline runs anywhere, GPU optional
Request flow
Browser (Next.js) FastAPI backend
───────────────── ───────────────
upload EEG ──► POST /api/analyze ─────────► load_signal() (CSV/EDF/NPY/JSON)
(multipart + SSE) │
▼
◄──── data: {stage:"signal",running} ─── Signal Analyst (filter, FFT, features)
◄──── data: {stage:"triage",...} ─────── Triage (urgency)
◄──── data: {stage:"retriever",...} ──── Knowledge RAG (ICD-10/SNOMED/RxNorm)
◄──── data: {stage:"diagnostician"} ──── Diagnostician ┐
◄──── data: {stage:"pharmacologist"} ─── Pharmacologist ├─ each on its own LLM
◄──── data: {stage:"critic",...} ─────── Safety Critic ┘ (local GPU OR API)
◄──── data: {stage:"reporter",...} ───── Reporter
◄──── data: {type:"result", ...} ────── final report
◄──── data: {type:"done"}
No backend? → the same event shape is generated client-side (offline demo).The agents
1. Signal Analyst
EEG preprocessing & feature extraction
2. Triage Agent
Acuity & urgency assessment
3. Knowledge Retriever
GraphRAG over ICD-10 / SNOMED / RxNorm
4. Diagnostician
Differential diagnosis reasoning
5. Pharmacologist
Drug-drug interaction safety
6. Safety Critic
Self-correction & guardrails
7. Reporter
Clinical report synthesis
API surface
POST
/api/analyzeMultipart upload → SSE multi-agent runPOST
/api/analyze/sampleJSON {dataset_id} → SSE runPOST
/api/chatSSE token stream from the copilotGET
/api/knowledge-graphICD-10 / SNOMED / RxNorm graphGET
/api/providersLLM provider catalog (local + hosted)GET
/api/agentsMulti-agent rosterGET
/api/samplesBuilt-in demo datasetsGET
/healthLiveness + provider statusPortable runtime
- FastAPI + SSE
- NumPy/SciPy DSP
- In-memory GraphRAG
- Deterministic demo engine
- No GPU required to run
Deep-learning engine (src/)
- CNN-LSTM seizure detector
- Transformer sleep stager
- Mamba2 long-context SSM
- Llama 3.1 8B QLoRA
- Spiking NN event detector
Run it locally
Backend: uvicorn app.main:app · Frontend: npm run dev