File size: 1,032 Bytes
16d4dce | 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 | from __future__ import annotations
from typing import Any
from reorgbench.runtime import Episode
from reorgbench.runtime.policy import AgentInfo, Observation
class Script:
"""Per-agent action lists; an agent with nothing left does noop."""
def __init__(self, plans: dict[str, list[dict[str, Any]]]):
self.plans = {k: list(v) for k, v in plans.items()}
self.seen: dict[str, list[Observation]] = {}
def __call__(self, info: AgentInfo):
script = self
class P:
def act(self, obs: Observation) -> dict[str, Any]:
script.seen.setdefault(info.id, []).append(obs)
plan = script.plans.get(info.id, [])
return plan.pop(0) if plan else {"type": "noop"}
return P()
def run_script(task, plans):
script = Script(plans)
res = Episode(task, script).run()
return res, script
def errors(res, kind=None):
return [e for e in res.events if e["type"] == "error" and (kind is None or e["payload"]["kind"] == kind)]
|