File size: 1,800 Bytes
96e6518
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
from __future__ import annotations

import argparse
import json
from pathlib import Path

from .agent import BiomniReActAgent
from .config import AgentConfig
from .schema import TaskSpec


def load_task(path: Path, workspace_override: Path | None = None) -> TaskSpec:
    payload = json.loads(path.read_text(encoding="utf-8"))
    workspace = workspace_override or Path(payload.get("workspace", "runs/default"))
    outputs = []
    for raw in payload.get("expected_outputs", []):
        output = Path(raw)
        outputs.append(output if output.is_absolute() else workspace / output)
    return TaskSpec(
        name=payload["name"],
        objective=payload["objective"],
        workspace=workspace,
        expected_outputs=outputs,
        constraints=list(payload.get("constraints", [])),
        metadata={str(key): str(value) for key, value in payload.get("metadata", {}).items()},
    )


def main() -> None:
    parser = argparse.ArgumentParser(description="Run a Biomni-ReAct task.")
    parser.add_argument("--task", required=True, type=Path, help="Path to a JSON task specification.")
    parser.add_argument("--workspace", type=Path, help="Override the task workspace.")
    parser.add_argument("--model", help="Override BIOMNI_REACT_MODEL.")
    parser.add_argument("--top-k", type=int, help="Number of resources to retrieve.")
    args = parser.parse_args()

    config = AgentConfig()
    if args.model:
        config.model = args.model
    if args.top_k:
        config.retrieval_top_k = args.top_k

    task = load_task(args.task, args.workspace)
    result = BiomniReActAgent(config=config).run(task)
    print(json.dumps({"success": result.success, "error": result.error, "summary": str(result.artifact_paths["summary"])}, indent=2))


if __name__ == "__main__":
    main()