Skip to content

zHaooJ/Medical-Agent-System

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

1 Commit
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

DoctorAgent Clinical Workflow System

License: MIT Python FastAPI LangGraph Medical AI

项目概览 · 环境搭建 · 架构设计 · Agent 原理 · RAG 与 Milvus · API 与 FHIR · HIPAA 设计 · 部署运维

Disclaimer: This repository is a research and engineering demo. It is not intended to provide medical advice, diagnosis, treatment, or clinical decision support in production.

基于 LangGraph + FastAPI 构建的医疗问诊工作流,复用现有 DoctorAgent 作为前半段主控智能体。

当前实现采用下面这条主链路:

Intake (message normalization)
  -> Diagnosis (DoctorAgent consultation turn + embedded RAG)
  -> Treatment (optional)
  -> Coding (optional, default off)
  -> Audit (optional, default on)

其中:

  • Intake 不再做一次性 LLM 结构化,只负责标准化本轮患者输入
  • Diagnosis 节点内部复用 doctor-agent-servingDialogueLoop.step()
  • DoctorAgent 自带的 RAG 仍然走 BM25 + MedCPT + FAISS
  • Treatment / Coding / Audit 作为可配置的尾链节点保留

快速开始

cd /data1/zenghao/work/try02/medical-multi-agent-system-python
pip install -r requirements.txt
cp .env.example .env

编辑 .env 至少填这些项:

DOCTOR_MODEL_PATH=/path/to/doctor/checkpoint
DOCTOR_DEVICE=cuda:0
OPENAI_API_KEY=your-openai-key

如果你只想先跑 Doctor 问诊主链路,可以保留默认:

ENABLE_TREATMENT=true
ENABLE_CODING=false
ENABLE_AUDIT=true

启动服务:

uvicorn src.api.main:app --reload --port 8000

主要接口

1. 多轮聊天接口

curl -X POST http://127.0.0.1:8000/api/v1/clinical/chat \
  -H "Content-Type: application/json" \
  -d '{
        "session_id": "demo-session-001",
        "patient_message": "我最近右下腹痛两天了",
        "max_turns": 10
      }'

返回示例:

{
  "session_id": "demo-session-001",
  "doctor_response": "Question: 疼痛有没有伴随发热、恶心或呕吐?",
  "action": {
    "action_type": "question"
  },
  "done": false,
  "needs_more_info": true
}

当 Doctor 完成诊断后,响应里会附带:

  • patient_info
  • diagnosis
  • treatment_plan(如果开启)
  • coding_result(如果开启)
  • audit_result(如果开启)

2. 兼容 analyze 接口

为了兼容原项目,保留了:

POST /api/v1/clinical/analyze

它本质上会把 patient_description 当作首轮 patient_message 路由到同一个 DoctorAgent 工作流。

3. 保留的工具接口

  • POST /api/v1/clinical/icd10/search
  • GET /api/v1/clinical/icd10/{code}
  • POST /api/v1/clinical/ddi/check

配置说明

DoctorAgent 相关

  • DOCTOR_SERVING_ROOT doctor-agent-serving 目录路径
  • DOCTOR_MODEL_PATH Doctor 模型 checkpoint 路径
  • DOCTOR_DEVICEcuda:0
  • DOCTOR_MAX_TURNS 会话最大轮次
  • DOCTOR_MAX_RETRIEVES RAG 最大触发次数

RAG 相关

  • RAG_DB_DIR MedRAG corpus 路径。当前默认建议指向已经完成本地索引构建的: /data1/zenghao/work/try01/MedRAG_try01/corpus
  • RAG_RETRIEVER 默认 Milvus-RRF-2。可选: RRF-2Milvus-MedCPTMilvus-RRF-2
  • RAG_CORPUS 默认 Textbooks
  • RAG_TOP_K 默认 16
  • RAG_MILVUS_DB_PATH Milvus Lite 本地数据库文件路径,默认: /data1/zenghao/work/try01/MedRAG_try01/corpus/_milvus/medrag_lite.db
  • RAG_MILVUS_COLLECTION_PREFIX Milvus collection 前缀,默认 medrag
  • MEDRAG_SRC MedRAG src 路径
  • HF_HOME 本地 Hugging Face 缓存目录
  • TRANSFORMERS_OFFLINE 默认建议 true,优先走本地缓存
  • HF_HUB_OFFLINE 默认建议 true,避免运行时重新访问远端

Milvus Lite 向量库构建

这版默认将稠密检索升级为 Milvus Lite 持久化向量库,复用已有 MedCPT article embeddings,不需要重新计算 embedding。

构建命令:

/home/zenghao/anaconda3/envs/medla_py310/bin/python scripts/build_milvus_index.py \
  --db-dir /data1/zenghao/work/try01/MedRAG_try01/corpus \
  --medrag-src /data1/zenghao/work/try02/MedRAG_try01/src \
  --corpus Textbooks \
  --retriever Milvus-MedCPT

检索模式说明:

  • Milvus-MedCPT: 纯向量检索,MedCPT query encoder -> Milvus Lite
  • Milvus-RRF-2: BM25 + Milvus-MedCPT 混合召回,经 RRF 融合
  • RRF-2: 旧版 BM25 + FAISS(MedCPT),保留用于对照

Tail Pipeline 开关

  • ENABLE_TREATMENT 默认 true
  • ENABLE_CODING 默认 false
  • ENABLE_AUDIT 默认 true

当前实现边界

  • Treatment Agent 当前是 patient_info + diagnosis -> LLM treatment_plan
  • Coding Agent 当前是 diagnosis + treatment_plan -> LLM coding draft
  • Audit Agent 是规则化的 PHI / HIPAA 风险扫描

所以这一版更适合表述为:

在保留 LangGraph workflow 和 Tail Pipeline 外壳的前提下,将前半段 Intake/Diagnosis 替换为 DoctorAgent 主导的多轮问诊与诊断流程。

About

No description, website, or topics provided.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors