# wuxb02/medi-agent-swarm architecture

> Architecture diagram of the GitHub repository wuxb02/medi-agent-swarm, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-10-14). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/wuxb02/medi-agent-swarm
- Repository: https://github.com/wuxb02/medi-agent-swarm

## Overview

MediZJ is a multi-agent medical assistant with CLI and Vue/FastAPI web access. The main web workflow accepts a question, can gather structured medical background, delegates work to agents, retrieves version-governed medical evidence, validates the answer, then streams the result and citations. Major companion capabilities include persistent session and personal memory, image understanding, knowledge administration, conversation-driven evolution, and trace dashboards. The README documents these product stages; several backend modules were not sampled, so their internal call details are not inferred.

Main entry points: [`mediZJ/swarm/swarm_coordinator.py`](https://github.com/wuxb02/medi-agent-swarm/blob/main/mediZJ/swarm/swarm_coordinator.py) (Swarm coordinator), [`mediZJ/api/services/run_service.py`](https://github.com/wuxb02/medi-agent-swarm/blob/main/mediZJ/api/services/run_service.py) (Run lifecycle), [`mediZJ/knowledge/milvus_kb.py`](https://github.com/wuxb02/medi-agent-swarm/blob/main/mediZJ/knowledge/milvus_kb.py) (Medical retrieval), [`mediZJ/api/main.py`](https://github.com/wuxb02/medi-agent-swarm/blob/main/mediZJ/api/main.py) (FastAPI application)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_experience["User experience"]
  node_web["Web interface"]
  node_api["FastAPI application<br/>[main.py]"]
  node_chat_routes["Chat endpoints<br/>[chat.py]"]
  node_run_service["Run lifecycle<br/>[run_service.py]"]
  node_image["Image analysis<br/>[image_analyzer.py]"]
  node_trace_ui["Trace dashboard<br/>[TraceView.vue]"]
end

subgraph group_orchestration["Agent orchestration"]
  node_clarification["Questionnaire"]
  node_swarm["Swarm coordinator"]
  node_supervisor["Agent graph"]
  node_worker["Agent worker<br/>[worker.py]"]
  node_skills["Skill and tool loading<br/>[skill_loader.py]"]
  node_llm["LLM client<br/>[llm_client.py]"]
end

subgraph group_knowledge["Knowledge and safety"]
  node_retrieval["Medical retrieval<br/>[milvus_kb.py]"]
  node_catalog["Knowledge catalog<br/>[catalog.py]"]
  node_candidate["Knowledge candidates"]
  node_validation["Answer validation<br/>[medical_answer.py]"]
end

subgraph group_state["State and governance"]
  node_memory["Memory services"]
  node_session_store[("Session persistence<br/>[session_db.py]")]
  node_evolution["Conversation evolution<br/>[service.py]"]
  node_evolution_store[("Evolution storage<br/>[storage.py]")]
end

subgraph group_operations["Operations and observability"]
  node_infrastructure["Infrastructure services"]
  node_trace["Trace collection<br/>[context.py]"]
end

node_patient(("Patient"))
node_mysql[("MySQL")]
node_redis[("Redis")]
node_milvus[("Milvus")]
node_vision(("Vision model"))

node_patient -->|"asks question"| node_web
node_web -->|"sends requests"| node_api
node_api -->|"routes requests"| node_chat_routes
node_chat_routes -.->|"starts runs"| node_run_service
node_run_service -->|"runs agents"| node_swarm
node_swarm -->|"asks background"| node_clarification
node_clarification -->|"streams questionnaire"| node_web
node_swarm -->|"dispatches work"| node_supervisor
node_supervisor -->|"executes subtasks"| node_worker
node_worker -->|"activates skills"| node_skills
node_worker -.->|"requests completion"| node_llm
node_swarm -->|"gathers evidence"| node_retrieval
node_retrieval -->|"checks active versions"| node_catalog
node_retrieval -->|"searches vectors"| node_milvus
node_swarm -->|"validates answer"| node_validation
node_validation -->|"returns safe result"| node_run_service
node_run_service -->|"streams result"| node_web
node_chat_routes -.->|"analyzes uploads"| node_image
node_image -->|"parses image"| node_vision
node_swarm -->|"loads context"| node_memory
node_memory -.->|"reads sessions"| node_session_store
node_session_store -->|"persists sessions"| node_mysql
node_memory -->|"stores working memory"| node_redis
node_retrieval -.->|"reads catalog"| node_mysql
node_candidate -->|"checks evidence"| node_catalog
node_run_service -.->|"queues review"| node_evolution
node_evolution -->|"persists evaluations"| node_evolution_store
node_evolution_store -->|"stores strategies"| node_mysql
node_run_service -->|"records execution"| node_trace
node_trace_ui -.->|"requests traces"| node_api
node_api -->|"starts services"| node_infrastructure
node_infrastructure -->|"manages database"| node_mysql
node_infrastructure -->|"initializes cache"| node_redis

click node_web "https://github.com/wuxb02/medi-agent-swarm/tree/main/frontend/src"
click node_api "https://github.com/wuxb02/medi-agent-swarm/blob/main/mediZJ/api/main.py"
click node_chat_routes "https://github.com/wuxb02/medi-agent-swarm/blob/main/mediZJ/api/routers/chat.py"
click node_run_service "https://github.com/wuxb02/medi-agent-swarm/blob/main/mediZJ/api/services/run_service.py"
click node_image "https://github.com/wuxb02/medi-agent-swarm/blob/main/mediZJ/api/services/image_analyzer.py"
click node_clarification "https://github.com/wuxb02/medi-agent-swarm/blob/main/mediZJ/core/questionnaire_manager.py"
click node_swarm "https://github.com/wuxb02/medi-agent-swarm/blob/main/mediZJ/swarm/swarm_coordinator.py"
click node_supervisor "https://github.com/wuxb02/medi-agent-swarm/blob/main/mediZJ/lgraph/supervisor_graph.py"
click node_worker "https://github.com/wuxb02/medi-agent-swarm/blob/main/mediZJ/lgraph/worker.py"
click node_skills "https://github.com/wuxb02/medi-agent-swarm/blob/main/mediZJ/core/skill_loader.py"
click node_llm "https://github.com/wuxb02/medi-agent-swarm/blob/main/mediZJ/core/llm_client.py"
click node_retrieval "https://github.com/wuxb02/medi-agent-swarm/blob/main/mediZJ/knowledge/milvus_kb.py"
click node_catalog "https://github.com/wuxb02/medi-agent-swarm/blob/main/mediZJ/knowledge/catalog.py"
click node_candidate "https://github.com/wuxb02/medi-agent-swarm/blob/main/mediZJ/knowledge/candidate_service.py"
click node_validation "https://github.com/wuxb02/medi-agent-swarm/blob/main/mediZJ/validation/medical_answer.py"
click node_memory "https://github.com/wuxb02/medi-agent-swarm/tree/main/mediZJ/memory"
click node_session_store "https://github.com/wuxb02/medi-agent-swarm/blob/main/mediZJ/memory/session_db.py"
click node_evolution "https://github.com/wuxb02/medi-agent-swarm/blob/main/mediZJ/evolution/service.py"
click node_evolution_store "https://github.com/wuxb02/medi-agent-swarm/blob/main/mediZJ/evolution/storage.py"
click node_infrastructure "https://github.com/wuxb02/medi-agent-swarm/tree/main/mediZJ/infrastructure"
click node_trace "https://github.com/wuxb02/medi-agent-swarm/blob/main/mediZJ/trace/context.py"
click node_trace_ui "https://github.com/wuxb02/medi-agent-swarm/blob/main/frontend/src/views/TraceView.vue"

classDef toneNeutral fill:#f8fafc,stroke:#334155,stroke-width:1.5px,color:#0f172a
classDef toneBlue fill:#dbeafe,stroke:#2563eb,stroke-width:1.5px,color:#172554
classDef toneAmber fill:#fef3c7,stroke:#d97706,stroke-width:1.5px,color:#78350f
classDef toneMint fill:#dcfce7,stroke:#16a34a,stroke-width:1.5px,color:#14532d
classDef toneRose fill:#ffe4e6,stroke:#e11d48,stroke-width:1.5px,color:#881337
classDef toneIndigo fill:#e0e7ff,stroke:#4f46e5,stroke-width:1.5px,color:#312e81
classDef toneTeal fill:#ccfbf1,stroke:#0f766e,stroke-width:1.5px,color:#134e4a
class node_web,node_api,node_chat_routes,node_run_service,node_image,node_trace_ui toneBlue
class node_clarification,node_swarm,node_supervisor,node_worker,node_skills,node_llm,node_mysql,node_redis,node_milvus toneAmber
class node_retrieval,node_catalog,node_candidate,node_validation toneMint
class node_memory,node_session_store,node_evolution,node_evolution_store toneRose
class node_infrastructure,node_trace,node_patient,node_vision toneIndigo
```

## Components

### User experience

- [Web interface](https://github.com/wuxb02/medi-agent-swarm/tree/main/frontend/src): `frontend/src`
- [FastAPI application](https://github.com/wuxb02/medi-agent-swarm/blob/main/mediZJ/api/main.py): `mediZJ/api/main.py`
- [Chat endpoints](https://github.com/wuxb02/medi-agent-swarm/blob/main/mediZJ/api/routers/chat.py): `mediZJ/api/routers/chat.py`
- [Run lifecycle](https://github.com/wuxb02/medi-agent-swarm/blob/main/mediZJ/api/services/run_service.py): `mediZJ/api/services/run_service.py`
- [Image analysis](https://github.com/wuxb02/medi-agent-swarm/blob/main/mediZJ/api/services/image_analyzer.py): `mediZJ/api/services/image_analyzer.py`
- [Trace dashboard](https://github.com/wuxb02/medi-agent-swarm/blob/main/frontend/src/views/TraceView.vue): `frontend/src/views/TraceView.vue`

### Agent orchestration

- [Questionnaire](https://github.com/wuxb02/medi-agent-swarm/blob/main/mediZJ/core/questionnaire_manager.py): `mediZJ/core/questionnaire_manager.py`
- [Swarm coordinator](https://github.com/wuxb02/medi-agent-swarm/blob/main/mediZJ/swarm/swarm_coordinator.py): `mediZJ/swarm/swarm_coordinator.py`
- [Agent graph](https://github.com/wuxb02/medi-agent-swarm/blob/main/mediZJ/lgraph/supervisor_graph.py): `mediZJ/lgraph/supervisor_graph.py`
- [Agent worker](https://github.com/wuxb02/medi-agent-swarm/blob/main/mediZJ/lgraph/worker.py): `mediZJ/lgraph/worker.py`
- [Skill and tool loading](https://github.com/wuxb02/medi-agent-swarm/blob/main/mediZJ/core/skill_loader.py): `mediZJ/core/skill_loader.py`
- [LLM client](https://github.com/wuxb02/medi-agent-swarm/blob/main/mediZJ/core/llm_client.py): `mediZJ/core/llm_client.py`

### Knowledge and safety

- [Medical retrieval](https://github.com/wuxb02/medi-agent-swarm/blob/main/mediZJ/knowledge/milvus_kb.py): `mediZJ/knowledge/milvus_kb.py`
- [Knowledge catalog](https://github.com/wuxb02/medi-agent-swarm/blob/main/mediZJ/knowledge/catalog.py): `mediZJ/knowledge/catalog.py`
- [Knowledge candidates](https://github.com/wuxb02/medi-agent-swarm/blob/main/mediZJ/knowledge/candidate_service.py): `mediZJ/knowledge/candidate_service.py`
- [Answer validation](https://github.com/wuxb02/medi-agent-swarm/blob/main/mediZJ/validation/medical_answer.py): `mediZJ/validation/medical_answer.py`

### State and governance

- [Memory services](https://github.com/wuxb02/medi-agent-swarm/tree/main/mediZJ/memory): `mediZJ/memory`
- [Session persistence](https://github.com/wuxb02/medi-agent-swarm/blob/main/mediZJ/memory/session_db.py): `mediZJ/memory/session_db.py`
- [Conversation evolution](https://github.com/wuxb02/medi-agent-swarm/blob/main/mediZJ/evolution/service.py): `mediZJ/evolution/service.py`
- [Evolution storage](https://github.com/wuxb02/medi-agent-swarm/blob/main/mediZJ/evolution/storage.py): `mediZJ/evolution/storage.py`

### Operations and observability

- [Infrastructure services](https://github.com/wuxb02/medi-agent-swarm/tree/main/mediZJ/infrastructure): `mediZJ/infrastructure`
- [Trace collection](https://github.com/wuxb02/medi-agent-swarm/blob/main/mediZJ/trace/context.py): `mediZJ/trace/context.py`

### Other components

- **Patient**
- **MySQL**
- **Redis**
- **Milvus**
- **Vision model**

## Connections

- Patient → Web interface: asks question
- Web interface → FastAPI application: sends requests
- FastAPI application → Chat endpoints: routes requests (evidence: `mediZJ/api/main.py`)
- Chat endpoints → Run lifecycle: starts runs
- Run lifecycle → Swarm coordinator: runs agents (evidence: `mediZJ/api/services/run_service.py`)
- Swarm coordinator → Questionnaire: asks background
- Questionnaire → Web interface: streams questionnaire
- Swarm coordinator → Agent graph: dispatches work (evidence: `mediZJ/swarm/swarm_coordinator.py`)
- Agent graph → Agent worker: executes subtasks
- Agent worker → Skill and tool loading: activates skills (evidence: `mediZJ/lgraph/worker.py`)
- Agent worker → LLM client: requests completion (evidence: `mediZJ/lgraph/worker.py`)
- Swarm coordinator → Medical retrieval: gathers evidence
- Medical retrieval → Knowledge catalog: checks active versions (evidence: `mediZJ/knowledge/milvus_kb.py`)
- Medical retrieval → Milvus: searches vectors
- Swarm coordinator → Answer validation: validates answer
- Answer validation → Run lifecycle: returns safe result
- Run lifecycle → Web interface: streams result
- Chat endpoints → Image analysis: analyzes uploads
- Image analysis → Vision model: parses image
- Swarm coordinator → Memory services: loads context (evidence: `mediZJ/swarm/swarm_coordinator.py`)
- Memory services → Session persistence: reads sessions
- Session persistence → MySQL: persists sessions (evidence: `mediZJ/memory/session_db.py`)
- Memory services → Redis: stores working memory
- Medical retrieval → MySQL: reads catalog
- Knowledge candidates → Knowledge catalog: checks evidence (evidence: `mediZJ/knowledge/candidate_service.py`)
- Run lifecycle → Conversation evolution: queues review
- Conversation evolution → Evolution storage: persists evaluations (evidence: `mediZJ/evolution/service.py`)
- Evolution storage → MySQL: stores strategies (evidence: `mediZJ/evolution/storage.py`)
- Run lifecycle → Trace collection: records execution (evidence: `mediZJ/api/services/run_service.py`)
- Trace dashboard → FastAPI application: requests traces
- FastAPI application → Infrastructure services: starts services (evidence: `mediZJ/api/main.py`)
- Infrastructure services → MySQL: manages database (evidence: `mediZJ/infrastructure/database.py`)
- Infrastructure services → Redis: initializes cache (evidence: `mediZJ/infrastructure/redis_client.py`)
