MRAgent is an intelligent agent that automates the entire process of Mendelian randomization analysis for causal discovery in biomedical research. It:
Knowledge Discovery Mode (KD): Given a disease (outcome), automatically scans PubMed literature to discover potential modifiable exposure (risk factor) that have correlation but no established causal inference, then performs comprehensive Mendelian randomization analysis using OpenGWAS data to identify novel causal relationships.
Causal Validation Mode (CV): Directly test whether a user-specified exposure (e.g., "body mass index") has a causal effect on a specific outcome (e.g., "type 2 diabetes") using two-sample Mendelian randomization.
MRAgent handles all steps automatically:
Python packages (install via pip install -r {baseDir}/requirements.txt)
R language (>= 4.3.4) with the following packages installed:
TwoSampleMR - core Mendelian randomizationieugwasr - OpenGWAS interfacevcfR - required for MRlap (optional)MRlap - sample overlap correction (optional)jsonlite - JSON processing (required for MRlap)OPENAI_API_KEY environment variable must be set (OpenAI API key)
OPENGWAS_JWT environment variable (optional, for OpenGWAS access token)
Discover novel causal relationships starting from a disease:
bash
python {baseDir}/run_mragent.py --mode KD --outcome "back pain" --num-pubmed 100 --bidirectional
Discover novel causal relationships starting from an exposure:
(Currently the CLI implements KD starting from outcome; for exposure-based discovery use the Python API directly)
Validate a specific hypothesis: does exposure causally affect outcome?
bash
python {baseDir}/run_mragent.py --mode CV --exposure "body mass index" --outcome "type 2 diabetes"
OptionDescriptionExample--mode KD|CVRequired. KD =knowledge discovery, CV =causal validation--mode CV``--outcome NAMERequired. Outcome (disease) to study--outcome "back pain"``--exposure NAMERequired in CV mode. Exposure factor to test--exposure "osteoporosis"``--num-pubmed NNumber of papers to fetch from PubMed (default: 100)--num-pubmed 50``--model MR|MR_MOEMR model type. MR =standard, MR_MOE =mixture of experts--model MR_MOE``--bidirectionalPerform bidirectional analysis (also test outcome → exposure)--bidirectional``--no-synonymsDisable synonym expansion (faster)--no-synonyms``--strobe-mrEnable STROBE-MR quality assessment of existing studies--strobe-mr``--mrlapEnable MRlap sample overlap correction--mrlap``--output-dir DIROutput directory (default: ./output)--output-dir /tmp/mragent-out``--steps 1,2,3Only run specific steps (for debugging/intervention)--steps 1,2
VariableRequiredDescriptionOPENAI_API_KEYYesOpenAI API keyOPENGWAS_JWTOptionalOpenGWAS JWT access tokenLLM_MODELNoLLM model name (default: gpt-4o)LLM_PROVIDERNoopenai or ollama (default: openai)OPENAI_BASE_URLNoCustom base URL for OpenAI-compatible APIMRAGENT_SOURCE_PATHNoPath to original MRAgent source if not installed globally
MRAgent outputs a JSON summary to stdout with:
success: boolean indicating successoutput_directory: directory containing all resultsdiscovered_pairs: number of candidate exposure-outcome pairs foundselected_for_mr: number of pairs selected for MR analysisreports: list of paths to generated PDF files (Report.pdf, Introduction.pdf, Conclusion.pdf, etc.)Example output:
json
{
"success": true,
"mode": "CV",
"outcome": "back pain",
"exposure": "osteoarthritis",
"output_directory": "./output/osteoarthritis_back_pain_gpt-4o",
"discovered_pairs": 1,
"selected_for_mr": 1,
"reports": [
"./output/osteoarthritis_back_pain_gpt-4o/osteoarthritis_back_pain/Introduction.pdf",
"./output/osteoarthritis_back_pain_gpt-4o/osteoarthritis_back_pain/osteoarthritis_back_pain/MR_ieu-a-2_ieu-a-1008/Report.pdf",
"./output/osteoarthritis_back_pain_gpt-4o/osteoarthritis_back_pain/Conclusion.pdf"
]
}
When running all steps (default):
StepDescription1Crawl PubMed, extract candidate exposure-outcome pairs2Check if each pair already has MR studies in literature3Extract unique terms, expand with medical synonyms4Check which terms have available GWAS data in OpenGWAS5LLM selects most appropriate GWAS IDs for each term6Generate all combinations of exposure-outcome pairs7Check new combinations for existing MR studies8Select final set of novel pairs for analysis9Run MR analysis, generate plots and LLM-interpreted PDF reports