← Lesson
The Assembler Has a Budget
Joeven
Run
Reset
Python loads on first run
TOOLS_ALL = ["search", "get_ticket", "refund", "run_sql", "finish"] def assemble(goal, events, state, char_limit=80): legal = ["search", "get_ticket", "finish"] if state == "apply": legal = ["refund", "finish"] recent = events[-3:] ctx = { "goal": goal, "recent": recent, "tools": legal, } blob = str(ctx) if len(blob) > char_limit: ctx["recent"] = events[-1:] ctx["truncated"] = True else: ctx["truncated"] = False return ctx events = [ {"act": "search", "obs": "long " * 20}, {"act": "search", "obs": "still long"}, {"act": "get_ticket", "obs": "open"}, ] print(assemble("fix OOM", events, "gather", 40)["tools"]) print("truncated", assemble("fix OOM", events, "gather", 40)["truncated"]) print("apply tools", assemble("refund", events, "apply")["tools"]) print("gather has no refund", "refund" not in assemble("x", events, "gather")["tools"])
Run to execute this in your browser. Nothing is sent to a server.