File size: 10,158 Bytes
b2c86fd | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 | # Biomanus
Biomanus is a graph-guided extension of the Biomni A1 biomedical agent. It adds MCP server generation, MCP ToolGraph construction, GraphRAG-style tool routing, dynamic MCP registration, and benchmark runners for BioAgent-Bench and LAB-Bench.
This README explains how to install the environment, prepare MCP servers, build the MCP graph, and run the experiments.
## 1. Repository Layout
```text
biomni/ Core agent, tools, graph router, retriever, and utilities
biomni_env/ Conda environment files and setup scripts
demo_web/backend/tool2mcp.py Utility for converting bioinformatics tools into MCP servers
build_generated_mcp_graph.py Build MCP server catalogs and graph artifacts
run_bioagent_bench.py BioAgent-Bench runner
evaluate_bioagent_bench.py BioAgent-Bench evaluator
experiments/lab_bench/scripts/ LAB-Bench runners and graph utilities
graph_outputs/ Example prebuilt graph artifacts
```
Large runtime artifacts, downloaded data lakes, benchmark outputs, node modules, and Git history are intentionally not included in this upload package.
## 2. Install the Environment
Create and activate the Biomni environment:
```bash
cd /path/to/Biomanus
conda env create -f biomni_env/environment.yml
conda activate biomni_e1
```
For a smaller environment, use:
```bash
conda env create -f biomni_env/fixed_env.yml
conda activate biomni_e1
```
Install extra packages used by MCP generation and benchmark execution:
```bash
pip install fastmcp mcp openai anthropic python-dotenv pymupdf pipreqs
pip install langchain langchain-openai langchain-anthropic langgraph
```
Because this upload package is source-first and does not require a wheel install, run commands from the repository root or export:
```bash
export PYTHONPATH="$PWD:$PYTHONPATH"
export BIOMNI_EXECUTION_ENV_PREFIX="$CONDA_PREFIX"
export BIOMNI_EXECUTION_PYTHON="$CONDA_PREFIX/bin/python"
```
If your experiments need command-line bioinformatics tools, install them into the same conda environment. The full upstream Biomni setup script is available at:
```bash
bash biomni_env/setup.sh
```
This full setup can take many hours and requires substantial disk space.
## 3. Configure the LLM Backend
Biomanus uses Biomni's `Custom` OpenAI-compatible backend in the main experiments. For DeepSeek:
```bash
export DEEPSEEK_API_KEY="your_key"
export DEEPSEEK_BASE_URL="https://api.deepseek.com/v1"
export DEEPSEEK_MODEL_NAME="deepseek-chat"
export BIOMNI_SOURCE="Custom"
export BIOMNI_LLM="$DEEPSEEK_MODEL_NAME"
export BIOMNI_CUSTOM_BASE_URL="$DEEPSEEK_BASE_URL"
export BIOMNI_CUSTOM_API_KEY="$DEEPSEEK_API_KEY"
export BIOMNI_LLM_PROVIDER="deepseek"
```
For another OpenAI-compatible endpoint, keep `BIOMNI_SOURCE=Custom` and replace the base URL, model name, and API key.
## 4. Prepare MCP Servers
Graph-based execution requires local MCP server directories. Each generated server should follow this structure:
```text
demo_web/backend/data/mcp_generated/
mcp_<server_name>/
app/
<server_name>_server.py
<server_name>_shim_server.py # optional but recommended
Dockerfile
docker-compose.yml
requirements.txt
environment.yaml
```
Create the MCP directories:
```bash
mkdir -p demo_web/backend/data/mcp_generated
mkdir -p demo_web/backend/data/merged_prefer_help_txt
```
### Option A: Copy Existing MCP Servers
If you already generated MCP servers elsewhere, copy the `mcp_*` directories into:
```text
demo_web/backend/data/mcp_generated/
```
Then patch generated servers so they expose stdio-compatible MCP entrypoints:
```bash
python patch_raw_mcp_servers.py --mcp-root demo_web/backend/data/mcp_generated
python patch_generated_mcp_shims.py --mcp-root demo_web/backend/data/mcp_generated
```
### Option B: Generate One MCP Server from a Tool Manual
Use `tool2mcp.py` to convert a bioinformatics command-line tool and its help/manual text into an MCP server.
Example using a local help text:
```bash
python demo_web/backend/tool2mcp.py \
--name kallisto \
--manual docs/kallisto_help.txt \
--output_location demo_web/backend/data/mcp_generated \
--llm_provider deepseek
```
Example using the installed tool's help command:
```bash
python demo_web/backend/tool2mcp.py \
--name fastqc \
--manual=--help \
--run_help_command True \
--output_location demo_web/backend/data/mcp_generated \
--llm_provider deepseek
```
The converter calls an LLM, so the corresponding API key must be configured. Supported providers include `deepseek`, `openai`, `claude`, `azure`, and `gemini`.
## 5. Build the MCP Graph
Once MCP servers exist under `demo_web/backend/data/mcp_generated`, build a graph over all servers:
```bash
python build_generated_mcp_graph.py \
--mcp-root demo_web/backend/data/mcp_generated \
--help-root demo_web/backend/data/merged_prefer_help_txt \
--output-root graph_outputs \
--preset all \
--python-cmd "$BIOMNI_EXECUTION_PYTHON"
```
The output directory will look like:
```text
graph_outputs/mcp_generated_graph_all_<timestamp>/
server_catalog.json
graph_nodes.json
graph_edges.json
server_semantics.json
graph_summary.json
```
For BioAgent-Bench, you can build a smaller graph containing high-signal benchmark servers:
```bash
python build_generated_mcp_graph.py \
--mcp-root demo_web/backend/data/mcp_generated \
--help-root demo_web/backend/data/merged_prefer_help_txt \
--output-root graph_outputs \
--preset bioagent-bench \
--python-cmd "$BIOMNI_EXECUTION_PYTHON"
```
This upload package includes an example graph under `graph_outputs/`. Use it for inspection or as a template. For executable experiments on a new machine, rebuild the graph after placing MCP servers locally so `server_catalog.json` contains valid local commands.
## 6. Run BioAgent-Bench
First download or clone BioAgent-Bench and set the metadata/data paths:
```bash
export BIOAGENT_BENCH_DATASET_ROOT="/path/to/bioagent-bench/dataset"
export BIOAGENT_BENCH_METADATA="/path/to/bioagent-bench/src/task_metadata.json"
```
Run a single task:
```bash
python run_bioagent_bench.py \
--task transcript-quant \
--dataset-root "$BIOAGENT_BENCH_DATASET_ROOT" \
--metadata "$BIOAGENT_BENCH_METADATA" \
--mcp-graph graph_outputs/mcp_generated_graph_benchmark_<timestamp> \
--executable-mcp-only \
--output-root experiments/bioagent-bench-runs \
--execution-env-prefix "$CONDA_PREFIX"
```
Run all supported tasks:
```bash
python run_bioagent_bench.py \
--all \
--dataset-root "$BIOAGENT_BENCH_DATASET_ROOT" \
--metadata "$BIOAGENT_BENCH_METADATA" \
--mcp-graph graph_outputs/mcp_generated_graph_benchmark_<timestamp> \
--executable-mcp-only \
--output-root experiments/bioagent-bench-runs \
--execution-env-prefix "$CONDA_PREFIX"
```
Useful ablation switches:
```bash
--no-graph-retriever # disable graph-guided routing
--no-mcp # disable MCP registration/execution
--no-use-tool-retriever # disable internal Biomni tool retrieval
```
Evaluate BioAgent-Bench outputs:
```bash
python evaluate_bioagent_bench.py \
--all \
--runs-root experiments/bioagent-bench-runs \
--dataset-root "$BIOAGENT_BENCH_DATASET_ROOT" \
--judge-mode rule \
--output experiments/bioagent-bench-runs/latest_evaluation.json
```
For LLM-based judging, set the judge provider/key and use `--judge-mode llm` or `--judge-mode both`.
## 7. Run LAB-Bench
First install or clone LAB-Bench and set:
```bash
export LAB_BENCH_ROOT="/path/to/LAB-Bench"
```
Run a small debug pass:
```bash
python experiments/lab_bench/scripts/run_labbench_with_hypobioos.py \
--evals DbQA SeqQA \
--splits test \
--debug \
--graph-dir graph_outputs/mcp_generated_graph_all_<timestamp> \
--output-root experiments/lab_bench/results/debug \
--agent-root experiments/lab_bench/agent_runtime/debug \
--compact-results-path experiments/lab_bench/results/debug/results.jsonl \
--reasoning-log-path experiments/lab_bench/results/debug/reasoning.log \
--compact-output-only
```
Run the main DbQA/SeqQA protocol:
```bash
python experiments/lab_bench/scripts/run_labbench_with_hypobioos.py \
--evals DbQA SeqQA \
--splits test \
--dev-size 45 \
--test-size 315 \
--seed 20260514 \
--graph-dir graph_outputs/mcp_generated_graph_all_<timestamp> \
--mcp-server-top-k 8 \
--mcp-tool-top-k 12 \
--mcp-server-candidate-pool 24 \
--output-root experiments/lab_bench/results/main \
--agent-root experiments/lab_bench/agent_runtime/main \
--compact-results-path experiments/lab_bench/results/main/results.jsonl \
--reasoning-log-path experiments/lab_bench/results/main/reasoning.log \
--compact-output-only
```
For parallel sharded runs, call the same runner repeatedly with `--shard-index` and `--shard-count`, writing all shards to the same compact JSONL with `--skip-existing-results`.
## 8. Recommended Reproduction Order
1. Create and activate the conda environment.
2. Configure the LLM backend.
3. Generate or copy MCP servers into `demo_web/backend/data/mcp_generated`.
4. Patch MCP shims.
5. Build the MCP graph.
6. Run a single BioAgent-Bench task as a smoke test.
7. Run LAB-Bench in `--debug` mode.
8. Launch full benchmark runs and evaluate.
## 9. Common Issues
`MCP root does not exist`
Create `demo_web/backend/data/mcp_generated` and copy or generate `mcp_*` server directories.
`Help root does not exist`
Create an empty help directory:
```bash
mkdir -p demo_web/backend/data/merged_prefer_help_txt
```
`server_catalog.json points to old paths`
Rebuild the graph on the current machine after placing MCP servers locally. The graph stores executable command paths.
`Missing API key`
Export `DEEPSEEK_API_KEY`, `OPENAI_API_KEY`, `ANTHROPIC_API_KEY`, or the matching provider key before running agents or MCP generation.
`LAB-Bench import errors`
Set `LAB_BENCH_ROOT` to the local LAB-Bench checkout and install LAB-Bench dependencies in the active environment.
`BioAgent-Bench cannot find metadata`
Set `BIOAGENT_BENCH_METADATA` and `BIOAGENT_BENCH_DATASET_ROOT`, or pass `--metadata` and `--dataset-root` explicitly.
|