Answer architecture round 1: 0 🔴, 5 🟡; keep a taken-in E + I only where it lifts the reviewers, outside stepped, parse the archived line once, point the help at the code, and name the field one way
This commit is contained in:
@@ -45,7 +45,7 @@ def rung_named(rung: Rung, route: Route, anchor: Rung) -> str:
|
||||
"""Why a review runs on rung: it is the project's, anchor, or the one the route's reviewed_on E + I picks, the item's or one taken in."""
|
||||
if rung == anchor:
|
||||
return "the project's rung"
|
||||
if route.escape_and_impact_taken_in > route.escape_and_impact:
|
||||
if route.escape_and_impact_taken_in:
|
||||
return f"the rung an E + I of {route.escape_and_impact_taken_in} taken into the chunk picks"
|
||||
return f"the rung item {route.item}'s E + I of {route.escape_and_impact} picks"
|
||||
|
||||
|
||||
@@ -63,10 +63,11 @@ loop-claude hands the worker's claude its own rung, the project's and the review
|
||||
LOOP_CLAUDE_WORKER_RUNG, LOOP_CLAUDE_PROJECT_RUNG and LOOP_CLAUDE_REVIEWER_RUNG, and rule-hook
|
||||
refuses a review launched below the rung named for it. The judge reports the highest L and the
|
||||
highest E + I the worker states for an item it takes in. The next cycle steps the worker up to the
|
||||
rung that L picks, never down, and the reviewers to the rung the higher of that E + I and the routed
|
||||
item's picks; a level off its scale counts as none. Every second unfinished
|
||||
verdict on a chunk steps it up one rung. So does an unfinished verdict on a worker that ended its
|
||||
run asking for a higher rung, once the judge quotes the transcript showing that the escalation
|
||||
rung that L picks, never down, and the reviewers to the rung the higher of that E + I and the
|
||||
routed item's picks (Route.reviewed_on in bin/model_routing/route.py); a level off its scale
|
||||
counts as none. Every second unfinished verdict on a chunk steps it up one rung (stepped in
|
||||
bin/loop_claude/routing.py). So does an unfinished verdict on a worker that ended its run asking
|
||||
for a higher rung, once the judge quotes the transcript showing that the escalation
|
||||
trigger it named fired (~/.claude/CLAUDE.md → "Working with the codebase" lists them). That step
|
||||
stops two rungs above the rung the chunk's item picks, and the worker's prompts offer it only while
|
||||
the worker is below that limit. Each finished or unfinished verdict, stop and step-up in the
|
||||
@@ -79,7 +80,7 @@ it routed on L. A todo.md or an archive that cannot be read or parsed is said on
|
||||
without it.
|
||||
|
||||
The judge of a model listed in JUDGE_REPLAYED (bin/loop_claude/routing.py) runs on the rung the
|
||||
reviewers' E + I picks for a review from that model: the routed item's, or a higher one taken in.
|
||||
reviewers' E + I, Route.reviewed_on, picks for a review from that model: the routed item's, or a higher one taken in.
|
||||
It never runs below the model's cheapest rung, and runs on it when no item routed the chunk or was
|
||||
taken in. Its rung stays put when the worker steps up. A model is listed once judge-replay found its cheapest rung returning every
|
||||
verdict the reference judge reproduced. Any other model's judge runs at the effort its settings
|
||||
@@ -223,7 +224,7 @@ def routed(loop_run: LoopRun, anchor: Rung | None, archived: typing.Callable[[],
|
||||
def after_verdict(loop_run: LoopRun, anchor: Rung | None, verdict: Finished | Unfinished) -> LoopRun:
|
||||
if isinstance(verdict, Finished):
|
||||
return dataclasses.replace(loop_run, route=None, unfinished_evidence="")
|
||||
route = stepped(anchor, loop_run.route, verdict.bundled, bool(verdict.escalation), verdict.bundled_escape_and_impact) if anchor and loop_run.route else loop_run.route
|
||||
route = stepped(anchor, loop_run.route, verdict.bundled, bool(verdict.escalation)).taking_in(verdict.bundled_escape_and_impact) if anchor and loop_run.route else loop_run.route
|
||||
return dataclasses.replace(loop_run, route=route, unfinished_evidence=verdict.evidence)
|
||||
|
||||
|
||||
|
||||
@@ -61,17 +61,16 @@ def escalation_cap(anchor: Rung, route: Route) -> Rung:
|
||||
return climbed(item_rung(anchor, route), ESCALATION_CAP)
|
||||
|
||||
|
||||
def stepped(anchor: Rung, route: Route, bundled: int, escalated: bool, bundled_escape_and_impact: int = 0) -> Route:
|
||||
"""The route after one more unfinished verdict. Its rules, in order: the rung never falls below kept_rung; a bundled item lifts it to the rung that item's L picks; every second unfinished verdict steps it up one rung; so does an escalation the judge found, up to escalation_cap, two rungs above item_rung; and both steps on one verdict make one step. The route keeps the highest E + I bundled so far, never a lower one.
|
||||
def stepped(anchor: Rung, route: Route, bundled: int, escalated: bool) -> Route:
|
||||
"""The route after one more unfinished verdict. Its rules, in order: the rung never falls below kept_rung; a bundled item lifts it to the rung that item's L picks; every second unfinished verdict steps it up one rung; so does an escalation the judge found, up to escalation_cap, two rungs above item_rung; and both steps on one verdict make one step.
|
||||
|
||||
bundled, escalated and bundled_escape_and_impact are the verdict's fields, not the verdict, since loop_claude.cycle.judge imports this module through prompts.
|
||||
bundled and escalated are the verdict's fields, not the verdict, since loop_claude.cycle.judge imports this module through prompts.
|
||||
"""
|
||||
rung = taken_in(anchor, route, bundled)
|
||||
unfinished = route.unfinished + 1
|
||||
counted_out = unfinished >= UNFINISHED_PER_STEP
|
||||
# The judge found the escalation trigger the worker cited in asking for a higher rung.
|
||||
escalates = escalated and position(rung) < position(escalation_cap(anchor, route))
|
||||
route = dataclasses.replace(route, escape_and_impact_taken_in=max(route.escape_and_impact_taken_in, bundled_escape_and_impact))
|
||||
if counted_out or escalates:
|
||||
return dataclasses.replace(route, rung=stepped_up(rung), unfinished=0)
|
||||
return dataclasses.replace(route, rung=rung, unfinished=unfinished)
|
||||
|
||||
@@ -624,11 +624,14 @@ class Routing(unittest.TestCase):
|
||||
self.assertEqual(routing.stepped(self.OPUS, Route(self.XHIGH), 0, True), Route(self.XHIGH, unfinished=1))
|
||||
self.assertEqual(routing.stepped(self.OPUS, Route(self.SONNET, 3, 2, 4), 4, True), Route(self.HIGH, 3, 2, 4, unfinished=1))
|
||||
|
||||
def test_keeps_the_highest_e_plus_i_the_judge_saw_taken_in_and_never_lowers_it(self):
|
||||
taken = routing.stepped(self.OPUS, Route(self.OPUS, 3, 3, 4), 0, False, 6)
|
||||
self.assertEqual(taken, Route(self.OPUS, 3, 3, 4, unfinished=1, escape_and_impact_taken_in=6))
|
||||
self.assertEqual(routing.stepped(self.OPUS, taken, 0, False, 5), Route(self.HIGH, 3, 3, 4, escape_and_impact_taken_in=6))
|
||||
self.assertEqual(routing.stepped(self.OPUS, Route(self.OPUS), 0, False, 5), Route(self.OPUS, unfinished=1, escape_and_impact_taken_in=5))
|
||||
def test_keeps_an_e_plus_i_taken_in_only_where_it_lifts_the_reviewers(self):
|
||||
taken = Route(self.OPUS, 3, 3, 4).taking_in(6)
|
||||
self.assertEqual(taken, Route(self.OPUS, 3, 3, 4, escape_and_impact_taken_in=6))
|
||||
self.assertEqual(taken.taking_in(5), taken)
|
||||
self.assertEqual(Route(self.OPUS, 3, 3, 4).taking_in(4), Route(self.OPUS, 3, 3, 4))
|
||||
self.assertEqual(Route(self.OPUS, 3, 3, 4).taking_in(3), Route(self.OPUS, 3, 3, 4))
|
||||
self.assertEqual(Route(self.OPUS).taking_in(5), Route(self.OPUS, escape_and_impact_taken_in=5))
|
||||
self.assertEqual(Route(self.OPUS).taking_in(0), Route(self.OPUS))
|
||||
|
||||
def test_a_rung_an_edit_took_off_the_ladder_counts_as_the_projects(self):
|
||||
self.assertEqual(routing.stepped(self.OPUS, Route(Rung("claude-opus-5-5", "low")), 0, False).rung, self.OPUS)
|
||||
@@ -645,7 +648,6 @@ class Routing(unittest.TestCase):
|
||||
|
||||
def test_runs_the_judge_on_the_rung_the_highest_e_plus_i_taken_in_picks(self):
|
||||
self.assertEqual(routing.judge_rung("claude-opus-5-5", Route(self.OPUS, 3, 3, 4, escape_and_impact_taken_in=6)), self.XHIGH)
|
||||
self.assertEqual(routing.judge_rung("claude-opus-5-5", Route(self.OPUS, 3, 3, 6, escape_and_impact_taken_in=5)), self.XHIGH)
|
||||
self.assertEqual(routing.judge_rung("claude-opus-5-5", Route(self.OPUS, escape_and_impact_taken_in=5)), self.HIGH)
|
||||
|
||||
def test_refuses_a_route_whose_item_has_levels_off_their_scales_or_levels_without_an_item(self):
|
||||
@@ -654,8 +656,8 @@ class Routing(unittest.TestCase):
|
||||
with self.assertRaises(ValueError):
|
||||
Route(self.HIGH, item, likelihood, escape_and_impact)
|
||||
|
||||
def test_refuses_a_route_taking_in_an_e_plus_i_off_its_scale(self):
|
||||
for taken_in in (1, 9, -1):
|
||||
def test_refuses_a_route_taking_in_an_e_plus_i_off_its_scale_or_not_above_its_items(self):
|
||||
for taken_in in (1, 9, -1, 5, 4):
|
||||
with self.subTest(taken_in=taken_in):
|
||||
with self.assertRaises(ValueError):
|
||||
Route(self.HIGH, 3, 4, 5, escape_and_impact_taken_in=taken_in)
|
||||
@@ -681,6 +683,7 @@ class Routing(unittest.TestCase):
|
||||
self.assertEqual(str(unrouted), "claude-opus-5-5 at high effort, taking in an E + I of 6")
|
||||
self.assertEqual(route_from(str(unrouted)), unrouted)
|
||||
self.assertIsNone(route_from("claude-opus-5-5 at high effort, taking in an E + I of 9"))
|
||||
self.assertIsNone(route_from("claude-opus-5-5 at high effort, routed by item 3's L of 4 and E + I of 5, taking in an E + I of 5"))
|
||||
|
||||
def test_reads_no_route_from_a_line_whose_levels_are_off_their_scales_or_an_r_plus_c_route_wrote(self):
|
||||
for line in ("claude-opus-5-5 at high effort, routed by item 3's L of 5 and E + I of 5", "claude-opus-5-5 at high effort, routed by item 3's L of 0 and E + I of 5", "claude-opus-5-5 at high effort, routed by item 3's L of 4 and E + I of 9", "claude-opus-5-5 at high effort, routed by item 3's L of 4 and E + I of 1", "claude-opus-5-5 at high effort, routed by item 3's R + C of 11"):
|
||||
@@ -782,6 +785,8 @@ class Steps(unittest.TestCase):
|
||||
after = main.after_verdict(main.LoopRun(cycle_number=1, root="/r", task="Do it.", unfinished_evidence="", route=before), self.OPUS, Unfinished("working", 0, bundled_escape_and_impact=6))
|
||||
self.assertIsNone(main.archive_step(archive, opened, after, before, FakeEffects().effects()))
|
||||
self.assertEqual(main.archived_route(archive, opened), Route(self.OPUS, 3, 3, 4, escape_and_impact_taken_in=6))
|
||||
lower = main.after_verdict(main.LoopRun(cycle_number=1, root="/r", task="Do it.", unfinished_evidence="", route=before), self.OPUS, Unfinished("working", 0, bundled_escape_and_impact=3))
|
||||
self.assertEqual(lower.route, Route(self.OPUS, 3, 3, 4, unfinished=1))
|
||||
|
||||
|
||||
class WorkerArgs(unittest.TestCase):
|
||||
@@ -812,7 +817,6 @@ class WorkerArgs(unittest.TestCase):
|
||||
def test_launches_reviewers_on_the_rung_the_highest_e_plus_i_taken_in_picks(self):
|
||||
opus = Rung("claude-opus-5-5", "medium")
|
||||
self.assertIn(f"loop-claude runs you on claude-opus-5-5 at medium effort. Launch each reviewer with the Agent tool set to model opus, effort max, the rung an E + I of 7 taken into the chunk picks. When an escalation trigger", prompts.resumed("", Route(opus, 3, 3, 5, escape_and_impact_taken_in=7), opus))
|
||||
self.assertIn(" Launch each reviewer with the Agent tool set to model opus, effort xhigh, the rung item 3's E + I of 6 picks.", prompts.resumed("", Route(opus, 3, 3, 6, escape_and_impact_taken_in=5), opus))
|
||||
self.assertIn(" Launch each reviewer with the Agent tool set to model opus, effort high, the rung an E + I of 5 taken into the chunk picks.", prompts.resumed("", Route(opus, escape_and_impact_taken_in=5), opus))
|
||||
|
||||
def test_keeps_seats_and_the_security_pass_on_the_projects_rung_while_the_worker_runs_above_it(self):
|
||||
|
||||
+18
-18
@@ -8,17 +8,17 @@ from model_routing.ladder import Rung
|
||||
|
||||
# How a worker opens the prompt of a subagent it escalates a task to, `Escalation trigger 2: …`: docs/decisions.md → `routing: a worker hands a task one rung up`.
|
||||
ESCALATION_MARKER = "Escalation trigger"
|
||||
# An archived worker line: the rung, then the item and the levels that routed it, if any, then the highest E + I taken in, if any. route_from reads only LEVELS_ROUTED's levels, so a line an older loop-claude wrote, naming an R + C, routes its chunk afresh; archived_worker still reads its rung for the routing figures.
|
||||
ROUTED = re.compile(r"(?P<rung>.+?)(?:, routed by item (?P<item>[0-9]+)'s (?P<levels>.+?))?(?:, taking in an E \+ I of (?P<taken_in>[0-9]+))?")
|
||||
LEVELS_ROUTED = re.compile(r"L of (?P<likelihood>[0-9]+) and E \+ I of (?P<escape_and_impact>[0-9]+)")
|
||||
# An archived worker line: the rung, then the item and the levels that routed it, if any, then the E + I taken in, if any. A line an older loop-claude wrote names an R + C in place of L and E + I: archived_worker reads its rung for the routing figures, and no levels, so route_from routes its chunk afresh.
|
||||
ROUTED = re.compile(r"(?P<rung>.+?)(?:, routed by item (?P<item>[0-9]+)'s (?:L of (?P<likelihood>[0-9]+) and E \+ I of (?P<escape_and_impact>[0-9]+)|.+?))?(?:, taking in an E \+ I of (?P<escape_and_impact_taken_in>[0-9]+))?")
|
||||
|
||||
|
||||
class ArchivedWorker(typing.NamedTuple):
|
||||
"""What an archived worker line names: the worker's rung, the item that routed it, 0 for none, the text naming that item's levels, which an older loop-claude wrote as an R + C, and the highest E + I taken in, 0 for none."""
|
||||
"""What an archived worker line names: the worker's rung, the item that routed it, its L and E + I, and the E + I taken in; 0 for each it does not name."""
|
||||
rung: Rung
|
||||
item: int
|
||||
levels: str
|
||||
taken_in: int = 0
|
||||
likelihood: int
|
||||
escape_and_impact: int
|
||||
escape_and_impact_taken_in: int
|
||||
|
||||
|
||||
def on_its_scale(escape_and_impact: int) -> bool:
|
||||
@@ -31,10 +31,10 @@ def on_their_scales(likelihood: int, escape_and_impact: int) -> bool:
|
||||
return 1 <= likelihood <= LEVELS["L"] and on_its_scale(escape_and_impact)
|
||||
|
||||
|
||||
def levels_fit(item: int, likelihood: int, escape_and_impact: int, taken_in: int = 0) -> bool:
|
||||
"""Whether a route may hold these: an item with levels on their scales, or no item and no levels; and no E + I taken in, or one on its scale."""
|
||||
def levels_fit(item: int, likelihood: int, escape_and_impact: int, escape_and_impact_taken_in: int = 0) -> bool:
|
||||
"""Whether a route may hold these: an item with levels on their scales, or no item and no levels; and no E + I taken in, or one on its scale above the item's, as Route.taking_in keeps."""
|
||||
routed = on_their_scales(likelihood, escape_and_impact) if item else not (likelihood or escape_and_impact)
|
||||
return routed and (taken_in == 0 or on_its_scale(taken_in))
|
||||
return routed and (escape_and_impact_taken_in == 0 or (on_its_scale(escape_and_impact_taken_in) and escape_and_impact_taken_in > escape_and_impact))
|
||||
|
||||
|
||||
@dataclasses.dataclass(frozen=True)
|
||||
@@ -63,6 +63,10 @@ class Route:
|
||||
"""Whether a route may be built from these fields, as the reload decoder asks of a handed one."""
|
||||
return levels_fit(fields.get("item", 0), fields.get("likelihood", 0), fields.get("escape_and_impact", 0), fields.get("escape_and_impact_taken_in", 0))
|
||||
|
||||
def taking_in(self, escape_and_impact: int) -> "Route":
|
||||
"""The route after the judge saw the worker take in an item of this E + I, 0 for none: it keeps the E + I only where it lifts reviewed_on, so the archive records no step-up that lifts nothing."""
|
||||
return dataclasses.replace(self, escape_and_impact_taken_in=escape_and_impact) if escape_and_impact > self.reviewed_on() else self
|
||||
|
||||
def reviewed_on(self) -> int:
|
||||
"""The E + I that picks the reviewers' and the judge's rung: the routed item's or the highest taken in, whichever is higher; 0 for neither."""
|
||||
return max(self.escape_and_impact, self.escape_and_impact_taken_in)
|
||||
@@ -78,18 +82,14 @@ def archived_worker(worker: str) -> ArchivedWorker | None:
|
||||
"""What an archived worker line names; None for a model run off the ladder."""
|
||||
found = ROUTED.fullmatch(worker)
|
||||
rung = Rung.parse(found["rung"]) if found else None
|
||||
return ArchivedWorker(rung, int(found["item"] or 0), found["levels"] or "", int(found["taken_in"] or 0)) if found and rung else None
|
||||
if not (found and rung):
|
||||
return None
|
||||
return ArchivedWorker(rung, *(int(found[name] or 0) for name in ("item", "likelihood", "escape_and_impact", "escape_and_impact_taken_in")))
|
||||
|
||||
|
||||
def route_from(worker: str) -> Route | None:
|
||||
"""The route an archived worker line names; None for a model run off the ladder, or a route by anything but levels on their scales."""
|
||||
archived = archived_worker(worker)
|
||||
if archived is None:
|
||||
if archived is None or not levels_fit(archived.item, archived.likelihood, archived.escape_and_impact, archived.escape_and_impact_taken_in):
|
||||
return None
|
||||
levels = LEVELS_ROUTED.fullmatch(archived.levels) if archived.item else None
|
||||
if archived.item and not levels:
|
||||
return None
|
||||
likelihood, escape_and_impact = (int(levels["likelihood"]), int(levels["escape_and_impact"])) if levels else (0, 0)
|
||||
if not levels_fit(archived.item, likelihood, escape_and_impact, archived.taken_in):
|
||||
return None
|
||||
return Route(archived.rung, archived.item, likelihood, escape_and_impact, escape_and_impact_taken_in=archived.taken_in)
|
||||
return Route(archived.rung, archived.item, archived.likelihood, archived.escape_and_impact, escape_and_impact_taken_in=archived.escape_and_impact_taken_in)
|
||||
|
||||
Reference in New Issue
Block a user