edbeeching's picture
edbeeching HF Staff
Port 270 AgentEscapeBench tasks to Harbor with OpenEnv integration (part 2)
49aa045 verified
Raw History Blame Contribute Delete
2.88 kB
"""Corpus reference validation with Python actions delegated to an isolated worker."""
import argparse
import json
import logging
import time
from collections import Counter
from pathlib import Path
from .adapter import ROOT, task_id
from .oracle import solve
from .runtime.service import Episode, upstream
def main():
parser = argparse.ArgumentParser(description=__doc__)
parser.add_argument("--worker-url", required=True)
parser.add_argument("--report", type=Path, default=ROOT / "reports/corpus.json")
args = parser.parse_args()
logging.disable(logging.CRITICAL)
rows = []
started = time.monotonic()
for source in sorted(
(ROOT / "data/questions").glob("*/narrative/*.json"), key=task_id
):
scenario = json.loads(source.read_text())
episode = Episode(source, 500, worker_url=args.worker_url)
visited_templates = set()
def action(payload):
response = episode.dispatch(payload)
if payload["action"] == "tool_call" and response.get("ok"):
node = next(
n for n in scenario["nodes"] if n["id"] == payload["node_id"]
)
visited_templates.add(node["template_id"])
return response
row = {"task_id": task_id(source), "difficulty": int(source.parent.parent.name)}
try:
row.update(solve(scenario, action, episode.initial))
row["templates_executed"] = sorted(visited_templates)
except Exception as exc:
row.update(won=False, error=str(exc), actions=episode.count)
rows.append(row)
for mapping in (
upstream.SCENARIOS,
upstream.SIMULATORS,
upstream.RAW_NODES_DATA,
upstream.FILE_METADATA,
):
mapping.pop(episode.case_id, None)
if len(rows) % 30 == 0:
print(
f"Validated {len(rows)}/270, failures={sum(not r['won'] for r in rows)}",
flush=True,
)
report = {
"scope": "In-process upstream facade and public action oracle; Python execution uses isolated Docker worker. Not 270 Harbor container trials.",
"tasks": len(rows),
"successes": sum(r["won"] for r in rows),
"difficulty_counts": dict(Counter(row["difficulty"] for row in rows)),
"templates_executed": sorted(
{t for row in rows for t in row.get("templates_executed", [])}
),
"seconds": round(time.monotonic() - started, 2),
"results": rows,
}
args.report.parent.mkdir(parents=True, exist_ok=True)
args.report.write_text(json.dumps(report, indent=2) + "\n")
print(json.dumps({k: v for k, v in report.items() if k != "results"}))
raise SystemExit(0 if report["tasks"] == report["successes"] == 270 else 1)
if __name__ == "__main__":
main()