Score risk as L + E + I, and route a worker on its item's L and its reviewers on its E + I
This commit is contained in:
@@ -2,33 +2,41 @@
|
||||
import dataclasses
|
||||
import re
|
||||
|
||||
from model_routing.ladder import Rung
|
||||
from todo_table import LEVELS
|
||||
from model_routing.ladder import Rung, WORKER_STEPS
|
||||
|
||||
# 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"
|
||||
ROUTED = re.compile(r"(?P<rung>.+?)(?:, routed by item (?P<item>[0-9]+)'s R \+ C of (?P<sum>[0-9]+))?")
|
||||
# A line an older loop-claude wrote, naming an R + C, reads as no route, so its chunk routes 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]+))?")
|
||||
|
||||
|
||||
@dataclasses.dataclass(frozen=True)
|
||||
class Route:
|
||||
"""A chunk's worker rung and the plan item whose R + C picked it, 0 for none.
|
||||
"""A chunk's worker rung, and the plan item that picked it, 0 for none, with its L, which picked the worker's rung, and its E + I, which picks its reviewers'.
|
||||
|
||||
unfinished counts the unfinished verdicts towards the next one-rung step; a reload hands it over with the rung.
|
||||
"""
|
||||
rung: Rung
|
||||
item: int = 0
|
||||
risk_and_complexity: int = 0
|
||||
likelihood: int = 0
|
||||
escape_and_impact: int = 0
|
||||
unfinished: int = 0
|
||||
|
||||
def __str__(self) -> str:
|
||||
"""What the archive records as each verdict's worker; ROUTED reads it back."""
|
||||
return f"{self.rung}, routed by item {self.item}'s R + C of {self.risk_and_complexity}" if self.item else str(self.rung)
|
||||
return f"{self.rung}, routed by item {self.item}'s L of {self.likelihood} and E + I of {self.escape_and_impact}" if self.item else str(self.rung)
|
||||
|
||||
|
||||
def route_from(worker: str) -> Route | None:
|
||||
"""The route an archived worker line names; None for a model run off the ladder."""
|
||||
"""The route an archived worker line names; None for a model run off the ladder, or levels off their scales."""
|
||||
found = ROUTED.fullmatch(worker)
|
||||
if not found:
|
||||
rung = Rung.parse(found["rung"]) if found else None
|
||||
if not found or not rung:
|
||||
return None
|
||||
rung = Rung.parse(found["rung"])
|
||||
return Route(rung, int(found["item"] or 0), int(found["sum"] or 0)) if rung else None
|
||||
if not found["item"]:
|
||||
return Route(rung)
|
||||
likelihood, escape_and_impact = int(found["likelihood"]), int(found["escape_and_impact"])
|
||||
if likelihood not in WORKER_STEPS or not 2 <= escape_and_impact <= LEVELS["E"] + LEVELS["I"]:
|
||||
return None
|
||||
return Route(rung, int(found["item"]), likelihood, escape_and_impact)
|
||||
|
||||
Reference in New Issue
Block a user