File size: 1,900 Bytes
c429240
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
"""Command line entry point for the fused Cortex.0 agent."""

from __future__ import annotations

import argparse
import json
import logging
import sys

from cortex0.fusion import Cortex0Agent
from cortex0.settings import Cortex0Settings


def main(argv: list[str] | None = None) -> int:
    parser = argparse.ArgumentParser(
        prog="cortex0",
        description="Run the OpenHands agent whose reasoning engine is Cortex.0.",
    )
    parser.add_argument("task", nargs="?", help="task to run")
    parser.add_argument("--config", help="path to a YAML config file")
    parser.add_argument("--workspace", help="sandbox directory for the agent")
    parser.add_argument("--base-url", help="Cortex.0 inference endpoint")
    parser.add_argument("--model", help="model name the endpoint exposes")
    parser.add_argument(
        "--check",
        action="store_true",
        help="probe the inference server and exit",
    )
    parser.add_argument("-v", "--verbose", action="store_true")
    args = parser.parse_args(argv)

    logging.basicConfig(
        level=logging.DEBUG if args.verbose else logging.INFO,
        format="%(levelname)s %(name)s: %(message)s",
    )

    settings = Cortex0Settings.load(args.config)
    if args.base_url:
        settings.base_url = args.base_url
    if args.model:
        settings.served_model_name = args.model
        settings.model = f"openai/{args.model}"

    try:
        agent = Cortex0Agent(settings=settings, verify=True)
    except RuntimeError as exc:
        print(f"error: {exc}", file=sys.stderr)
        return 2
    print(json.dumps(agent.summary(), indent=2, ensure_ascii=False))

    if args.check:
        return 0
    if not args.task:
        parser.error("provide a task, or use --check to only probe the server")

    agent.run(args.task, workspace=args.workspace)
    return 0


if __name__ == "__main__":
    sys.exit(main())