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:
2026-10-16 23:45:11 +02:00
parent ba4a00d6b7
commit 6df1833eb7
5 changed files with 42 additions and 38 deletions
+18 -18
View File
@@ -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)