Spaces:
Running
Running
KaiWu commited on
Commit ·
e4cff4b
1
Parent(s): 5a3be35
feat(eval): add CAD benchmark runner
Browse filesAdd a CLI runner that executes CAD benchmark cases through the active agent path and writes per-attempt transcripts, copied artifacts, scores, and aggregate summaries under outputs/evals.
Add hard metric checks for tool success, manifest validity, STEP/STL export, STEP loadability, and optional bounding-box dimension checks for objectively measurable cases.
Document benchmark runner usage and use readable eval directory names in the format <case_count>cases-<model_id>-<timestamp>.
- agent_core/eval/__init__.py +1 -0
- agent_core/eval/checks.py +159 -0
- agent_core/eval/run.py +270 -0
- benchmarks/cad_v1/README.md +40 -1
- benchmarks/cad_v1/hard_checks.json +77 -0
agent_core/eval/__init__.py
ADDED
|
@@ -0,0 +1 @@
|
|
|
|
|
|
|
| 1 |
+
"""Benchmark evaluation helpers for CAD generation."""
|
agent_core/eval/checks.py
ADDED
|
@@ -0,0 +1,159 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import json
|
| 2 |
+
from pathlib import Path
|
| 3 |
+
from typing import Any
|
| 4 |
+
|
| 5 |
+
from agent_core.config import STEP_SUFFIXES, WORKDIR
|
| 6 |
+
|
| 7 |
+
|
| 8 |
+
def resolve_existing_path(path: str | None) -> Path | None:
|
| 9 |
+
if not path:
|
| 10 |
+
return None
|
| 11 |
+
candidate = Path(path)
|
| 12 |
+
if not candidate.is_absolute():
|
| 13 |
+
candidate = WORKDIR / candidate
|
| 14 |
+
candidate = candidate.resolve()
|
| 15 |
+
return candidate if candidate.exists() else None
|
| 16 |
+
|
| 17 |
+
|
| 18 |
+
def load_hard_checks(path: Path) -> dict[str, Any]:
|
| 19 |
+
if not path.exists():
|
| 20 |
+
return {}
|
| 21 |
+
raw = json.loads(path.read_text(encoding="utf-8"))
|
| 22 |
+
return raw.get("bbox_checks", {})
|
| 23 |
+
|
| 24 |
+
|
| 25 |
+
def _dimension_value(item: dict[str, Any]) -> float:
|
| 26 |
+
if "expected" in item:
|
| 27 |
+
return float(item["expected"])
|
| 28 |
+
return (float(item["min"]) + float(item["max"])) / 2
|
| 29 |
+
|
| 30 |
+
|
| 31 |
+
def _dimension_passes(actual: float, expected: dict[str, Any]) -> bool:
|
| 32 |
+
if "expected" in expected:
|
| 33 |
+
tolerance = float(expected.get("tolerance", 0))
|
| 34 |
+
target = float(expected["expected"])
|
| 35 |
+
return abs(actual - target) <= tolerance
|
| 36 |
+
return float(expected["min"]) <= actual <= float(expected["max"])
|
| 37 |
+
|
| 38 |
+
|
| 39 |
+
def _load_step_bbox(step_path: Path) -> dict[str, float]:
|
| 40 |
+
from build123d import import_step
|
| 41 |
+
|
| 42 |
+
shape = import_step(step_path)
|
| 43 |
+
bbox = shape.bounding_box()
|
| 44 |
+
return {
|
| 45 |
+
"x": float(bbox.size.X),
|
| 46 |
+
"y": float(bbox.size.Y),
|
| 47 |
+
"z": float(bbox.size.Z),
|
| 48 |
+
}
|
| 49 |
+
|
| 50 |
+
|
| 51 |
+
def evaluate_step_loadable(step_path: Path | None) -> dict[str, Any]:
|
| 52 |
+
if not step_path:
|
| 53 |
+
return {"passed": False, "reason": "missing_step"}
|
| 54 |
+
|
| 55 |
+
try:
|
| 56 |
+
from build123d import import_step
|
| 57 |
+
|
| 58 |
+
import_step(step_path)
|
| 59 |
+
except Exception as exc:
|
| 60 |
+
return {
|
| 61 |
+
"passed": False,
|
| 62 |
+
"reason": "step_load_failed",
|
| 63 |
+
"error_type": type(exc).__name__,
|
| 64 |
+
"error": str(exc),
|
| 65 |
+
}
|
| 66 |
+
|
| 67 |
+
return {"passed": True}
|
| 68 |
+
|
| 69 |
+
|
| 70 |
+
def evaluate_bbox(step_path: Path | None, check: dict[str, Any] | None) -> dict[str, Any]:
|
| 71 |
+
if not check:
|
| 72 |
+
return {"checked": False, "passed": None, "reason": "no_bbox_check"}
|
| 73 |
+
if not step_path:
|
| 74 |
+
return {"checked": True, "passed": False, "reason": "missing_step"}
|
| 75 |
+
|
| 76 |
+
try:
|
| 77 |
+
actual = _load_step_bbox(step_path)
|
| 78 |
+
except Exception as exc:
|
| 79 |
+
return {
|
| 80 |
+
"checked": True,
|
| 81 |
+
"passed": False,
|
| 82 |
+
"reason": "step_load_failed",
|
| 83 |
+
"error_type": type(exc).__name__,
|
| 84 |
+
"error": str(exc),
|
| 85 |
+
}
|
| 86 |
+
|
| 87 |
+
dimensions = check.get("dimensions_mm", [])
|
| 88 |
+
mode = check.get("mode", "unordered")
|
| 89 |
+
comparisons = []
|
| 90 |
+
|
| 91 |
+
if mode == "axis_aligned":
|
| 92 |
+
for expected in dimensions:
|
| 93 |
+
axis = expected["axis"]
|
| 94 |
+
actual_value = actual[axis]
|
| 95 |
+
comparisons.append({
|
| 96 |
+
"label": expected.get("label", axis),
|
| 97 |
+
"axis": axis,
|
| 98 |
+
"actual": actual_value,
|
| 99 |
+
"expected": expected,
|
| 100 |
+
"passed": _dimension_passes(actual_value, expected),
|
| 101 |
+
})
|
| 102 |
+
else:
|
| 103 |
+
expected_sorted = sorted(dimensions, key=_dimension_value)
|
| 104 |
+
actual_sorted = sorted(actual.values())
|
| 105 |
+
for actual_value, expected in zip(actual_sorted, expected_sorted):
|
| 106 |
+
comparisons.append({
|
| 107 |
+
"label": expected.get("label"),
|
| 108 |
+
"actual": actual_value,
|
| 109 |
+
"expected": expected,
|
| 110 |
+
"passed": _dimension_passes(actual_value, expected),
|
| 111 |
+
})
|
| 112 |
+
|
| 113 |
+
passed = bool(comparisons) and all(item["passed"] for item in comparisons)
|
| 114 |
+
return {
|
| 115 |
+
"checked": True,
|
| 116 |
+
"passed": passed,
|
| 117 |
+
"mode": mode,
|
| 118 |
+
"actual_bbox_mm": actual,
|
| 119 |
+
"comparisons": comparisons,
|
| 120 |
+
}
|
| 121 |
+
|
| 122 |
+
|
| 123 |
+
def evaluate_hard_metrics(case: dict[str, Any], tool_payload: dict[str, Any], hard_checks: dict[str, Any]) -> dict[str, Any]:
|
| 124 |
+
output_path = resolve_existing_path(tool_payload.get("output_path"))
|
| 125 |
+
preview_path = resolve_existing_path(tool_payload.get("preview_path"))
|
| 126 |
+
manifest_path = resolve_existing_path(tool_payload.get("manifest_path"))
|
| 127 |
+
|
| 128 |
+
step_export = bool(output_path and output_path.suffix.lower() in STEP_SUFFIXES)
|
| 129 |
+
stl_preview = bool(preview_path and preview_path.suffix.lower() == ".stl")
|
| 130 |
+
manifest_written = manifest_path is not None
|
| 131 |
+
|
| 132 |
+
manifest_json_ok = False
|
| 133 |
+
manifest_generator = None
|
| 134 |
+
if manifest_path:
|
| 135 |
+
try:
|
| 136 |
+
manifest = json.loads(manifest_path.read_text(encoding="utf-8"))
|
| 137 |
+
manifest_json_ok = True
|
| 138 |
+
manifest_generator = manifest.get("generator")
|
| 139 |
+
except Exception:
|
| 140 |
+
manifest_json_ok = False
|
| 141 |
+
|
| 142 |
+
step_load = evaluate_step_loadable(output_path if step_export else None)
|
| 143 |
+
bbox = evaluate_bbox(output_path if step_export else None, hard_checks.get(case["id"]))
|
| 144 |
+
tool_success = tool_payload.get("ok") is True
|
| 145 |
+
|
| 146 |
+
return {
|
| 147 |
+
"tool_success": tool_success,
|
| 148 |
+
"manifest_written": manifest_written,
|
| 149 |
+
"manifest_json_ok": manifest_json_ok,
|
| 150 |
+
"manifest_generator": manifest_generator,
|
| 151 |
+
"step_export": step_export,
|
| 152 |
+
"stl_preview": stl_preview,
|
| 153 |
+
"step_loadable": step_load["passed"],
|
| 154 |
+
"step_load": step_load,
|
| 155 |
+
"bbox_check": bbox,
|
| 156 |
+
"error_type": tool_payload.get("error_type"),
|
| 157 |
+
"error_stage": tool_payload.get("stage"),
|
| 158 |
+
"error": tool_payload.get("error"),
|
| 159 |
+
}
|
agent_core/eval/run.py
ADDED
|
@@ -0,0 +1,270 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import argparse
|
| 2 |
+
import json
|
| 3 |
+
import re
|
| 4 |
+
import shutil
|
| 5 |
+
import time
|
| 6 |
+
from datetime import datetime
|
| 7 |
+
from pathlib import Path
|
| 8 |
+
from typing import Any
|
| 9 |
+
|
| 10 |
+
from agent_core.config import ARTIFACT_ROOT, WORKDIR, get_model_id
|
| 11 |
+
from agent_core.eval.checks import evaluate_hard_metrics, load_hard_checks, resolve_existing_path
|
| 12 |
+
from agent_core.outputs import workspace_relative
|
| 13 |
+
from agent_core.service import run_chat_turn
|
| 14 |
+
|
| 15 |
+
|
| 16 |
+
DEFAULT_BENCHMARK = WORKDIR / "benchmarks" / "cad_v1" / "cases.jsonl"
|
| 17 |
+
DEFAULT_CHECKS = WORKDIR / "benchmarks" / "cad_v1" / "hard_checks.json"
|
| 18 |
+
|
| 19 |
+
|
| 20 |
+
def slugify(value: str) -> str:
|
| 21 |
+
slug = re.sub(r"[^A-Za-z0-9._-]+", "-", value).strip("-._")
|
| 22 |
+
return slug[:80] or "unknown-model"
|
| 23 |
+
|
| 24 |
+
|
| 25 |
+
def build_eval_id(case_count: int, model_id: str, created_at: datetime) -> str:
|
| 26 |
+
timestamp = created_at.strftime("%Y%m%d_%H%M%S")
|
| 27 |
+
return f"{case_count}cases-{slugify(model_id)}-{timestamp}"
|
| 28 |
+
|
| 29 |
+
|
| 30 |
+
def load_cases(path: Path) -> list[dict[str, Any]]:
|
| 31 |
+
cases = []
|
| 32 |
+
with path.open(encoding="utf-8") as handle:
|
| 33 |
+
for line_number, line in enumerate(handle, start=1):
|
| 34 |
+
line = line.strip()
|
| 35 |
+
if not line:
|
| 36 |
+
continue
|
| 37 |
+
case = json.loads(line)
|
| 38 |
+
if "id" not in case or "prompt" not in case:
|
| 39 |
+
raise ValueError(f"Invalid benchmark case at line {line_number}: missing id or prompt.")
|
| 40 |
+
cases.append(case)
|
| 41 |
+
return cases
|
| 42 |
+
|
| 43 |
+
|
| 44 |
+
def select_cases(cases: list[dict[str, Any]], case_ids: list[str] | None, limit: int | None) -> list[dict[str, Any]]:
|
| 45 |
+
if case_ids:
|
| 46 |
+
wanted = set(case_ids)
|
| 47 |
+
selected = [case for case in cases if case["id"] in wanted]
|
| 48 |
+
missing = wanted - {case["id"] for case in selected}
|
| 49 |
+
if missing:
|
| 50 |
+
raise ValueError(f"Unknown case id(s): {', '.join(sorted(missing))}")
|
| 51 |
+
else:
|
| 52 |
+
selected = list(cases)
|
| 53 |
+
|
| 54 |
+
if limit is not None:
|
| 55 |
+
selected = selected[:limit]
|
| 56 |
+
return selected
|
| 57 |
+
|
| 58 |
+
|
| 59 |
+
def to_jsonable(value: Any) -> Any:
|
| 60 |
+
if value is None or isinstance(value, (str, int, float, bool)):
|
| 61 |
+
return value
|
| 62 |
+
if isinstance(value, Path):
|
| 63 |
+
return str(value)
|
| 64 |
+
if isinstance(value, list):
|
| 65 |
+
return [to_jsonable(item) for item in value]
|
| 66 |
+
if isinstance(value, dict):
|
| 67 |
+
return {str(key): to_jsonable(item) for key, item in value.items()}
|
| 68 |
+
if hasattr(value, "model_dump"):
|
| 69 |
+
return to_jsonable(value.model_dump())
|
| 70 |
+
if hasattr(value, "__dict__"):
|
| 71 |
+
return {key: to_jsonable(item) for key, item in vars(value).items() if not key.startswith("_")}
|
| 72 |
+
return str(value)
|
| 73 |
+
|
| 74 |
+
|
| 75 |
+
def write_json(path: Path, payload: dict[str, Any]) -> None:
|
| 76 |
+
path.parent.mkdir(parents=True, exist_ok=True)
|
| 77 |
+
path.write_text(json.dumps(payload, ensure_ascii=False, indent=2), encoding="utf-8")
|
| 78 |
+
|
| 79 |
+
|
| 80 |
+
def append_jsonl(path: Path, payload: dict[str, Any]) -> None:
|
| 81 |
+
path.parent.mkdir(parents=True, exist_ok=True)
|
| 82 |
+
with path.open("a", encoding="utf-8") as handle:
|
| 83 |
+
handle.write(json.dumps(payload, ensure_ascii=False) + "\n")
|
| 84 |
+
|
| 85 |
+
|
| 86 |
+
def copy_if_exists(source: Path | None, target: Path) -> str | None:
|
| 87 |
+
if not source:
|
| 88 |
+
return None
|
| 89 |
+
target.parent.mkdir(parents=True, exist_ok=True)
|
| 90 |
+
shutil.copy2(source, target)
|
| 91 |
+
return workspace_relative(target)
|
| 92 |
+
|
| 93 |
+
|
| 94 |
+
def copy_artifacts(tool_payload: dict[str, Any], attempt_dir: Path) -> dict[str, str | None]:
|
| 95 |
+
output_path = resolve_existing_path(tool_payload.get("output_path"))
|
| 96 |
+
preview_path = resolve_existing_path(tool_payload.get("preview_path"))
|
| 97 |
+
manifest_path = resolve_existing_path(tool_payload.get("manifest_path"))
|
| 98 |
+
|
| 99 |
+
output_target = None
|
| 100 |
+
if output_path:
|
| 101 |
+
suffix = output_path.suffix or ".step"
|
| 102 |
+
output_target = attempt_dir / f"model{suffix}"
|
| 103 |
+
|
| 104 |
+
return {
|
| 105 |
+
"output_path": copy_if_exists(output_path, output_target) if output_target else None,
|
| 106 |
+
"preview_path": copy_if_exists(preview_path, attempt_dir / "preview.stl"),
|
| 107 |
+
"manifest_path": copy_if_exists(manifest_path, attempt_dir / "manifest.json"),
|
| 108 |
+
"source_output_path": workspace_relative(output_path) if output_path else None,
|
| 109 |
+
"source_preview_path": workspace_relative(preview_path) if preview_path else None,
|
| 110 |
+
"source_manifest_path": workspace_relative(manifest_path) if manifest_path else None,
|
| 111 |
+
}
|
| 112 |
+
|
| 113 |
+
|
| 114 |
+
def run_attempt(
|
| 115 |
+
case: dict[str, Any],
|
| 116 |
+
attempt_index: int,
|
| 117 |
+
eval_dir: Path,
|
| 118 |
+
hard_checks: dict[str, Any],
|
| 119 |
+
) -> dict[str, Any]:
|
| 120 |
+
attempt_id = f"attempt_{attempt_index + 1:02d}"
|
| 121 |
+
attempt_dir = eval_dir / "cases" / case["id"] / attempt_id
|
| 122 |
+
messages: list[dict[str, Any]] = []
|
| 123 |
+
started_at = datetime.now().astimezone().isoformat(timespec="seconds")
|
| 124 |
+
started = time.monotonic()
|
| 125 |
+
|
| 126 |
+
error = None
|
| 127 |
+
result: dict[str, Any] = {
|
| 128 |
+
"tool_payload": {},
|
| 129 |
+
"assistant_text": "",
|
| 130 |
+
}
|
| 131 |
+
|
| 132 |
+
try:
|
| 133 |
+
result = run_chat_turn(messages, case["prompt"])
|
| 134 |
+
except Exception as exc:
|
| 135 |
+
error = {
|
| 136 |
+
"error_type": type(exc).__name__,
|
| 137 |
+
"error": str(exc),
|
| 138 |
+
}
|
| 139 |
+
|
| 140 |
+
latency_seconds = round(time.monotonic() - started, 3)
|
| 141 |
+
finished_at = datetime.now().astimezone().isoformat(timespec="seconds")
|
| 142 |
+
tool_payload = result.get("tool_payload") or {}
|
| 143 |
+
artifact_paths = copy_artifacts(tool_payload, attempt_dir)
|
| 144 |
+
metrics = evaluate_hard_metrics(case, tool_payload, hard_checks)
|
| 145 |
+
if error:
|
| 146 |
+
metrics["error_type"] = error["error_type"]
|
| 147 |
+
metrics["error"] = error["error"]
|
| 148 |
+
|
| 149 |
+
record = {
|
| 150 |
+
"case_id": case["id"],
|
| 151 |
+
"attempt_id": attempt_id,
|
| 152 |
+
"started_at": started_at,
|
| 153 |
+
"finished_at": finished_at,
|
| 154 |
+
"latency_seconds": latency_seconds,
|
| 155 |
+
"category": case.get("category"),
|
| 156 |
+
"difficulty": case.get("difficulty"),
|
| 157 |
+
"language": case.get("language"),
|
| 158 |
+
"prompt": case["prompt"],
|
| 159 |
+
"run_id": tool_payload.get("run_id"),
|
| 160 |
+
"source_generator": case.get("source_generator"),
|
| 161 |
+
"tool_payload": tool_payload,
|
| 162 |
+
"artifact_paths": artifact_paths,
|
| 163 |
+
"metrics": metrics,
|
| 164 |
+
"exception": error,
|
| 165 |
+
}
|
| 166 |
+
|
| 167 |
+
write_json(attempt_dir / "transcript.json", {"messages": to_jsonable(messages)})
|
| 168 |
+
write_json(attempt_dir / "score.json", record)
|
| 169 |
+
return record
|
| 170 |
+
|
| 171 |
+
|
| 172 |
+
def summarize(eval_id: str, benchmark_path: Path, results: list[dict[str, Any]], repeat: int, results_path: Path) -> dict[str, Any]:
|
| 173 |
+
total = len(results)
|
| 174 |
+
|
| 175 |
+
def rate(metric_name: str) -> float | None:
|
| 176 |
+
if total == 0:
|
| 177 |
+
return None
|
| 178 |
+
passed = sum(1 for result in results if result["metrics"].get(metric_name) is True)
|
| 179 |
+
return round(passed / total, 4)
|
| 180 |
+
|
| 181 |
+
bbox_checked = [result for result in results if result["metrics"].get("bbox_check", {}).get("checked")]
|
| 182 |
+
bbox_passed = sum(1 for result in bbox_checked if result["metrics"]["bbox_check"].get("passed") is True)
|
| 183 |
+
error_counts: dict[str, int] = {}
|
| 184 |
+
for result in results:
|
| 185 |
+
error_type = result["metrics"].get("error_type")
|
| 186 |
+
if error_type:
|
| 187 |
+
error_counts[error_type] = error_counts.get(error_type, 0) + 1
|
| 188 |
+
|
| 189 |
+
return {
|
| 190 |
+
"eval_id": eval_id,
|
| 191 |
+
"benchmark_path": workspace_relative(benchmark_path),
|
| 192 |
+
"model_id": get_model_id(),
|
| 193 |
+
"repeat": repeat,
|
| 194 |
+
"total_attempts": total,
|
| 195 |
+
"case_count": len({result["case_id"] for result in results}),
|
| 196 |
+
"metrics": {
|
| 197 |
+
"tool_success_rate": rate("tool_success"),
|
| 198 |
+
"manifest_written_rate": rate("manifest_written"),
|
| 199 |
+
"manifest_json_ok_rate": rate("manifest_json_ok"),
|
| 200 |
+
"step_export_rate": rate("step_export"),
|
| 201 |
+
"stl_preview_rate": rate("stl_preview"),
|
| 202 |
+
"step_loadable_rate": rate("step_loadable"),
|
| 203 |
+
"bbox_checked_attempts": len(bbox_checked),
|
| 204 |
+
"bbox_passed_attempts": bbox_passed,
|
| 205 |
+
"bbox_pass_rate": round(bbox_passed / len(bbox_checked), 4) if bbox_checked else None,
|
| 206 |
+
},
|
| 207 |
+
"error_counts": error_counts,
|
| 208 |
+
"results_path": workspace_relative(results_path),
|
| 209 |
+
}
|
| 210 |
+
|
| 211 |
+
|
| 212 |
+
def parse_args() -> argparse.Namespace:
|
| 213 |
+
parser = argparse.ArgumentParser(description="Run CAD benchmark cases through the active agent.")
|
| 214 |
+
parser.add_argument("--benchmark", type=Path, default=DEFAULT_BENCHMARK, help="Path to benchmark cases JSONL.")
|
| 215 |
+
parser.add_argument("--checks", type=Path, default=DEFAULT_CHECKS, help="Path to hard metric checks JSON.")
|
| 216 |
+
parser.add_argument("--eval-root", type=Path, default=ARTIFACT_ROOT / "evals", help="Directory for benchmark outputs.")
|
| 217 |
+
parser.add_argument("--backend", choices=["build123d"], default="build123d", help="Active CAD backend label.")
|
| 218 |
+
parser.add_argument("--case-id", action="append", help="Run only this case id. Can be repeated.")
|
| 219 |
+
parser.add_argument("--limit", type=int, help="Run only the first N selected cases.")
|
| 220 |
+
parser.add_argument("--repeat", type=int, default=1, help="Number of attempts per case.")
|
| 221 |
+
return parser.parse_args()
|
| 222 |
+
|
| 223 |
+
|
| 224 |
+
def main() -> None:
|
| 225 |
+
args = parse_args()
|
| 226 |
+
if args.repeat < 1:
|
| 227 |
+
raise ValueError("--repeat must be >= 1")
|
| 228 |
+
if args.limit is not None and args.limit < 1:
|
| 229 |
+
raise ValueError("--limit must be >= 1")
|
| 230 |
+
|
| 231 |
+
benchmark_path = args.benchmark if args.benchmark.is_absolute() else WORKDIR / args.benchmark
|
| 232 |
+
checks_path = args.checks if args.checks.is_absolute() else WORKDIR / args.checks
|
| 233 |
+
eval_root = args.eval_root if args.eval_root.is_absolute() else WORKDIR / args.eval_root
|
| 234 |
+
|
| 235 |
+
cases = select_cases(load_cases(benchmark_path), args.case_id, args.limit)
|
| 236 |
+
hard_checks = load_hard_checks(checks_path)
|
| 237 |
+
model_id = get_model_id()
|
| 238 |
+
created_at = datetime.now().astimezone()
|
| 239 |
+
eval_id = build_eval_id(len(cases), model_id, created_at)
|
| 240 |
+
eval_dir = eval_root / eval_id
|
| 241 |
+
results_path = eval_dir / "results.jsonl"
|
| 242 |
+
|
| 243 |
+
metadata = {
|
| 244 |
+
"eval_id": eval_id,
|
| 245 |
+
"created_at": created_at.isoformat(timespec="seconds"),
|
| 246 |
+
"backend": args.backend,
|
| 247 |
+
"model_id": model_id,
|
| 248 |
+
"benchmark_path": workspace_relative(benchmark_path),
|
| 249 |
+
"checks_path": workspace_relative(checks_path),
|
| 250 |
+
"case_count": len(cases),
|
| 251 |
+
"repeat": args.repeat,
|
| 252 |
+
}
|
| 253 |
+
write_json(eval_dir / "metadata.json", metadata)
|
| 254 |
+
|
| 255 |
+
results = []
|
| 256 |
+
for case in cases:
|
| 257 |
+
for attempt_index in range(args.repeat):
|
| 258 |
+
print(f"[{len(results) + 1}/{len(cases) * args.repeat}] {case['id']} attempt {attempt_index + 1}")
|
| 259 |
+
record = run_attempt(case, attempt_index, eval_dir, hard_checks)
|
| 260 |
+
results.append(record)
|
| 261 |
+
append_jsonl(results_path, record)
|
| 262 |
+
|
| 263 |
+
summary = summarize(eval_id, benchmark_path, results, args.repeat, results_path)
|
| 264 |
+
summary["finished_at"] = datetime.now().astimezone().isoformat(timespec="seconds")
|
| 265 |
+
write_json(eval_dir / "summary.json", summary)
|
| 266 |
+
print(json.dumps(summary, ensure_ascii=False, indent=2))
|
| 267 |
+
|
| 268 |
+
|
| 269 |
+
if __name__ == "__main__":
|
| 270 |
+
main()
|
benchmarks/cad_v1/README.md
CHANGED
|
@@ -21,6 +21,45 @@ Required fields:
|
|
| 21 |
- `why_selected`: Short reason this case belongs in the benchmark.
|
| 22 |
- `expected_checks`: Executable evaluation targets for a future runner.
|
| 23 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 24 |
## Selection Criteria
|
| 25 |
|
| 26 |
- Keep only CAD generator manifests.
|
|
@@ -50,6 +89,6 @@ The selected cases cover the most useful early benchmark surface for this projec
|
|
| 50 |
|
| 51 |
## Current Non-Goals
|
| 52 |
|
| 53 |
-
- No eval runner is included in v1.
|
| 54 |
- No IoU, Chamfer Distance, F-score, or mesh metrics are computed yet.
|
|
|
|
| 55 |
- Multi-turn edit benchmarks should be built as a separate dataset because they require preserved conversation context.
|
|
|
|
| 21 |
- `why_selected`: Short reason this case belongs in the benchmark.
|
| 22 |
- `expected_checks`: Executable evaluation targets for a future runner.
|
| 23 |
|
| 24 |
+
Hard metric checks are stored in `hard_checks.json`. The first version only includes bounding-box checks for cases with objective dimensions that can be checked without a reference CAD model.
|
| 25 |
+
|
| 26 |
+
## Runner
|
| 27 |
+
|
| 28 |
+
Run the benchmark through the active agent:
|
| 29 |
+
|
| 30 |
+
```bash
|
| 31 |
+
conda run --no-capture-output -n aigc python -m agent_core.eval.run
|
| 32 |
+
```
|
| 33 |
+
|
| 34 |
+
Useful scoped runs:
|
| 35 |
+
|
| 36 |
+
```bash
|
| 37 |
+
conda run --no-capture-output -n aigc python -m agent_core.eval.run --limit 3
|
| 38 |
+
conda run --no-capture-output -n aigc python -m agent_core.eval.run --case-id boolean_cube_corner_cut
|
| 39 |
+
conda run --no-capture-output -n aigc python -m agent_core.eval.run --repeat 3
|
| 40 |
+
```
|
| 41 |
+
|
| 42 |
+
Each run writes git-ignored artifacts under `outputs/evals/<case_count>cases-<model_id>-<timestamp>/`:
|
| 43 |
+
|
| 44 |
+
- `metadata.json`: benchmark config for this run.
|
| 45 |
+
- `results.jsonl`: one record per case attempt.
|
| 46 |
+
- `summary.json`: aggregate hard metrics.
|
| 47 |
+
- `cases/<case_id>/<attempt_id>/`: copied model artifacts, manifest, transcript, and score.
|
| 48 |
+
|
| 49 |
+
The runner evaluates the full agent path: prompt -> model/tool call -> build123d execution -> STEP/STL export.
|
| 50 |
+
|
| 51 |
+
## Hard Metrics
|
| 52 |
+
|
| 53 |
+
The current runner records:
|
| 54 |
+
|
| 55 |
+
- `tool_success`: the tool returned `ok=true`.
|
| 56 |
+
- `manifest_written` and `manifest_json_ok`: the run manifest exists and parses.
|
| 57 |
+
- `step_export`: a `.step` or `.stp` file exists.
|
| 58 |
+
- `stl_preview`: `preview.stl` exists.
|
| 59 |
+
- `step_loadable`: build123d can load the exported STEP for checked cases.
|
| 60 |
+
- `bbox_check`: optional bounding-box dimension check from `hard_checks.json`.
|
| 61 |
+
- `latency_seconds`, `error_type`, and `error_stage`.
|
| 62 |
+
|
| 63 |
## Selection Criteria
|
| 64 |
|
| 65 |
- Keep only CAD generator manifests.
|
|
|
|
| 89 |
|
| 90 |
## Current Non-Goals
|
| 91 |
|
|
|
|
| 92 |
- No IoU, Chamfer Distance, F-score, or mesh metrics are computed yet.
|
| 93 |
+
- No topology or semantic automatic scoring is included yet.
|
| 94 |
- Multi-turn edit benchmarks should be built as a separate dataset because they require preserved conversation context.
|
benchmarks/cad_v1/hard_checks.json
ADDED
|
@@ -0,0 +1,77 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
{
|
| 2 |
+
"version": 1,
|
| 3 |
+
"bbox_checks": {
|
| 4 |
+
"ergonomic_table": {
|
| 5 |
+
"mode": "unordered",
|
| 6 |
+
"dimensions_mm": [
|
| 7 |
+
{"label": "width", "expected": 500, "tolerance": 50},
|
| 8 |
+
{"label": "height", "min": 680, "max": 800},
|
| 9 |
+
{"label": "length", "expected": 2000, "tolerance": 80}
|
| 10 |
+
]
|
| 11 |
+
},
|
| 12 |
+
"cable_spool_with_flanges": {
|
| 13 |
+
"mode": "unordered",
|
| 14 |
+
"dimensions_mm": [
|
| 15 |
+
{"label": "length", "min": 780, "max": 850},
|
| 16 |
+
{"label": "flange diameter", "expected": 1500, "tolerance": 60},
|
| 17 |
+
{"label": "flange diameter", "expected": 1500, "tolerance": 60}
|
| 18 |
+
]
|
| 19 |
+
},
|
| 20 |
+
"shaker_cabinet_door": {
|
| 21 |
+
"mode": "unordered",
|
| 22 |
+
"dimensions_mm": [
|
| 23 |
+
{"label": "thickness", "expected": 19, "tolerance": 3},
|
| 24 |
+
{"label": "width", "expected": 450, "tolerance": 10},
|
| 25 |
+
{"label": "height", "expected": 600, "tolerance": 10}
|
| 26 |
+
]
|
| 27 |
+
},
|
| 28 |
+
"shaker_door_with_euro_hinges": {
|
| 29 |
+
"mode": "unordered",
|
| 30 |
+
"dimensions_mm": [
|
| 31 |
+
{"label": "thickness", "expected": 19, "tolerance": 3},
|
| 32 |
+
{"label": "width", "expected": 450, "tolerance": 10},
|
| 33 |
+
{"label": "height", "expected": 600, "tolerance": 10}
|
| 34 |
+
]
|
| 35 |
+
},
|
| 36 |
+
"wpc_deck_with_subframe": {
|
| 37 |
+
"mode": "unordered",
|
| 38 |
+
"dimensions_mm": [
|
| 39 |
+
{"label": "height above ground", "min": 900, "max": 1200},
|
| 40 |
+
{"label": "width", "expected": 2000, "tolerance": 120},
|
| 41 |
+
{"label": "length", "expected": 5000, "tolerance": 180}
|
| 42 |
+
]
|
| 43 |
+
},
|
| 44 |
+
"stepped_shaft_keyway": {
|
| 45 |
+
"mode": "axis_aligned",
|
| 46 |
+
"dimensions_mm": [
|
| 47 |
+
{"label": "length along X", "axis": "x", "expected": 120, "tolerance": 3},
|
| 48 |
+
{"label": "max diameter Y", "axis": "y", "expected": 30, "tolerance": 3},
|
| 49 |
+
{"label": "max diameter Z", "axis": "z", "expected": 30, "tolerance": 3}
|
| 50 |
+
]
|
| 51 |
+
},
|
| 52 |
+
"interior_door_production_drawing": {
|
| 53 |
+
"mode": "unordered",
|
| 54 |
+
"dimensions_mm": [
|
| 55 |
+
{"label": "thickness", "expected": 116, "tolerance": 8},
|
| 56 |
+
{"label": "width", "expected": 780, "tolerance": 20},
|
| 57 |
+
{"label": "height", "expected": 2032, "tolerance": 30}
|
| 58 |
+
]
|
| 59 |
+
},
|
| 60 |
+
"boolean_cube_corner_cut": {
|
| 61 |
+
"mode": "unordered",
|
| 62 |
+
"dimensions_mm": [
|
| 63 |
+
{"label": "x", "expected": 10, "tolerance": 0.8},
|
| 64 |
+
{"label": "y", "expected": 10, "tolerance": 0.8},
|
| 65 |
+
{"label": "z", "expected": 10, "tolerance": 0.8}
|
| 66 |
+
]
|
| 67 |
+
},
|
| 68 |
+
"imperial_plywood_panel": {
|
| 69 |
+
"mode": "unordered",
|
| 70 |
+
"dimensions_mm": [
|
| 71 |
+
{"label": "thickness", "expected": 50.8, "tolerance": 4},
|
| 72 |
+
{"label": "width", "expected": 2438.4, "tolerance": 30},
|
| 73 |
+
{"label": "length", "expected": 3048, "tolerance": 30}
|
| 74 |
+
]
|
| 75 |
+
}
|
| 76 |
+
}
|
| 77 |
+
}
|