https://github.com/bowang-lab/medrax
MedRAX: Medical Reasoning Agent for Chest X-ray - ICML 2025
Science Score: 36.0%
This score indicates how likely this project is to be science-related based on various indicators:
-
○CITATION.cff file
-
✓codemeta.json file
Found codemeta.json file -
✓.zenodo.json file
Found .zenodo.json file -
○DOI references
-
✓Academic publication links
Links to: arxiv.org -
○Committers with academic emails
-
○Institutional organization owner
-
○JOSS paper metadata
-
○Scientific vocabulary similarity
Low similarity (12.3%) to scientific vocabulary
Keywords
Repository
MedRAX: Medical Reasoning Agent for Chest X-ray - ICML 2025
Basic Info
- Host: GitHub
- Owner: bowang-lab
- License: apache-2.0
- Language: Python
- Default Branch: main
- Homepage: https://bowang-lab.github.io/MedRAX/
- Size: 78.2 MB
Statistics
- Stars: 652
- Watchers: 13
- Forks: 136
- Open Issues: 11
- Releases: 0
Topics
Metadata Files
README.md
🤖 MedRAX: Medical Reasoning Agent for Chest X-ray

Abstract
Chest X-rays (CXRs) play an integral role in driving critical decisions in disease management and patient care. While recent innovations have led to specialized models for various CXR interpretation tasks, these solutions often operate in isolation, limiting their practical utility in clinical practice. We present MedRAX, the first versatile AI agent that seamlessly integrates state-of-the-art CXR analysis tools and multimodal large language models into a unified framework. MedRAX dynamically leverages these models to address complex medical queries without requiring additional training. To rigorously evaluate its capabilities, we introduce ChestAgentBench, a comprehensive benchmark containing 2,500 complex medical queries across 7 diverse categories. Our experiments demonstrate that MedRAX achieves state-of-the-art performance compared to both open-source and proprietary models, representing a significant step toward the practical deployment of automated CXR interpretation systems.
MedRAX
MedRAX is built on a robust technical foundation: - Core Architecture: Built on LangChain and LangGraph frameworks - Language Model: Uses GPT-4o with vision capabilities as the backbone LLM - Deployment: Supports both local and cloud-based deployments - Interface: Production-ready interface built with Gradio - Modular Design: Tool-agnostic architecture allowing easy integration of new capabilities
Integrated Tools
- Visual QA: Utilizes CheXagent and LLaVA-Med for complex visual understanding and medical reasoning
- Segmentation: Employs MedSAM and PSPNet model trained on ChestX-Det for precise anatomical structure identification
- Grounding: Uses Maira-2 for localizing specific findings in medical images
- Report Generation: Implements SwinV2 Transformer trained on CheXpert Plus for detailed medical reporting
- Disease Classification: Leverages DenseNet-121 from TorchXRayVision for detecting 18 pathology classes
- X-ray Generation: Utilizes RoentGen for synthetic CXR generation
- Utilities: Includes DICOM processing, visualization tools, and custom plotting capabilities
ChestAgentBench
We introduce ChestAgentBench, a comprehensive evaluation framework with 2,500 complex medical queries across 7 categories, built from 675 expert-curated clinical cases. The benchmark evaluates complex multi-step reasoning in CXR interpretation through:
- Detection
- Classification
- Localization
- Comparison
- Relationship
- Diagnosis
- Characterization
Download the benchmark: ChestAgentBench on Hugging Face
huggingface-cli download wanglab/chestagentbench --repo-type dataset --local-dir chestagentbench
Unzip the Eurorad figures to your local MedMAX directory.
unzip chestagentbench/figures.zip
To evaluate with GPT-4o, set your OpenAI API key and run the quickstart script.
export OPENAI_API_KEY="<your-openai-api-key>"
python quickstart.py \
--model chatgpt-4o-latest \
--temperature 0.2 \
--max-cases 2 \
--log-prefix chatgpt-4o-latest \
--use-urls
Installation
Prerequisites
- Python 3.8+
- CUDA/GPU for best performance
Installation Steps
```bash
Clone the repository
git clone https://github.com/bowang-lab/MedRAX.git cd MedRAX
Install package
pip install -e . ```
Getting Started
```bash
Start the Gradio interface
python main.py
or if you run into permission issues
bash
sudo -E env "PATH=$PATH" python main.py
``
You need to setup themodel_dirinsidemain.pyto the directory where you want to download or already have the weights of above tools from Hugging Face.
Comment out the tools that you do not have access to.
Make sure to setup your OpenAI API key in.env` file!
Tool Selection and Initialization
MedRAX supports selective tool initialization, allowing you to use only the tools you need. Tools can be specified when initializing the agent (look at main.py):
```python selected_tools = [ "ImageVisualizerTool", "ChestXRayClassifierTool", "ChestXRaySegmentationTool", # Add or remove tools as needed ]
agent, toolsdict = initializeagent( "medrax/docs/systemprompts.txt", toolstouse=selectedtools, model_dir="/model-weights" ) ```
Automatically Downloaded Models
The following tools will automatically download their model weights when initialized:
Classification Tool
python
ChestXRayClassifierTool(device=device)
Segmentation Tool
python
ChestXRaySegmentationTool(device=device)
Grounding Tool
python
XRayPhraseGroundingTool(
cache_dir=model_dir,
temp_dir=temp_dir,
load_in_8bit=True,
device=device
)
- Maira-2 weights download to specified cache_dir
- 8-bit and 4-bit quantization available for reduced memory usage
LLaVA-Med Tool
python
LlavaMedTool(
cache_dir=model_dir,
device=device,
load_in_8bit=True
)
- Automatic weight download to cache_dir
- 8-bit and 4-bit quantization available for reduced memory usage
Report Generation Tool
python
ChestXRayReportGeneratorTool(
cache_dir=model_dir,
device=device
)
Visual QA Tool
python
XRayVQATool(
cache_dir=model_dir,
device=device
)
- CheXagent weights download automatically
MedSAM Tool
Support for MedSAM segmentation will be added in a future update.
Utility Tools
No additional model weights required:
python
ImageVisualizerTool()
DicomProcessorTool(temp_dir=temp_dir)
Manual Setup Required
Image Generation Tool
python
ChestXRayGeneratorTool(
model_path=f"{model_dir}/roentgen",
temp_dir=temp_dir,
device=device
)
- RoentGen weights require manual setup:
1. Contact authors: https://github.com/StanfordMIMI/RoentGen
2. Place weights in {model_dir}/roentgen
3. Optional tool, can be excluded if not needed
Configuration Notes
Required Parameters
model_dirorcache_dir: Base directory for model weights that Hugging Face usestemp_dir: Directory for temporary filesdevice: "cuda" for GPU, "cpu" for CPU-only
Memory Management
- Consider selective tool initialization for resource constraints
- Use 8-bit quantization where available
- Some tools (LLaVA-Med, Grounding) are more resource-intensive
Local LLMs
If you are running a local LLM using frameworks like Ollama or LM Studio, you need to configure your environment variables accordingly. For example:
export OPENAI_BASE_URL="http://localhost:11434/v1"
export OPENAI_API_KEY="ollama"
Star History
Authors
- Adibvafa Fallahpour¹²³⁴ * (adibvafa.fallahpour@mail.utoronto.ca)
- *Jun Ma*²³ *
- Alif Munim³⁵ *
- *Hongwei Lyu*³
- *Bo Wang*¹²³⁶
¹ Department of Computer Science, University of Toronto, Toronto, Canada
² Vector Institute, Toronto, Canada
³ University Health Network, Toronto, Canada
⁴ Cohere, Toronto, Canada
⁵ Cohere Labs, Toronto, Canada
⁶ Department of Laboratory Medicine and Pathobiology, University of Toronto, Toronto, Canada
* Equal contribution
Citation
If you find this work useful, please cite our paper:
bibtex
@misc{fallahpour2025medraxmedicalreasoningagent,
title={MedRAX: Medical Reasoning Agent for Chest X-ray},
author={Adibvafa Fallahpour and Jun Ma and Alif Munim and Hongwei Lyu and Bo Wang},
year={2025},
eprint={2502.02673},
archivePrefix={arXiv},
primaryClass={cs.LG},
url={https://arxiv.org/abs/2502.02673},
}
Made with ❤️ at University of Toronto, Vector Institute, and University Health Network
Owner
- Name: WangLab @ U of T
- Login: bowang-lab
- Kind: organization
- Location: 190 Elizabeth St, Toronto, ON M5G 2C4 Canada
- Website: https://wanglab.ml
- Repositories: 11
- Profile: https://github.com/bowang-lab
BoWang's Lab at University of Toronto
GitHub Events
Total
- Create event: 9
- Commit comment event: 1
- Issues event: 31
- Watch event: 599
- Delete event: 1
- Issue comment event: 33
- Member event: 6
- Push event: 48
- Pull request event: 23
- Fork event: 123
Last Year
- Create event: 9
- Commit comment event: 1
- Issues event: 31
- Watch event: 599
- Delete event: 1
- Issue comment event: 33
- Member event: 6
- Push event: 48
- Pull request event: 23
- Fork event: 123
Committers
Last synced: 9 months ago
Top Committers
| Name | Commits | |
|---|---|---|
| Adibvafa Fallahpour | 9****a | 41 |
| amarzullo24 | m****4@g****m | 1 |
| Alif Munim | a****m@r****a | 1 |
Committer Domains (Top 20 + Academic)
Issues and Pull Requests
Last synced: 6 months ago
All Time
- Total issues: 20
- Total pull requests: 19
- Average time to close issues: 4 days
- Average time to close pull requests: about 18 hours
- Total issue authors: 8
- Total pull request authors: 4
- Average comments per issue: 0.8
- Average comments per pull request: 0.21
- Merged pull requests: 7
- Bot issues: 0
- Bot pull requests: 0
Past Year
- Issues: 20
- Pull requests: 19
- Average time to close issues: 4 days
- Average time to close pull requests: about 18 hours
- Issue authors: 8
- Pull request authors: 4
- Average comments per issue: 0.8
- Average comments per pull request: 0.21
- Merged pull requests: 7
- Bot issues: 0
- Bot pull requests: 0
Top Authors
Issue Authors
- Adibvafa (9)
- FreeCloudmlgbd (4)
- 0wweewe0 (1)
- muratkarabulut75 (1)
- JZPeterPan (1)
- wuxi-dixi (1)
- Psilym (1)
- asetilsalisilikasit (1)
Pull Request Authors
- Adibvafa (10)
- VictorLJZ (5)
- amarzullo24 (2)
- rkarahan80 (1)
Top Labels
Issue Labels
Pull Request Labels
Dependencies
- Pillow >=8.0.0
- accelerate >=0.12.0
- albumentations >=1.0.0
- backoff >=1.10.0
- bitsandbytes >=0.35.0
- diffusers >=0.20.0
- einops >=0.3.0
- einops-exts >=0.0.4
- fastapi >=0.68.0
- gdcm >=1.0.0
- gradio >=5.0.0
- gradio >=3.0.0
- gradio_client >=0.2.0
- httpx >=0.23.0
- jupyter >=1.0.0
- langchain-anthropic >=0.0.2
- langchain-community >=0.0.10
- langchain-core >=0.1.0
- langchain-openai >=0.0.2
- langgraph >=0.0.10
- markdown2 [all]>=2.4.0
- matplotlib >=3.8.0
- numpy >=1.19.0
- openai >=0.27.0
- opencv-python >=4.8.0
- pandas >=1.3.0
- peft >=0.2.0
- protobuf >=3.15.0
- pyarrow >=10.0.0
- pydantic >=1.8.0
- pydicom >=2.3.0
- pygraphviz >=1.8
- pylibjpeg >=1.0.0
- python-dotenv >=0.19.0
- requests >=2.25.0
- scikit-image >=0.18.0
- scikit-learn >=0.24.0
- sentencepiece >=0.1.95
- shortuuid >=1.0.0
- tiktoken >=0.3.0
- timm >=0.5.0
- tokenizers >=0.10.0
- torch >=2.2.0
- torchvision >=0.10.0
- torchxrayvision >=0.0.37
- transformers @ git+https://github.com/huggingface/transformers.git@88d960937c81a32bfb63356a2e8ecf7999619681
- uvicorn >=0.15.0