""" OpenClaw Skill example for AgentEvalTool. This skill demonstrates how OpenClaw can call the AgentEvalTool CLI to execute an evaluation run and fetch the report. In OpenClaw, register this as a skill and configure the following parameters: - target_id: ID of the registered evaluation target - scenario_id: ID of the evaluation scenario - report_format: "json" or "html" (default "json") The skill assumes that the `agenteval` CLI is available on the system PATH. """ import json import subprocess from typing import Any class AgentEvalSkill: """OpenClaw skill wrapper for AgentEvalTool.""" def __init__(self, config: dict[str, Any]): self.config = config def run(self) -> dict[str, Any]: target_id = self.config["target_id"] scenario_id = self.config["scenario_id"] report_format = self.config.get("report_format", "json") # 1. Trigger evaluation run run_cmd = [ "agenteval", "run", "start", "--target-id", target_id, "--scenario-id", scenario_id, ] run_result = subprocess.run(run_cmd, capture_output=True, text=True, check=False) if run_result.returncode != 0: return { "ok": False, "error": f"evaluation run failed: {run_result.stderr}", "stdout": run_result.stdout, } # Extract run_id from CLI output (last line contains "run_id=xxx") run_id = None for line in reversed(run_result.stdout.strip().splitlines()): if "run_id=" in line: run_id = line.split("run_id=")[-1].strip().split()[0] break if not run_id: return { "ok": False, "error": "could not extract run_id from CLI output", "stdout": run_result.stdout, } # 2. Fetch report report_cmd = [ "agenteval", "report", "show", run_id, "--format", report_format, ] report_result = subprocess.run(report_cmd, capture_output=True, text=True, check=False) if report_result.returncode != 0: return { "ok": False, "error": f"report fetch failed: {report_result.stderr}", "run_id": run_id, } report_data = report_result.stdout if report_format == "json": try: report_data = json.loads(report_data) except json.JSONDecodeError: pass return { "ok": True, "run_id": run_id, "report": report_data, } # Example entrypoint for OpenClaw runtime. def execute(config: dict[str, Any]) -> dict[str, Any]: return AgentEvalSkill(config).run()