
Agent
Open-MAI-Dx-Orchestrator
About this agent
An open source implementation of the paper: "Sequential Diagnosis with Language Models" From Microsoft Built with Swarms Framework
MAI Diagnostic Orchestrator (MAI-DxO)
An open-source implementation of Microsoft Research's "Sequential Diagnosis with Language Models" paper, built with the Swarms AI framework.
MAI-DxO (MAI Diagnostic Orchestrator) is a sophisticated AI-powered diagnostic system that simulates a virtual panel of physician-agents to perform iterative medical diagnosis with cost-effectiveness optimization. This implementation faithfully reproduces the methodology described in the Microsoft Research paper while providing additional features and flexibility.
โจ Key Features
- 8 AI Physician Agents: Specialized roles for comprehensive diagnosis.
- 5 Operational Modes: Instant, question-only, budgeted, no-budget, and ensemble modes.
- Cost Tracking: Real-time budget monitoring with costs for 25+ medical tests.
- Clinical Evaluation: 5-point accuracy scoring with detailed feedback.
- Model Agnostic: Works with GPT, Gemini, Claude, and other leading LLMs.
- Token-Optimized Prompts: Ultra-compact role prompts reduce token usage and latency without sacrificing reasoning quality.
๐ Quick Start
1. Installation
Install the package directly via pip:
BASHpip install mai-dx
Or, for development, clone the repository and install the requirements:
BASHgit clone https://github.com/The-Swarm-Corporation/Open-MAI-Dx-Orchestrator.git cd Open-MAI-Dx-Orchestrator pip install -r requirements.txt
2. Environment Setup
Create a .env
file in your project root and add your API keys:
TXTOPENAI_API_KEY="Your OpenAI API key" GEMINI_API_KEY="Your Gemini API key" ANTHROPIC_API_KEY="Your Anthropic API key"
3. Basic Usage
PYTHONfrom mai_dx import MaiDxOrchestrator # Create the orchestrator (defaults to a capable model) orchestrator = MaiDxOrchestrator() # Run a diagnosis result = orchestrator.run( initial_case_info="29-year-old woman with sore throat and peritonsillar swelling...", full_case_details="Patient: 29-year-old female. History: Onset of sore throat...", ground_truth_diagnosis="Embryonal rhabdomyosarcoma of the pharynx" ) # Print the results print(f"Final Diagnosis: {result.final_diagnosis}") print(f"Accuracy: {result.accuracy_score}/5.0") print(f"Total Cost: ${result.total_cost:,.2f}")
โ๏ธ Advanced Usage & Configuration
Customize the orchestrator's model, budget, and operational mode.
PYTHONfrom mai_dx import MaiDxOrchestrator # Configure with a specific model and budget orchestrator = MaiDxOrchestrator( model_name="gemini/gemini-2.5-flash", # or "gpt-4", "claude-3-5-sonnet" max_iterations=10, initial_budget=3000, mode="budgeted" # Other modes: "instant", "question_only", "no_budget" ) # Run the diagnosis # ...
๐ฅ How It Works: The Virtual Physician Panel
MAI-DxO employs a multi-agent system where each agent has a specific role:
- ๐ง Dr. Hypothesis: Maintains the differential diagnosis.
- ๐ฌ Dr. Test-Chooser: Selects the most cost-effective diagnostic tests.
- ๐ค Dr. Challenger: Prevents cognitive biases and diagnostic errors.
- ๐ฐ Dr. Stewardship: Ensures cost-effective care.
- โ Dr. Checklist: Performs quality control checks.
- ๐ค Consensus Coordinator: Synthesizes panel decisions.
- ๐ Gatekeeper: Acts as the clinical information oracle.
- โ๏ธ Judge: Evaluates the final diagnostic accuracy.
Documentation
Learn more about this repository with the docs
๐ค Contributing
We welcome contributions! Please feel free to open an issue or submit a pull request.
๐ License
This project is licensed under the MIT License. See the LICENSE file for details.
๐ Citation
If you use this work in your research, please cite both the original paper and this software implementation.
BIBTEX@misc{nori2025sequentialdiagnosislanguagemodels, title={Sequential Diagnosis with Language Models}, 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}, year={2025}, eprint={2506.22405}, archivePrefix={arXiv}, primaryClass={cs.CL}, url={https://arxiv.org/abs/2506.22405}, } @software{mai_dx_orchestrator, title={Open-MAI-Dx-Orchestrator: An Open Source Implementation of Sequential Diagnosis with Language Models}, author={The-Swarm-Corporation}, year={2025}, url={https://github.com/The-Swarm-Corporation/Open-MAI-Dx-Orchestrator.git} }
๐ Related Work
- Original Paper - Sequential Diagnosis with Language Models
- Swarms Framework - Multi-agent AI orchestration
- Microsoft Research - Original research institution
๐ Support
- Issues: GitHub Issues
- Discussions: GitHub Discussions
- Documentation: Full Documentation
<p align="center"> <strong>Built with Swarms for advancing AI-powered medical diagnosis</strong> </p>
Source: https://github.com/The-Swarm-Corporation/Open-MAI-Dx-Orchestrator
Requirements
Package | Installation |
---|---|
swarms | pip3 install swarms |
Agent Code
The main implementation code for this agent. You can view, copy, and use this code directly in your projects.
Agent Metadata (JSON)
All metadata and code for this agent, as a JSON object. Useful for programmatic use, export, or debugging.
{ "id": "fd5f91a5-3210-460e-8bc4-ff8d0aa056b8", "name": "Open-MAI-Dx-Orchestrator", "title": "Agent", "description": "An open source implementation of the paper: \"Sequential Diagnosis with Language Models\" From Microsoft Built with Swarms Framework\n\n# MAI Diagnostic Orchestrator (MAI-DxO)\n\n> **An open-source implementation of Microsoft Research's \"Sequential Diagnosis with Language Models\" paper, built with the Swarms AI framework.**\n\nMAI-DxO (MAI Diagnostic Orchestrator) is a sophisticated AI-powered diagnostic system that simulates a virtual panel of physician-agents to perform iterative medical diagnosis with cost-effectiveness optimization. This implementation faithfully reproduces the methodology described in the Microsoft Research paper while providing additional features and flexibility.\n\n[](https://arxiv.org/abs/2506.22405)\n[](LICENSE)\n[](https://python.org)\n\n## โจ Key Features\n\n- **8 AI Physician Agents**: Specialized roles for comprehensive diagnosis.\n- **5 Operational Modes**: Instant, question-only, budgeted, no-budget, and ensemble modes.\n- **Cost Tracking**: Real-time budget monitoring with costs for 25+ medical tests.\n- **Clinical Evaluation**: 5-point accuracy scoring with detailed feedback.\n- **Model Agnostic**: Works with GPT, Gemini, Claude, and other leading LLMs.\n- **Token-Optimized Prompts**: Ultra-compact role prompts reduce token usage and latency without sacrificing reasoning quality.\n\n## ๐ Quick Start\n\n### 1. Installation\n\nInstall the package directly via pip:\n\n```bash\npip install mai-dx\n```\n\nOr, for development, clone the repository and install the requirements:\n\n```bash\ngit clone https://github.com/The-Swarm-Corporation/Open-MAI-Dx-Orchestrator.git\ncd Open-MAI-Dx-Orchestrator\npip install -r requirements.txt\n```\n\n### 2. Environment Setup\n\nCreate a `.env` file in your project root and add your API keys:\n\n```txt\nOPENAI_API_KEY=\"Your OpenAI API key\"\nGEMINI_API_KEY=\"Your Gemini API key\"\nANTHROPIC_API_KEY=\"Your Anthropic API key\"\n```\n\n### 3. Basic Usage\n\n```python\nfrom mai_dx import MaiDxOrchestrator\n\n# Create the orchestrator (defaults to a capable model)\norchestrator = MaiDxOrchestrator()\n\n# Run a diagnosis\nresult = orchestrator.run(\n initial_case_info=\"29-year-old woman with sore throat and peritonsillar swelling...\",\n full_case_details=\"Patient: 29-year-old female. History: Onset of sore throat...\",\n ground_truth_diagnosis=\"Embryonal rhabdomyosarcoma of the pharynx\"\n)\n\n# Print the results\nprint(f\"Final Diagnosis: {result.final_diagnosis}\")\nprint(f\"Accuracy: {result.accuracy_score}/5.0\")\nprint(f\"Total Cost: ${result.total_cost:,.2f}\")\n```\n\n## โ๏ธ Advanced Usage & Configuration\n\nCustomize the orchestrator's model, budget, and operational mode.\n\n```python\nfrom mai_dx import MaiDxOrchestrator\n\n# Configure with a specific model and budget\norchestrator = MaiDxOrchestrator(\n model_name=\"gemini/gemini-2.5-flash\", # or \"gpt-4\", \"claude-3-5-sonnet\"\n max_iterations=10,\n initial_budget=3000,\n mode=\"budgeted\" # Other modes: \"instant\", \"question_only\", \"no_budget\"\n)\n\n# Run the diagnosis\n# ...\n```\n\n## ๐ฅ How It Works: The Virtual Physician Panel\n\nMAI-DxO employs a multi-agent system where each agent has a specific role:\n\n- **๐ง Dr. Hypothesis**: Maintains the differential diagnosis.\n- **๐ฌ Dr. Test-Chooser**: Selects the most cost-effective diagnostic tests.\n- **๐ค Dr. Challenger**: Prevents cognitive biases and diagnostic errors.\n- **๐ฐ Dr. Stewardship**: Ensures cost-effective care.\n- **โ Dr. Checklist**: Performs quality control checks.\n- **๐ค Consensus Coordinator**: Synthesizes panel decisions.\n- **๐ Gatekeeper**: Acts as the clinical information oracle.\n- **โ๏ธ Judge**: Evaluates the final diagnostic accuracy.\n\n\n## Documentation\n\nLearn more about this repository [with the docs](DOCS.md)\n\n## ๐ค Contributing\n\nWe welcome contributions! Please feel free to open an issue or submit a pull request.\n\n## ๐ License\n\nThis project is licensed under the MIT License. See the [LICENSE](LICENSE) file for details.\n\n## ๐ Citation\n\nIf you use this work in your research, please cite both the original paper and this software implementation.\n\n```bibtex\n@misc{nori2025sequentialdiagnosislanguagemodels,\n title={Sequential Diagnosis with Language Models}, \n 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},\n year={2025},\n eprint={2506.22405},\n archivePrefix={arXiv},\n primaryClass={cs.CL},\n url={https://arxiv.org/abs/2506.22405}, \n}\n\n@software{mai_dx_orchestrator,\n title={Open-MAI-Dx-Orchestrator: An Open Source Implementation of Sequential Diagnosis with Language Models},\n author={The-Swarm-Corporation},\n year={2025},\n url={https://github.com/The-Swarm-Corporation/Open-MAI-Dx-Orchestrator.git}\n}\n```\n\n## ๐ Related Work\n\n- [Original Paper](https://arxiv.org/abs/2506.22405) - Sequential Diagnosis with Language Models\n- [Swarms Framework](https://github.com/kyegomez/swarms) - Multi-agent AI orchestration\n- [Microsoft Research](https://www.microsoft.com/en-us/research/) - Original research institution\n\n## ๐ Support\n\n- **Issues**: [GitHub Issues](https://github.com/The-Swarm-Corporation/Open-MAI-Dx-Orchestrator/issues)\n- **Discussions**: [GitHub Discussions](https://github.com/The-Swarm-Corporation/Open-MAI-Dx-Orchestrator/discussions)\n- **Documentation**: [Full Documentation](https://docs.swarms.world)\n\n---\n\n<p align=\"center\">\n <strong>Built with Swarms for advancing AI-powered medical diagnosis</strong>\n</p>\n\nSource: https://github.com/The-Swarm-Corporation/Open-MAI-Dx-Orchestrator", "tags": [ "ai", "microsoft", "ml", "multi-agent", "paper-implementation", "swarms", "swarms-agents", "swarms-ecosystem", "ehr", "epic", "medical-agents", "healthcare-agennts", "xray-agents" ], "requirements": [ { "package": "swarms", "installation": "pip3 install swarms" } ], "usecases": [ { "title": "", "description": "" } ], "userId": "12fa3db5-0635-41b6-aa8c-71ece35a18db", "createdAt": "2025-07-11T17:03:18.568173+00:00", "links": [], "code": "from mai_dx import MaiDxOrchestrator\nfrom loguru import logger\n\nif __name__ == \"__main__\":\n # Example case inspired by the paper's Figure 1\n initial_info = (\n \"A 29-year-old woman was admitted to the hospital because of sore throat and peritonsillar swelling \"\n \"and bleeding. Symptoms did not abate with antimicrobial therapy.\"\n )\n\n full_case = \"\"\"\n Patient: 29-year-old female.\n History: Onset of sore throat 7 weeks prior to admission. Worsening right-sided pain and swelling.\n No fevers, headaches, or gastrointestinal symptoms. Past medical history is unremarkable. No history of smoking or significant alcohol use.\n Physical Exam: Right peritonsillar mass, displacing the uvula. No other significant findings.\n Initial Labs: FBC, clotting studies normal.\n MRI Neck: Showed a large, enhancing mass in the right peritonsillar space.\n Biopsy (H&E): Infiltrative round-cell neoplasm with high nuclear-to-cytoplasmic ratio and frequent mitotic figures.\n Biopsy (Immunohistochemistry for Carcinoma): CD31, D2-40, CD34, ERG, GLUT-1, pan-cytokeratin, CD45, CD20, CD3 all negative. Ki-67: 60% nuclear positivity.\n Biopsy (Immunohistochemistry for Rhabdomyosarcoma): Desmin and MyoD1 diffusely positive. Myogenin multifocally positive.\n Biopsy (FISH): No FOXO1 (13q14) rearrangements detected.\n Final Diagnosis from Pathology: Embryonal rhabdomyosarcoma of the pharynx.\n \"\"\"\n\n ground_truth = \"Embryonal rhabdomyosarcoma of the pharynx\"\n\n # --- Demonstrate Different MAI-DxO Variants ---\n try:\n print(\"\\n\" + \"=\" * 80)\n print(\n \" MAI DIAGNOSTIC ORCHESTRATOR (MAI-DxO) - SEQUENTIAL DIAGNOSIS BENCHMARK\"\n )\n print(\n \" Implementation based on the NEJM Research Paper\"\n )\n print(\"=\" * 80)\n\n # Test different variants as described in the paper\n variants_to_test = [\n (\n \"no_budget\",\n \"Standard MAI-DxO with no budget constraints\",\n ),\n (\"budgeted\", \"Budget-constrained MAI-DxO ($3000 limit)\"),\n (\n \"question_only\",\n \"Question-only variant (no diagnostic tests)\",\n ),\n ]\n\n results = {}\n\n for variant_name, description in variants_to_test:\n print(f\"\\n{'='*60}\")\n print(f\"Testing Variant: {variant_name.upper()}\")\n print(f\"Description: {description}\")\n print(\"=\" * 60)\n\n # Create the variant\n if variant_name == \"budgeted\":\n orchestrator = MaiDxOrchestrator.create_variant(\n variant_name,\n budget=3000,\n model_name=\"gemini/gemini-2.5-flash\",\n max_iterations=5,\n )\n else:\n orchestrator = MaiDxOrchestrator.create_variant(\n variant_name,\n model_name=\"gemini/gemini-2.5-flash\",\n max_iterations=5,\n )\n\n # Run the diagnostic process\n result = orchestrator.run(\n initial_case_info=initial_info,\n full_case_details=full_case,\n ground_truth_diagnosis=ground_truth,\n )\n\n results[variant_name] = result\n\n # Display results\n print(f\"\\n๐ Final Diagnosis: {result.final_diagnosis}\")\n print(f\"๐ฏ Ground Truth: {result.ground_truth}\")\n print(f\"โญ Accuracy Score: {result.accuracy_score}/5.0\")\n print(f\" Reasoning: {result.accuracy_reasoning}\")\n print(f\"๐ฐ Total Cost: ${result.total_cost:,}\")\n print(f\"๐ Iterations: {result.iterations}\")\n print(f\"โฑ๏ธ Mode: {orchestrator.mode}\")\n\n # Demonstrate ensemble approach\n print(f\"\\n{'='*60}\")\n print(\"Testing Variant: ENSEMBLE\")\n print(\n \"Description: Multiple independent runs with consensus aggregation\"\n )\n print(\"=\" * 60)\n\n ensemble_orchestrator = MaiDxOrchestrator.create_variant(\n \"ensemble\",\n model_name=\"gemini/gemini-2.5-flash\",\n max_iterations=3, # Shorter iterations for ensemble\n )\n\n ensemble_result = ensemble_orchestrator.run_ensemble(\n initial_case_info=initial_info,\n full_case_details=full_case,\n ground_truth_diagnosis=ground_truth,\n num_runs=2, # Reduced for demo\n )\n\n results[\"ensemble\"] = ensemble_result\n\n print(\n f\"\\n๐ Ensemble Diagnosis: {ensemble_result.final_diagnosis}\"\n )\n print(f\"๐ฏ Ground Truth: {ensemble_result.ground_truth}\")\n print(\n f\"โญ Ensemble Score: {ensemble_result.accuracy_score}/5.0\"\n )\n print(\n f\"๐ฐ Total Ensemble Cost: ${ensemble_result.total_cost:,}\"\n )\n\n # --- Summary Comparison ---\n print(f\"\\n{'='*80}\")\n print(\" RESULTS SUMMARY\")\n print(\"=\" * 80)\n print(\n f\"{'Variant':<15} {'Diagnosis Match':<15} {'Score':<8} {'Cost':<12} {'Iterations':<12}\"\n )\n print(\"-\" * 80)\n\n for variant_name, result in results.items():\n match_status = (\n \"โ Match\"\n if result.accuracy_score >= 4.0\n else \"โ No Match\"\n )\n print(\n f\"{variant_name:<15} {match_status:<15} {result.accuracy_score:<8.1f} ${result.total_cost:<11,} {result.iterations:<12}\"\n )\n\n print(f\"\\n{'='*80}\")\n print(\n \"Implementation successfully demonstrates the MAI-DxO framework\"\n )\n print(\n \"as described in 'Sequential Diagnosis with Language Models' paper\"\n )\n print(\"=\" * 80)\n\n except Exception as e:\n logger.exception(\n f\"An error occurred during the diagnostic session: {e}\"\n )\n print(f\"\\nโ Error occurred: {e}\")\n print(\"Please check your model configuration and API keys.\")\n" }
Comments & Discussion
Items You'd Like
Check out similar agents that match your interests