HassamGani commited on
Commit ·
ac53f34
1
Parent(s): 7c3e66b
Add a no-questions variant
Browse files- reorgbench/cli.py +5 -2
- reorgbench/harness/policy.py +3 -2
- reorgbench/harness/prompts.py +11 -5
- reorgbench/harness/runner.py +13 -9
- reorgbench/runtime/episode.py +7 -3
- tests/test_questions.py +10 -0
reorgbench/cli.py
CHANGED
|
@@ -53,6 +53,8 @@ def main(argv: list[str] | None = None) -> int:
|
|
| 53 |
rn.add_argument("--matcher", default=None,
|
| 54 |
help="model that matches questions to the person's pre-written answers, or 'keyword' "
|
| 55 |
"(default: the pinned matcher model)")
|
|
|
|
|
|
|
| 56 |
rn.add_argument("--runs", type=int, default=1, help="runs per task")
|
| 57 |
rn.add_argument("--jobs", type=int, default=4, help="episodes in parallel")
|
| 58 |
rn.add_argument("--out", type=Path, required=True, help="output directory")
|
|
@@ -77,7 +79,7 @@ def main(argv: list[str] | None = None) -> int:
|
|
| 77 |
orch = make_client(args.model, effort=args.effort)
|
| 78 |
subs = make_client(args.subagent_model, effort=args.effort) if args.subagent_model else orch
|
| 79 |
args.out.mkdir(parents=True, exist_ok=True)
|
| 80 |
-
matcher = (KeywordMatcher() if args.matcher == "keyword" else
|
| 81 |
LLMMatcher(make_client(args.matcher or MATCHER_MODEL, effort="low", max_tokens=2000),
|
| 82 |
CallLog(args.out / "matcher.calls.jsonl")))
|
| 83 |
|
|
@@ -89,7 +91,8 @@ def main(argv: list[str] | None = None) -> int:
|
|
| 89 |
f"{r['rounds']} rounds, {r['tokens']} tokens, {r['calls']} calls)", flush=True)
|
| 90 |
|
| 91 |
print(f"running {len(tasks)} task(s) x {args.runs} with {orch.model} / {subs.model} -> {args.out}")
|
| 92 |
-
s = run_tasks(tasks, args.out, orch, subs, runs=args.runs, jobs=args.jobs, on_done=done, matcher=matcher
|
|
|
|
| 93 |
o = s["overall"]
|
| 94 |
print(f"success {_fmt(o['success'])} pass^k {_fmt(o['pass^k'])} staffing {_fmt(o['staffing'])} "
|
| 95 |
f"efficiency {_fmt(o['efficiency'])} message yield {_fmt(o['message_yield'])} "
|
|
|
|
| 53 |
rn.add_argument("--matcher", default=None,
|
| 54 |
help="model that matches questions to the person's pre-written answers, or 'keyword' "
|
| 55 |
"(default: the pinned matcher model)")
|
| 56 |
+
rn.add_argument("--no-questions", action="store_true",
|
| 57 |
+
help="variant where the orchestrator can't ask the person anything")
|
| 58 |
rn.add_argument("--runs", type=int, default=1, help="runs per task")
|
| 59 |
rn.add_argument("--jobs", type=int, default=4, help="episodes in parallel")
|
| 60 |
rn.add_argument("--out", type=Path, required=True, help="output directory")
|
|
|
|
| 79 |
orch = make_client(args.model, effort=args.effort)
|
| 80 |
subs = make_client(args.subagent_model, effort=args.effort) if args.subagent_model else orch
|
| 81 |
args.out.mkdir(parents=True, exist_ok=True)
|
| 82 |
+
matcher = (None if args.no_questions else KeywordMatcher() if args.matcher == "keyword" else
|
| 83 |
LLMMatcher(make_client(args.matcher or MATCHER_MODEL, effort="low", max_tokens=2000),
|
| 84 |
CallLog(args.out / "matcher.calls.jsonl")))
|
| 85 |
|
|
|
|
| 91 |
f"{r['rounds']} rounds, {r['tokens']} tokens, {r['calls']} calls)", flush=True)
|
| 92 |
|
| 93 |
print(f"running {len(tasks)} task(s) x {args.runs} with {orch.model} / {subs.model} -> {args.out}")
|
| 94 |
+
s = run_tasks(tasks, args.out, orch, subs, runs=args.runs, jobs=args.jobs, on_done=done, matcher=matcher,
|
| 95 |
+
questions=not args.no_questions)
|
| 96 |
o = s["overall"]
|
| 97 |
print(f"success {_fmt(o['success'])} pass^k {_fmt(o['pass^k'])} staffing {_fmt(o['staffing'])} "
|
| 98 |
f"efficiency {_fmt(o['efficiency'])} message yield {_fmt(o['message_yield'])} "
|
reorgbench/harness/policy.py
CHANGED
|
@@ -40,9 +40,10 @@ class CallLog:
|
|
| 40 |
|
| 41 |
class LLMPolicy:
|
| 42 |
def __init__(self, info: AgentInfo, client: LLMClient, log: CallLog, *, round_cap: int, action_cap: int,
|
| 43 |
-
today: str = "2026-10-15"):
|
| 44 |
self.info, self.client, self.log, self.round_cap = info, client, log, round_cap
|
| 45 |
-
self.system = system_prompt(info, round_cap=round_cap, action_cap=action_cap, today=today
|
|
|
|
| 46 |
self.history: list[dict[str, str]] = []
|
| 47 |
self.calls = 0
|
| 48 |
|
|
|
|
| 40 |
|
| 41 |
class LLMPolicy:
|
| 42 |
def __init__(self, info: AgentInfo, client: LLMClient, log: CallLog, *, round_cap: int, action_cap: int,
|
| 43 |
+
today: str = "2026-10-15", questions: bool = True):
|
| 44 |
self.info, self.client, self.log, self.round_cap = info, client, log, round_cap
|
| 45 |
+
self.system = system_prompt(info, round_cap=round_cap, action_cap=action_cap, today=today,
|
| 46 |
+
questions=questions)
|
| 47 |
self.history: list[dict[str, str]] = []
|
| 48 |
self.calls = 0
|
| 49 |
|
reorgbench/harness/prompts.py
CHANGED
|
@@ -62,7 +62,14 @@ How this works:
|
|
| 62 |
- Today is {today}."""
|
| 63 |
|
| 64 |
|
| 65 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 66 |
if info.role == "orchestrator":
|
| 67 |
roles = "\n".join(f"- {r}: {ROLES[r].description}" for r in info.catalog)
|
| 68 |
return f"""You are the orchestrator of a team working inside a company's systems. A person gives you a goal and may \
|
|
@@ -75,13 +82,12 @@ Roles you can hire (each can only use its own tools, plus the shared docs):
|
|
| 75 |
Your own tools:
|
| 76 |
{tool_lines(info.tools)}
|
| 77 |
|
| 78 |
-
{ACTIONS.replace("{extra}", MANAGER_ACTIONS + chr(10) + ORCH_ACTIONS)}
|
| 79 |
|
| 80 |
{RULES.replace("{today}", today)}
|
| 81 |
- Agents you hire can hire one level of helpers themselves. You are told whenever anyone is hired or shut down.
|
| 82 |
-
- Budget: at most {round_cap} rounds and {action_cap} actions for the whole team. Running out is a failure.
|
| 83 |
-
|
| 84 |
-
they won't look things up or do the work, and each question costs an action.
|
| 85 |
- Finishing ends the work for everyone. Only finish when the goal as it currently stands is fully done."""
|
| 86 |
|
| 87 |
can_hire = info.depth < 2
|
|
|
|
| 62 |
- Today is {today}."""
|
| 63 |
|
| 64 |
|
| 65 |
+
NO_QUESTIONS = ' {"type": "finish", "answer": "..."} end the episode when the goal is done'
|
| 66 |
+
QUESTION_RULE = """
|
| 67 |
+
- Only you can ask the person questions. They can confirm scope, priorities and who may do what, but \
|
| 68 |
+
they won't look things up or do the work, and each question costs an action."""
|
| 69 |
+
|
| 70 |
+
|
| 71 |
+
def system_prompt(info: AgentInfo, *, round_cap: int, action_cap: int, today: str = "2026-10-15",
|
| 72 |
+
questions: bool = True) -> str:
|
| 73 |
if info.role == "orchestrator":
|
| 74 |
roles = "\n".join(f"- {r}: {ROLES[r].description}" for r in info.catalog)
|
| 75 |
return f"""You are the orchestrator of a team working inside a company's systems. A person gives you a goal and may \
|
|
|
|
| 82 |
Your own tools:
|
| 83 |
{tool_lines(info.tools)}
|
| 84 |
|
| 85 |
+
{ACTIONS.replace("{extra}", MANAGER_ACTIONS + chr(10) + (ORCH_ACTIONS if questions else NO_QUESTIONS))}
|
| 86 |
|
| 87 |
{RULES.replace("{today}", today)}
|
| 88 |
- Agents you hire can hire one level of helpers themselves. You are told whenever anyone is hired or shut down.
|
| 89 |
+
- Budget: at most {round_cap} rounds and {action_cap} actions for the whole team. Running out is a failure.\
|
| 90 |
+
{QUESTION_RULE if questions else ""}
|
|
|
|
| 91 |
- Finishing ends the work for everyone. Only finish when the goal as it currently stands is fully done."""
|
| 92 |
|
| 93 |
can_hire = info.depth < 2
|
reorgbench/harness/runner.py
CHANGED
|
@@ -27,28 +27,32 @@ from .clients import LLMClient
|
|
| 27 |
from .policy import CallLog, LLMPolicy
|
| 28 |
|
| 29 |
|
| 30 |
-
def llm_factory(task: Task, orchestrator: LLMClient, subagents: LLMClient, log: CallLog
|
|
|
|
| 31 |
b = task.budgets
|
| 32 |
|
| 33 |
def make(info: AgentInfo) -> LLMPolicy:
|
| 34 |
client = orchestrator if info.role == "orchestrator" else subagents
|
| 35 |
-
return LLMPolicy(info, client, log, round_cap=b.round_cap, action_cap=b.action_cap, today=task.today
|
|
|
|
| 36 |
|
| 37 |
return make
|
| 38 |
|
| 39 |
|
| 40 |
def run_one(task: Task, k: int, out: Path, orchestrator: LLMClient, subagents: LLMClient,
|
| 41 |
-
matcher: Matcher | None = None) -> dict[str, Any]:
|
| 42 |
d = out / task.id
|
| 43 |
d.mkdir(parents=True, exist_ok=True)
|
| 44 |
calls = d / f"run{k}.calls.jsonl"
|
| 45 |
calls.unlink(missing_ok=True)
|
| 46 |
log = CallLog(calls)
|
| 47 |
t0 = time.monotonic()
|
| 48 |
-
ep = Episode(task, llm_factory(task, orchestrator, subagents, log), matcher=matcher
|
|
|
|
| 49 |
res = ep.run()
|
| 50 |
header = {**res.header(), "run": k, "orchestrator_model": orchestrator.model, "subagent_model": subagents.model,
|
| 51 |
-
"matcher": ep.matcher.id
|
|
|
|
| 52 |
write_jsonl(d / f"run{k}.jsonl", header, [Event(**e) for e in res.events])
|
| 53 |
s = score(task, res)
|
| 54 |
(d / f"run{k}.score.json").write_text(json.dumps(s, indent=1, default=str))
|
|
@@ -83,11 +87,11 @@ def summarize(rows: list[dict[str, Any]]) -> dict[str, Any]:
|
|
| 83 |
|
| 84 |
|
| 85 |
def run_with_reruns(task: Task, k: int, out: Path, orchestrator: LLMClient, subagents: LLMClient,
|
| 86 |
-
matcher: Matcher | None = None, reruns: int = 2) -> dict[str, Any]:
|
| 87 |
"""Repeat a run at the same index after an infrastructure failure; never take the best of several."""
|
| 88 |
for attempt in range(reruns + 1):
|
| 89 |
try:
|
| 90 |
-
row = run_one(task, k, out, orchestrator, subagents, matcher)
|
| 91 |
return row | {"infra_reruns": attempt}
|
| 92 |
except InfraError:
|
| 93 |
if attempt == reruns:
|
|
@@ -97,12 +101,12 @@ def run_with_reruns(task: Task, k: int, out: Path, orchestrator: LLMClient, suba
|
|
| 97 |
|
| 98 |
def run_tasks(tasks: list[Task], out: Path, orchestrator: LLMClient, subagents: LLMClient, *, runs: int = 1,
|
| 99 |
jobs: int = 4, on_done: Callable[[dict[str, Any]], None] | None = None,
|
| 100 |
-
matcher: Matcher | None = None) -> dict[str, Any]:
|
| 101 |
out.mkdir(parents=True, exist_ok=True)
|
| 102 |
rows: list[dict[str, Any]] = []
|
| 103 |
work = [(t, k) for t in tasks for k in range(runs)]
|
| 104 |
with ThreadPoolExecutor(max_workers=jobs) as pool:
|
| 105 |
-
futs = {pool.submit(run_with_reruns, t, k, out, orchestrator, subagents, matcher): (t.id, k) for t, k in work}
|
| 106 |
for f in as_completed(futs):
|
| 107 |
try:
|
| 108 |
row = f.result()
|
|
|
|
| 27 |
from .policy import CallLog, LLMPolicy
|
| 28 |
|
| 29 |
|
| 30 |
+
def llm_factory(task: Task, orchestrator: LLMClient, subagents: LLMClient, log: CallLog,
|
| 31 |
+
questions: bool = True) -> Callable[[AgentInfo], LLMPolicy]:
|
| 32 |
b = task.budgets
|
| 33 |
|
| 34 |
def make(info: AgentInfo) -> LLMPolicy:
|
| 35 |
client = orchestrator if info.role == "orchestrator" else subagents
|
| 36 |
+
return LLMPolicy(info, client, log, round_cap=b.round_cap, action_cap=b.action_cap, today=task.today,
|
| 37 |
+
questions=questions)
|
| 38 |
|
| 39 |
return make
|
| 40 |
|
| 41 |
|
| 42 |
def run_one(task: Task, k: int, out: Path, orchestrator: LLMClient, subagents: LLMClient,
|
| 43 |
+
matcher: Matcher | None = None, questions: bool = True) -> dict[str, Any]:
|
| 44 |
d = out / task.id
|
| 45 |
d.mkdir(parents=True, exist_ok=True)
|
| 46 |
calls = d / f"run{k}.calls.jsonl"
|
| 47 |
calls.unlink(missing_ok=True)
|
| 48 |
log = CallLog(calls)
|
| 49 |
t0 = time.monotonic()
|
| 50 |
+
ep = Episode(task, llm_factory(task, orchestrator, subagents, log, questions), matcher=matcher,
|
| 51 |
+
questions=questions)
|
| 52 |
res = ep.run()
|
| 53 |
header = {**res.header(), "run": k, "orchestrator_model": orchestrator.model, "subagent_model": subagents.model,
|
| 54 |
+
"matcher": ep.matcher.id if questions else None,
|
| 55 |
+
"questions_allowed": questions, "wall_s": round(time.monotonic() - t0, 1)}
|
| 56 |
write_jsonl(d / f"run{k}.jsonl", header, [Event(**e) for e in res.events])
|
| 57 |
s = score(task, res)
|
| 58 |
(d / f"run{k}.score.json").write_text(json.dumps(s, indent=1, default=str))
|
|
|
|
| 87 |
|
| 88 |
|
| 89 |
def run_with_reruns(task: Task, k: int, out: Path, orchestrator: LLMClient, subagents: LLMClient,
|
| 90 |
+
matcher: Matcher | None = None, questions: bool = True, reruns: int = 2) -> dict[str, Any]:
|
| 91 |
"""Repeat a run at the same index after an infrastructure failure; never take the best of several."""
|
| 92 |
for attempt in range(reruns + 1):
|
| 93 |
try:
|
| 94 |
+
row = run_one(task, k, out, orchestrator, subagents, matcher, questions)
|
| 95 |
return row | {"infra_reruns": attempt}
|
| 96 |
except InfraError:
|
| 97 |
if attempt == reruns:
|
|
|
|
| 101 |
|
| 102 |
def run_tasks(tasks: list[Task], out: Path, orchestrator: LLMClient, subagents: LLMClient, *, runs: int = 1,
|
| 103 |
jobs: int = 4, on_done: Callable[[dict[str, Any]], None] | None = None,
|
| 104 |
+
matcher: Matcher | None = None, questions: bool = True) -> dict[str, Any]:
|
| 105 |
out.mkdir(parents=True, exist_ok=True)
|
| 106 |
rows: list[dict[str, Any]] = []
|
| 107 |
work = [(t, k) for t in tasks for k in range(runs)]
|
| 108 |
with ThreadPoolExecutor(max_workers=jobs) as pool:
|
| 109 |
+
futs = {pool.submit(run_with_reruns, t, k, out, orchestrator, subagents, matcher, questions): (t.id, k) for t, k in work}
|
| 110 |
for f in as_completed(futs):
|
| 111 |
try:
|
| 112 |
row = f.result()
|
reorgbench/runtime/episode.py
CHANGED
|
@@ -88,9 +88,11 @@ class EpisodeResult:
|
|
| 88 |
|
| 89 |
|
| 90 |
class Episode:
|
| 91 |
-
def __init__(self, task: Task, factory: PolicyFactory, *, matcher: Matcher | None = None,
|
|
|
|
| 92 |
self.task, self.factory = task, factory
|
| 93 |
self.matcher: Matcher = matcher or KeywordMatcher()
|
|
|
|
| 94 |
self.world: World = task.world()
|
| 95 |
self.human = HumanSimulator(task.interventions)
|
| 96 |
self.events: list[Event] = []
|
|
@@ -360,6 +362,8 @@ class Episode:
|
|
| 360 |
def _do_ask_human(self, a: AgentState, act: dict, usage: dict) -> None:
|
| 361 |
if a.id != "orch":
|
| 362 |
return self._error(a, "permission", "only the orchestrator can ask the person", act, usage)
|
|
|
|
|
|
|
| 363 |
q = act.get("question")
|
| 364 |
if not isinstance(q, str) or not q.strip():
|
| 365 |
return self._error(a, "malformed", "ask_human needs 'question' (text)", act, usage)
|
|
@@ -404,9 +408,9 @@ class Episode:
|
|
| 404 |
|
| 405 |
@classmethod
|
| 406 |
def restore(cls, task: Task, snap: dict[str, Any], factory: PolicyFactory,
|
| 407 |
-
matcher: Matcher | None = None) -> "Episode":
|
| 408 |
snap = copy.deepcopy(snap)
|
| 409 |
-
ep = cls(task, factory, matcher=matcher, _blank=True)
|
| 410 |
ep.round, ep.phase = snap["round"], snap["phase"]
|
| 411 |
ep.events = [Event(**d) for d in snap["events"]]
|
| 412 |
ep.world = World.from_snapshot(snap["world"])
|
|
|
|
| 88 |
|
| 89 |
|
| 90 |
class Episode:
|
| 91 |
+
def __init__(self, task: Task, factory: PolicyFactory, *, matcher: Matcher | None = None,
|
| 92 |
+
questions: bool = True, _blank: bool = False):
|
| 93 |
self.task, self.factory = task, factory
|
| 94 |
self.matcher: Matcher = matcher or KeywordMatcher()
|
| 95 |
+
self.questions = questions # False: the no-questions variant, where ask_human is refused
|
| 96 |
self.world: World = task.world()
|
| 97 |
self.human = HumanSimulator(task.interventions)
|
| 98 |
self.events: list[Event] = []
|
|
|
|
| 362 |
def _do_ask_human(self, a: AgentState, act: dict, usage: dict) -> None:
|
| 363 |
if a.id != "orch":
|
| 364 |
return self._error(a, "permission", "only the orchestrator can ask the person", act, usage)
|
| 365 |
+
if not self.questions:
|
| 366 |
+
return self._error(a, "permission", "questions are turned off in this run", act, usage)
|
| 367 |
q = act.get("question")
|
| 368 |
if not isinstance(q, str) or not q.strip():
|
| 369 |
return self._error(a, "malformed", "ask_human needs 'question' (text)", act, usage)
|
|
|
|
| 408 |
|
| 409 |
@classmethod
|
| 410 |
def restore(cls, task: Task, snap: dict[str, Any], factory: PolicyFactory,
|
| 411 |
+
matcher: Matcher | None = None, questions: bool = True) -> "Episode":
|
| 412 |
snap = copy.deepcopy(snap)
|
| 413 |
+
ep = cls(task, factory, matcher=matcher, questions=questions, _blank=True)
|
| 414 |
ep.round, ep.phase = snap["round"], snap["phase"]
|
| 415 |
ep.events = [Event(**d) for d in snap["events"]]
|
| 416 |
ep.world = World.from_snapshot(snap["world"])
|
tests/test_questions.py
CHANGED
|
@@ -136,3 +136,13 @@ def test_only_the_orchestrator_prompt_offers_the_question_action():
|
|
| 136 |
obs = Observation("orch", "orchestrator", 2, 0, [
|
| 137 |
{"kind": "human_answer", "content": {"question": "ok?", "answer": "Yes."}, "event": 3}])
|
| 138 |
assert "answered your question (ok?): Yes." in render_observation(obs, 12)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 136 |
obs = Observation("orch", "orchestrator", 2, 0, [
|
| 137 |
{"kind": "human_answer", "content": {"question": "ok?", "answer": "Yes."}, "event": 3}])
|
| 138 |
assert "answered your question (ok?): Yes." in render_observation(obs, 12)
|
| 139 |
+
|
| 140 |
+
|
| 141 |
+
def test_no_questions_variant_refuses_asks_and_drops_them_from_the_prompt():
|
| 142 |
+
ask = {"type": "ask_human", "question": "Should the other onboarding steps keep their wording and order?"}
|
| 143 |
+
res = Episode(T1, lambda info: _Once(ask), questions=False).run()
|
| 144 |
+
assert [e["payload"]["kind"] for e in errors(res)] == ["permission"]
|
| 145 |
+
assert not any(e["type"] == "ask_human" for e in res.events)
|
| 146 |
+
info = AgentInfo("orch", "orchestrator", None, 0, "", 0, ["docs.read"], T1.catalog)
|
| 147 |
+
off = system_prompt(info, round_cap=12, action_cap=24, questions=False)
|
| 148 |
+
assert '"ask_human"' not in off and "ask the person" not in off and '"finish"' in off
|