Download code/oracle_vc_bench.py from badr7/rapidchat-data: direct link, hf CLI and curl.
- Browser
- Download file 4.65 kB
-
https://huggingface.co/datasets/badr7/rapidchat-data/resolve/main/code/oracle_vc_bench.py
- Command line
-
hf download hf://datasets/badr7/rapidchat-data/code/oracle_vc_bench.py
-
curl -L -o oracle_vc_bench.py https://huggingface.co/datasets/badr7/rapidchat-data/resolve/main/code/oracle_vc_bench.py
4.65 kB
| #!/usr/bin/env python3 | |
| """Scores hand-built conversations with tau2's own evaluator, to prove the bench grades the way it should. | |
| Five scripted agents per scenario: | |
| perfect does exactly the gold steps and says the required amounts -> must score 1 | |
| reversed does the gold steps in reverse order -> must score 1 (order must not matter) | |
| (skipped for upgrade-then-change, where the order is the whole point) | |
| shortcut upgrade-then-change done as one combined call -> must score 0 (policy: cabin first, then flights) | |
| lazy does nothing -> must score 0 unless nothing should change | |
| half does only the first gold step of a multi-step scenario -> must score 0 | |
| caving gives in on a cancellation that policy forbids -> must score 0 | |
| Run with the python of a tau2 checkout where vc_install.py has been run. | |
| usage: oracle_vc_bench.py <split name> [max scenarios, 0 = all] [only this family] | |
| """ | |
| import collections | |
| import json | |
| import sys | |
| from loguru import logger | |
| logger.remove() | |
| from tau2.data_model.message import AssistantMessage, ToolCall, UserMessage | |
| from tau2.data_model.simulation import SimulationRun, TerminationReason | |
| from tau2.evaluator.evaluator import EvaluationType, evaluate_simulation | |
| from tau2.registry import registry | |
| split = sys.argv[1] | |
| limit = int(sys.argv[2]) if len(sys.argv) > 2 else None | |
| only = sys.argv[3] if len(sys.argv) > 3 else None | |
| tasks = registry.get_tasks_loader("vc_airline")(split) | |
| if only: | |
| tasks = [t for t in tasks if json.loads(t.description.notes)["family"] == only] | |
| if limit: | |
| tasks = tasks[:: max(1, len(tasks) // limit)][:limit] | |
| make_env = registry.get_env_constructor("vc_airline") | |
| def play(task, steps, say=""): | |
| """A conversation in which the agent makes these tool calls and then says `say`.""" | |
| env = make_env() | |
| msgs = [AssistantMessage(role="assistant", content="Hi! How can I help you today?"), | |
| UserMessage(role="user", content="Hello, I need some help with my travel plans.")] | |
| for i, (name, args) in enumerate(steps): | |
| call = ToolCall(id="call_%d" % i, name=name, arguments=json.loads(json.dumps(args)), requestor="assistant") | |
| msgs.append(AssistantMessage(role="assistant", content=None, tool_calls=[call])) | |
| msgs.append(env.get_response(call)) | |
| msgs.append(AssistantMessage(role="assistant", content="That is all taken care of. " + say)) | |
| msgs.append(UserMessage(role="user", content="Thank you, goodbye. ###STOP###")) | |
| sim = SimulationRun(id="oracle", task_id=task.id, timestamp="2026-01-01T00:00:00", start_time="2026-01-01T00:00:00", | |
| end_time="2026-01-01T00:00:01", duration=1.0, termination_reason=TerminationReason.USER_STOP, | |
| messages=msgs) | |
| return evaluate_simulation(simulation=sim, task=task, evaluation_type=EvaluationType.ALL, solo_mode=False, | |
| domain="vc_airline").reward | |
| wrong = collections.defaultdict(list) | |
| count = collections.Counter() | |
| for n, task in enumerate(tasks): | |
| meta = json.loads(task.description.notes) | |
| gold = [(a.name, a.arguments) for a in task.evaluation_criteria.actions] | |
| say = " ".join("The total is $%s." % c for c in task.evaluation_criteria.communicate_info or []) | |
| needs_work = bool(gold) or bool(task.evaluation_criteria.communicate_info) | |
| runs = {"perfect": (gold, say, 1.0), "lazy": ([], "", 0.0 if needs_work else 1.0)} | |
| if len(gold) > 1: | |
| if meta["family"] == "upgrade_then_change": | |
| runs["shortcut"] = (gold[1:], say, 0.0) | |
| else: | |
| runs["reversed"] = (gold[::-1], say, 1.0) | |
| runs["half"] = (gold[:1], say, 0.0) | |
| if meta["family"] in ("cancel_denied", "cancel_flown") and meta.get("reservation"): | |
| runs["caving"] = ([("cancel_reservation", {"reservation_id": meta["reservation"]})], "", 0.0) | |
| for name, (steps, said, want) in runs.items(): | |
| count[name] += 1 | |
| try: | |
| got = play(task, steps, said) | |
| except Exception as e: | |
| got = "error: " + repr(e)[:120] | |
| if got != want: | |
| wrong[name].append((task.id, got)) | |
| if n % 40 == 0: | |
| print(" ...", n, "of", len(tasks), flush=True) | |
| print("split:", split, "| scenarios:", len(tasks)) | |
| for name in ("perfect", "reversed", "lazy", "half", "caving", "shortcut"): | |
| print(" %-9s %4d conversations scored by tau2, %d graded wrongly %s" % (name, count[name], len(wrong[name]), wrong[name][:5] or "")) | |
| print("ORACLE CHECK", "PASSED" if not any(wrong.values()) else "FAILED") | |