Spaces:
Sleeping
Sleeping
Commit
·
a5f4f6d
1
Parent(s):
27a55e7
Refactor README and module documentation; add convenience functions for orchestrator creation and quick diagnosis
Browse files- .gitignore +1 -0
- README.md +76 -60
- mai_dx/__init__.py +84 -2
- mai_dx/main.py +1 -1
.gitignore
CHANGED
@@ -2,6 +2,7 @@
|
|
2 |
__pycache__/
|
3 |
*.py[cod]
|
4 |
*$py.class
|
|
|
5 |
|
6 |
# C extensions
|
7 |
*.so
|
|
|
2 |
__pycache__/
|
3 |
*.py[cod]
|
4 |
*$py.class
|
5 |
+
agent_workspace
|
6 |
|
7 |
# C extensions
|
8 |
*.so
|
README.md
CHANGED
@@ -1,46 +1,26 @@
|
|
1 |
-
#
|
2 |
|
3 |
-
> **
|
4 |
|
5 |
[](https://arxiv.org/abs/2506.22405)
|
6 |
[](LICENSE)
|
7 |
[](https://python.org)
|
8 |
|
9 |
-
|
10 |
|
11 |
## 🚀 Quick Start
|
12 |
|
13 |
```bash
|
14 |
-
# Install the package
|
15 |
-
pip install mai-dx
|
16 |
-
|
17 |
-
# Or install from source
|
18 |
git clone https://github.com/The-Swarm-Corporation/Open-MAI-Dx-Orchestrator.git
|
19 |
cd Open-MAI-Dx-Orchestrator
|
20 |
-
pip install -
|
21 |
-
```
|
22 |
-
|
23 |
-
----
|
24 |
-
|
25 |
-
## Enivronement Configuration
|
26 |
-
Configure your api keys and environment variables like the following.
|
27 |
-
|
28 |
-
```txt
|
29 |
-
WORKSPACE_DIR="" # for the swarms library
|
30 |
-
OPENAI_API_KEY="" # Your model api key
|
31 |
-
GEMINI_API_KEY="" # your gemini api key
|
32 |
-
ANTHROPIC_API_KEY=""
|
33 |
```
|
34 |
|
35 |
-
----
|
36 |
-
|
37 |
-
## Example
|
38 |
-
|
39 |
```python
|
40 |
from mai_dx import MaiDxOrchestrator
|
41 |
|
42 |
# Create orchestrator
|
43 |
-
orchestrator = MaiDxOrchestrator(
|
44 |
|
45 |
# Run diagnosis
|
46 |
result = orchestrator.run(
|
@@ -54,53 +34,89 @@ print(f"Accuracy: {result.accuracy_score}/5.0")
|
|
54 |
print(f"Cost: ${result.total_cost:,}")
|
55 |
```
|
56 |
|
57 |
-
|
58 |
|
59 |
-
|
|
|
|
|
|
|
|
|
60 |
|
61 |
-
|
62 |
|
63 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
64 |
|
65 |
-
|
66 |
|
67 |
-
|
|
|
|
|
68 |
|
69 |
-
|
|
|
70 |
|
71 |
-
|
72 |
-
|
73 |
-
title={Sequential Diagnosis with Language Models},
|
74 |
-
author={Harsha Nori and Mayank Daswani and Christopher Kelly and Scott Lundberg and Marco Tulio Ribeiro and Marc Wilson and Xiaoxuan Liu and Viknesh Sounderajah and Jonathan Carlson and Matthew P Lungren and Bay Gross and Peter Hames and Mustafa Suleyman and Dominic King and Eric Horvitz},
|
75 |
-
year={2025},
|
76 |
-
eprint={2506.22405},
|
77 |
-
archivePrefix={arXiv},
|
78 |
-
primaryClass={cs.CL},
|
79 |
-
url={https://arxiv.org/abs/2506.22405},
|
80 |
-
}
|
81 |
|
82 |
-
|
83 |
-
|
84 |
-
|
85 |
-
|
86 |
-
|
87 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
88 |
```
|
89 |
|
90 |
-
##
|
91 |
|
92 |
-
|
93 |
-
- [Swarms Framework](https://github.com/kyegomez/swarms) - Multi-agent AI orchestration
|
94 |
-
- [Microsoft Research](https://www.microsoft.com/en-us/research/) - Original research institution
|
95 |
|
96 |
-
##
|
97 |
|
98 |
-
-
|
99 |
-
- **Discussions**: [GitHub Discussions](https://github.com/The-Swarm-Corporation/Open-MAI-Dx-Orchestrator/discussions)
|
100 |
-
- **Documentation**: [Full Documentation](https://docs.swarms.world)
|
101 |
|
102 |
-
|
103 |
|
104 |
-
|
105 |
-
|
106 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
# MAI Diagnostic Orchestrator (MAI-DxO)
|
2 |
|
3 |
+
> **AI-powered diagnostic system that simulates a virtual panel of physician-agents for medical diagnosis**
|
4 |
|
5 |
[](https://arxiv.org/abs/2506.22405)
|
6 |
[](LICENSE)
|
7 |
[](https://python.org)
|
8 |
|
9 |
+
An open-source implementation of Microsoft Research's "Sequential Diagnosis with Language Models" paper, built with the Swarms AI framework.
|
10 |
|
11 |
## 🚀 Quick Start
|
12 |
|
13 |
```bash
|
|
|
|
|
|
|
|
|
14 |
git clone https://github.com/The-Swarm-Corporation/Open-MAI-Dx-Orchestrator.git
|
15 |
cd Open-MAI-Dx-Orchestrator
|
16 |
+
pip install -r requirements.txt
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
17 |
```
|
18 |
|
|
|
|
|
|
|
|
|
19 |
```python
|
20 |
from mai_dx import MaiDxOrchestrator
|
21 |
|
22 |
# Create orchestrator
|
23 |
+
orchestrator = MaiDxOrchestrator()
|
24 |
|
25 |
# Run diagnosis
|
26 |
result = orchestrator.run(
|
|
|
34 |
print(f"Cost: ${result.total_cost:,}")
|
35 |
```
|
36 |
|
37 |
+
## ✨ Key Features
|
38 |
|
39 |
+
- **8 AI Physician Agents**: Specialized roles for comprehensive diagnosis
|
40 |
+
- **5 Operational Modes**: instant, question-only, budgeted, no-budget, ensemble
|
41 |
+
- **Cost Tracking**: Real-time budget monitoring with 25+ medical test costs
|
42 |
+
- **Clinical Evaluation**: 5-point accuracy scoring with detailed feedback
|
43 |
+
- **Model Agnostic**: Works with GPT, Gemini, Claude, and other LLMs
|
44 |
|
45 |
+
## 🏥 Virtual Physician Panel
|
46 |
|
47 |
+
- **🧠 Dr. Hypothesis**: Maintains differential diagnosis with probabilities
|
48 |
+
- **🔬 Dr. Test-Chooser**: Selects optimal diagnostic tests
|
49 |
+
- **🤔 Dr. Challenger**: Prevents cognitive biases and diagnostic errors
|
50 |
+
- **💰 Dr. Stewardship**: Ensures cost-effective care decisions
|
51 |
+
- **✅ Dr. Checklist**: Quality control and consistency checks
|
52 |
+
- **🤝 Consensus Coordinator**: Synthesizes panel decisions
|
53 |
+
- **🔑 Gatekeeper**: Clinical information oracle
|
54 |
+
- **⚖️ Judge**: Evaluates diagnostic accuracy
|
55 |
|
56 |
+
## 📋 Usage Modes
|
57 |
|
58 |
+
```python
|
59 |
+
# Instant diagnosis (emergency triage)
|
60 |
+
orchestrator = MaiDxOrchestrator.create_variant("instant")
|
61 |
|
62 |
+
# Budget-constrained diagnosis
|
63 |
+
orchestrator = MaiDxOrchestrator.create_variant("budgeted", budget=3000)
|
64 |
|
65 |
+
# Question-only mode (telemedicine)
|
66 |
+
orchestrator = MaiDxOrchestrator.create_variant("question_only")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
67 |
|
68 |
+
# Full diagnostic capability
|
69 |
+
orchestrator = MaiDxOrchestrator.create_variant("no_budget")
|
70 |
+
|
71 |
+
# Ensemble approach (multiple panels)
|
72 |
+
result = orchestrator.run_ensemble(case_info, case_details, ground_truth, num_runs=3)
|
73 |
+
```
|
74 |
+
|
75 |
+
## 🛠 Configuration
|
76 |
+
|
77 |
+
```python
|
78 |
+
orchestrator = MaiDxOrchestrator(
|
79 |
+
model_name="gemini/gemini-2.5-flash", # or "gpt-4", "claude-3-5-sonnet"
|
80 |
+
max_iterations=10,
|
81 |
+
initial_budget=10000,
|
82 |
+
mode="no_budget"
|
83 |
+
)
|
84 |
+
```
|
85 |
+
|
86 |
+
## 📚 Documentation
|
87 |
+
|
88 |
+
- **[Complete Documentation](docs.md)** - Detailed API reference and examples
|
89 |
+
- **[Example Usage](example.py)** - Ready-to-run examples
|
90 |
+
- **[Original Paper](https://arxiv.org/abs/2506.22405)** - Microsoft Research paper
|
91 |
+
|
92 |
+
## 🎯 Example Results
|
93 |
+
|
94 |
+
```
|
95 |
+
=== MAI-DxO Diagnostic Results ===
|
96 |
+
Variant: no_budget
|
97 |
+
Final Diagnosis: Embryonal rhabdomyosarcoma of the pharynx
|
98 |
+
Ground Truth: Embryonal rhabdomyosarcoma of the pharynx
|
99 |
+
Accuracy Score: 5.0/5.0
|
100 |
+
Total Cost: $4,650
|
101 |
+
Iterations: 4
|
102 |
```
|
103 |
|
104 |
+
## 🤝 Contributing
|
105 |
|
106 |
+
We welcome contributions! Please check our issues and submit pull requests.
|
|
|
|
|
107 |
|
108 |
+
## 📄 License
|
109 |
|
110 |
+
MIT License - see [LICENSE](LICENSE) file for details.
|
|
|
|
|
111 |
|
112 |
+
## 📚 Citation
|
113 |
|
114 |
+
```bibtex
|
115 |
+
@misc{nori2025sequentialdiagnosislanguagemodels,
|
116 |
+
title={Sequential Diagnosis with Language Models},
|
117 |
+
author={Harsha Nori and others},
|
118 |
+
year={2025},
|
119 |
+
eprint={2506.22405},
|
120 |
+
archivePrefix={arXiv}
|
121 |
+
}
|
122 |
+
```
|
mai_dx/__init__.py
CHANGED
@@ -1,3 +1,85 @@
|
|
1 |
-
|
|
|
2 |
|
3 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
"""
|
2 |
+
MAI Diagnostic Orchestrator (MAI-DxO)
|
3 |
|
4 |
+
An AI-powered diagnostic system that simulates a virtual panel of physician-agents
|
5 |
+
for medical diagnosis. Based on Microsoft Research's "Sequential Diagnosis with
|
6 |
+
Language Models" paper.
|
7 |
+
|
8 |
+
Key Components:
|
9 |
+
- MaiDxOrchestrator: Main orchestrator class
|
10 |
+
- DiagnosisResult: Result container with diagnosis, accuracy, and cost
|
11 |
+
- Action: Action model for panel decisions
|
12 |
+
- AgentRole: Enumeration of physician agent roles
|
13 |
+
"""
|
14 |
+
|
15 |
+
from typing import Any, Optional
|
16 |
+
|
17 |
+
from .main import (
|
18 |
+
MaiDxOrchestrator,
|
19 |
+
DiagnosisResult,
|
20 |
+
Action,
|
21 |
+
AgentRole,
|
22 |
+
run_mai_dxo_demo
|
23 |
+
)
|
24 |
+
|
25 |
+
__version__ = "1.0.0"
|
26 |
+
__author__ = "The Swarm Corporation"
|
27 |
+
__email__ = "[email protected]"
|
28 |
+
__description__ = "AI-powered diagnostic system with virtual physician panels"
|
29 |
+
|
30 |
+
# Main exports
|
31 |
+
__all__ = [
|
32 |
+
"MaiDxOrchestrator",
|
33 |
+
"DiagnosisResult",
|
34 |
+
"Action",
|
35 |
+
"AgentRole",
|
36 |
+
"run_mai_dxo_demo"
|
37 |
+
]
|
38 |
+
|
39 |
+
# Convenience imports for common usage patterns
|
40 |
+
def create_orchestrator(
|
41 |
+
model_name: str = "gemini/gemini-2.5-flash",
|
42 |
+
mode: str = "no_budget",
|
43 |
+
**kwargs: Any
|
44 |
+
) -> MaiDxOrchestrator:
|
45 |
+
"""
|
46 |
+
Convenience function to create a MAI-DxO orchestrator.
|
47 |
+
|
48 |
+
Args:
|
49 |
+
model_name: Language model to use
|
50 |
+
mode: Operational mode
|
51 |
+
**kwargs: Additional configuration parameters
|
52 |
+
|
53 |
+
Returns:
|
54 |
+
Configured MaiDxOrchestrator instance
|
55 |
+
"""
|
56 |
+
if mode in ["instant", "question_only", "budgeted", "no_budget", "ensemble"]:
|
57 |
+
return MaiDxOrchestrator.create_variant(mode, model_name=model_name, **kwargs)
|
58 |
+
else:
|
59 |
+
return MaiDxOrchestrator(model_name=model_name, mode=mode, **kwargs)
|
60 |
+
|
61 |
+
|
62 |
+
def quick_diagnosis(
|
63 |
+
case_info: str,
|
64 |
+
case_details: str,
|
65 |
+
ground_truth: Optional[str] = None,
|
66 |
+
model_name: str = "gemini/gemini-2.5-flash"
|
67 |
+
) -> DiagnosisResult:
|
68 |
+
"""
|
69 |
+
Convenience function for quick diagnosis without configuration.
|
70 |
+
|
71 |
+
Args:
|
72 |
+
case_info: Initial case presentation
|
73 |
+
case_details: Complete case information
|
74 |
+
ground_truth: Correct diagnosis (optional)
|
75 |
+
model_name: Model to use
|
76 |
+
|
77 |
+
Returns:
|
78 |
+
DiagnosisResult with diagnosis and evaluation
|
79 |
+
"""
|
80 |
+
orchestrator = MaiDxOrchestrator(model_name=model_name, max_iterations=5)
|
81 |
+
return orchestrator.run(
|
82 |
+
initial_case_info=case_info,
|
83 |
+
full_case_details=case_details,
|
84 |
+
ground_truth_diagnosis=ground_truth or "Unknown"
|
85 |
+
)
|
mai_dx/main.py
CHANGED
@@ -198,7 +198,7 @@ class MaiDxOrchestrator:
|
|
198 |
f"🏥 MAI Diagnostic Orchestrator initialized successfully in '{mode}' mode with budget ${initial_budget:,}"
|
199 |
)
|
200 |
|
201 |
-
def _init_agents(self):
|
202 |
"""Initializes all required agents with their specific roles and prompts."""
|
203 |
self.agents = {
|
204 |
role: Agent(
|
|
|
198 |
f"🏥 MAI Diagnostic Orchestrator initialized successfully in '{mode}' mode with budget ${initial_budget:,}"
|
199 |
)
|
200 |
|
201 |
+
def _init_agents(self) -> None:
|
202 |
"""Initializes all required agents with their specific roles and prompts."""
|
203 |
self.agents = {
|
204 |
role: Agent(
|