Cortex.0 / cortex0 /cli.py
Frankenstein-Labs's picture
initial commit
c429240
Raw History Blame Contribute Delete
1.9 kB
"""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())