"""Print one saved agent run: each agent-browser call and the start of what came back.
Usage: python3 trace.py obscura r2 allbirds-price"""
import json, sys

engine, run, task = sys.argv[1:4]
d = next(d for d in json.load(open("agent-runs.json")) if (d["engine"], d["run"], d["task"]) == (engine, run, task))
for c in d["tool_calls"]:
    args = c["input"]["args"]
    print(f"$ agent-browser {args[:38] + ' ... ' + args[-24:] if len(args) > 66 else args}")
    out = " ".join(c["text"].split())
    print(f"  {out[:78] + '...' if len(out) > 80 else out or '(empty)'}")
print(f"\nanswer: {d['final'].splitlines()[0]}")
