Answer architecture round 1: 0 🔴, 8 🟡; read old routes' rungs, write R in rank_todo, route reviews through review_rungs, file item 168

This commit is contained in:
2026-10-16 12:11:25 +02:00
parent 149108e8d8
commit 12909f233d
20 changed files with 141 additions and 94 deletions
+25 -15
View File
@@ -1,4 +1,4 @@
from model_routing.ladder import climbed, LADDER, position, review_rung, reviewers_rung, ReviewKind, Rung
from model_routing.ladder import climbed, LADDER, position, review_rungs, ReviewKind, Rung
from model_routing.route import ESCALATION_MARKER, Route
from loop_claude.routing import escalation_rungs
from loop_claude.project.records import HUMAN_RULE_NAMES, RECORD_FILES
@@ -14,6 +14,8 @@ QUOTE_SOURCES = either(("README.md's Goals and Audience", *RECORD_FILES, *HUMAN_
# Where the worker may write an answer the human typed, so it counts as recorded.
ANSWER_DESTINATIONS = "README.md's Goals or Audience, " + ", ".join(RECORD_FILES) + ", todo.md or a comment"
ANSWERS_RECORDED = f"every answer the human typed in it that a later chunk could need is recorded in {ANSWER_DESTINATIONS} at the one place it governs"
# Each kind of review, as review_launches names those it launches.
REVIEWS: tuple[tuple[str, ReviewKind], ...] = (("each reviewer", "reviewer"), ("each comprehension seat", "seat"), ("the security pass's subagent", "security"))
def fresh(task: str, premises: str, route: Route, anchor: Rung | None) -> str:
@@ -27,24 +29,33 @@ def routed_by(route: Route, anchor: Rung | None) -> str:
def review_launches(route: Route, anchor: Rung | None) -> str:
"""Which reviews to launch on a rung other than the worker's, and on which; below the project's rung, anchor, also where to launch a subagent that plans. Empty off the ladder, and where every review runs on the worker's rung."""
"""Which reviews to launch on a rung other than the worker's, and on which; below the project's rung, anchor, also where to launch a subagent that plans. Empty off the ladder, and where every review runs on the worker's rung.
For a worker on Sonnet 5.5 at high, on an Opus 5.5 project, routed by item 3 of E + I 5, it opens: ` Launch each reviewer with the Agent tool set to model opus, effort high, the rung item 3's E + I of 5 picks. Launch each comprehension seat and the security pass's subagent with the Agent tool set to model opus, effort medium, the project's rung.`
"""
if anchor is None:
return ""
reviewers = reviewers_rung(anchor, route.rung, route.escape_and_impact)
# The seats score every chunk on one rung, and the security pass spends no more than the project chose. Where the reviewers' rung is anchor too, anchor's name wins.
named = {reviewers: f"the rung item {route.item}'s E + I of {route.escape_and_impact} picks", anchor: "the project's rung"}
rungs = review_rungs(anchor, route.rung, route.escape_and_impact)
launched: dict[Rung, list[str]] = {}
kinds: tuple[tuple[str, ReviewKind], ...] = (("each reviewer", "reviewer"), ("each comprehension seat and the security pass's subagent", "seat"))
for reviews, kind in kinds:
rung = review_rung(kind, anchor, reviewers)
if rung != route.rung:
launched.setdefault(rung, []).append(reviews)
launches = "".join(f" Launch {', '.join(reviews)} with the Agent tool set to {rung.agent_args()}, {named[rung]}." for rung, reviews in launched.items())
scan = " Run a full scan only from such a subagent, since the scan's agents run on the model that starts them." if anchor != route.rung else ""
for reviews, kind in REVIEWS:
if rungs[kind] != route.rung:
launched.setdefault(rungs[kind], []).append(reviews)
launches = "".join(f" Launch {listed(reviews)} with the Agent tool set to {rung.agent_args()}, {rung_named(rung, route, anchor)}." for rung, reviews in launched.items())
scan = " Run a full scan only from such a subagent, since the scan's agents run on the model that starts them." if rungs["security"] != route.rung else ""
planning = f" Your rung is below the project's: launch each subagent that files or scores todo.md items on the rung `~/.claude/bin/subagent-rung --plan {anchor.model} <L>` prints." if position(route.rung) < position(anchor) else ""
return f"{launches}{scan}{planning}"
def listed(names: list[str]) -> str:
"""The names as `a, b and c`."""
return names[0] if len(names) == 1 else f"{', '.join(names[:-1])} and {names[-1]}"
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 item's E + I picks."""
return "the project's rung" if rung == anchor else f"the rung item {route.item}'s E + I of {route.escape_and_impact} picks"
def escalation(route: Route, anchor: Rung | None) -> str:
"""The prompt's escalation sentences, the marker's among them. Empty off the ladder or on its top rung. Where escalation_rungs opens none, the worker escalates only with the human's yes.
Else they name the rungs escalation_rungs opens to a subagent, and offer to resume the worker one rung up for the rest of the chunk, up to the highest of those rungs."""
@@ -63,9 +74,8 @@ def reruns(route: Route, anchor: Rung | None) -> str:
"""The prompt's sentence naming the rung one above a reviewer's and a seat's, on which each reruns when it asks; empty off the ladder, and leaving out one already on the top rung."""
if anchor is None or route.rung not in LADDER:
return ""
# The rungs review_launches launches them on.
reviewers = reviewers_rung(anchor, route.rung, route.escape_and_impact)
launched = (("reviewer", review_rung("reviewer", anchor, reviewers)), ("comprehension seat", review_rung("seat", anchor, reviewers)))
rungs = review_rungs(anchor, route.rung, route.escape_and_impact)
launched = (("reviewer", rungs["reviewer"]), ("comprehension seat", rungs["seat"]))
rerun = {name: climbed(rung, 1) for name, rung in launched if rung != LADDER[-1]}
if not rerun:
return ""
+5 -5
View File
@@ -45,10 +45,10 @@ Where that model is on the routing ladder (bin/model_routing/ladder.py), the wor
interrupt run on one of the ladder's rungs: a model at an effort. As a chunk starts, todo.md's top
item in the next release that does not wait routes it: an item waits while it is marked question,
or while an item that blocks it is still in the table. The item's L picks the worker's rung,
counted from the model's cheapest rung, and an L of 2 or less picks a rung below it; without such
an item, or with no L, the chunk runs on the model's cheapest rung. The item's E + I picks the
reviewers' rung, never below the worker's or the cheapest rung, and an E + I of 5 or more picks a
rung above the cheapest. The worker's first prompt names the rung and the item, and asks the worker to
stepping from the model's cheapest rung by WORKER_STEPS in bin/model_routing/ladder.py, below it
for a low L; without such an item, or with no L, the chunk runs on the model's cheapest rung. The
item's E + I picks the reviewers' rung, stepping up from the cheapest rung by REVIEW_STEPS there,
never below the worker's rung. The worker's first prompt names the rung and the item, and asks the worker to
name each item the chunk takes, with its L and E + I. The prompt has the worker launch each review
that runs on a rung other than its own on that rung: the reviewers on theirs, and each
comprehension seat and the security pass on the cheapest rung. Below the cheapest rung, it has the
@@ -115,7 +115,7 @@ Exit 1, saying why, when:
worker fails when claude cannot start, exits non-zero, is killed, or ends without a result event;
a judge when claude cannot start, exits non-zero or prints no json reply, or its reply misses or
mistypes a field, interrupts or quotes an answer without a question, gives an unfinished verdict
an L outside 0 to 4, or quotes a passage the transcript does not hold; it holds an elided
an L off its scale, or quotes a passage the transcript does not hold; it holds an elided
passage when each fragment appears in order.
A usage limit is not a failure, and restarts the count of three: the worker or the judge is
retried 2 minutes after the limit resets, or every 10 minutes when the reset time is unknown or
+1 -1
View File
@@ -62,7 +62,7 @@ def escalation_cap(anchor: Rung, route: Route) -> Rung:
def stepped(anchor: Rung, route: Route, bundled: int, escalated: bool) -> Route:
"""The route after one more unfinished verdict, never on a lower rung.
"""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 and escalated are the verdict's fields, not the verdict, since loop_claude.cycle.judge imports this module through prompts.
"""
+1 -1
View File
@@ -979,7 +979,7 @@ class JudgeFailures(unittest.TestCase):
("verdict_from", 'f"the judge\'s reply has no {name}', field),
("verdict_from", "'the judge interrupted without a question'", unasked),
("verdict_from", "'the judge quoted an answer without a question'", unasked),
("verdict_from", 'f"the judge\'s bundled L', "gives an unfinished verdict an L outside 0 to 4"),
("verdict_from", 'f"the judge\'s bundled L', "gives an unfinished verdict an L off its scale"),
("run_judge", "f'{verdict.reason}; it replied:", field),
("run_judge", "f'the judge quoted {verdict.evidence!r}, which is not in the transcript", "quotes a passage the transcript does not hold"),
("claude_reply", "f'could not start claude:", started),