File size: 4,645 Bytes
f210f00 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 | #!/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")
|