Route the worker's subagents by their task's R + C, and keep seats and the security pass on the project's rung

This commit is contained in:
2026-10-15 00:09:22 +02:00
parent 1d00d3ee82
commit 258b7e4de5
14 changed files with 123 additions and 24 deletions
+5 -3
View File
@@ -22,10 +22,12 @@ def fresh(task: str, premises: str, route: Route, anchor: Rung | None) -> str:
def routed_by(route: Route, anchor: Rung | None) -> str:
said = f"loop-claude runs you on {route.rung}, routed by item {route.item}'s R + C of {route.risk_and_complexity}. Name each todo.md item this chunk takes, with its R + C, whether or not it is item {route.item}."
if anchor is None or highest(route.rung, anchor) == route.rung:
if anchor is None or route.rung == anchor:
return said
# The Agent tool takes a family name, such as opus, and runs that family's latest model; each rung names its family's latest, so the two match.
return f"{said} Your rung is below the project's, {anchor}: launch each reviewer, each comprehension seat and the security pass's subagent with the Agent tool's model `{anchor.model.split('-')[1]}` and effort `{anchor.effort}`, and run a full scan only from such a subagent, since the scan's agents run on the model that starts them."
# Below the project's rung, the reviewers stay on it to hold quality; above it, the seats score every chunk on one rung, and the security pass spends no more than the project chose.
below = highest(route.rung, anchor) == anchor
launched = "each reviewer, each comprehension seat and the security pass's subagent" if below else "each comprehension seat and the security pass's subagent"
return f"{said} Your rung is {'below' if below else 'above'} the project's, {anchor}: launch {launched} with the Agent tool's model `{anchor.family()}` and effort `{anchor.effort}`, and run a full scan only from such a subagent, since the scan's agents run on the model that starts them."
def resumed(unfinished_evidence: str) -> str:
+2 -1
View File
@@ -48,7 +48,8 @@ counts from the model's cheapest rung, and an R + C of 8 or less picks a rung be
such an item, or with a C missing, the chunk runs on the model's cheapest 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
R + C. When that rung is below the model's cheapest, the prompt also has the worker launch each
reviewer, each comprehension seat and the security pass in subagents on the cheapest rung. The
reviewer, each comprehension seat and the security pass in subagents on the cheapest rung; when it
is above, each comprehension seat and the security pass. The
judge reports the highest R + C the worker states, and the next cycle steps up to the rung that
R + C picks, never down. Every second unfinished verdict on a chunk steps it up one rung. Each
finished or unfinished verdict, stop and step-up in the archive names the worker's rung, with the
+6 -2
View File
@@ -541,8 +541,12 @@ class WorkerArgs(unittest.TestCase):
opus = Rung("claude-opus-5-5", "medium")
below = prompts.fresh("Do it.", "## Goals", routing.Route(Rung("claude-sonnet-5-5", "high"), 3, 5), opus)
self.assertIn("whether or not it is item 3. Your rung is below the project's, claude-opus-5-5 at medium effort: launch each reviewer, each comprehension seat and the security pass's subagent with the Agent tool's model `opus` and effort `medium`, and run a full scan only from such a subagent, since the scan's agents run on the model that starts them.\n\n", below)
for route in (routing.Route(opus, 3, 9), routing.Route(Rung("claude-opus-5-5", "high"), 3, 11)):
self.assertNotIn("below the project's", prompts.fresh("Do it.", "## Goals", route, opus))
self.assertNotIn("the project's", prompts.fresh("Do it.", "## Goals", routing.Route(opus, 3, 9), opus))
def test_keeps_seats_and_the_security_pass_on_the_projects_rung_while_the_worker_runs_above_it(self):
opus = Rung("claude-opus-5-5", "medium")
above = prompts.fresh("Do it.", "## Goals", routing.Route(Rung("claude-opus-5-5", "high"), 3, 11), opus)
self.assertIn("whether or not it is item 3. Your rung is above the project's, claude-opus-5-5 at medium effort: launch each comprehension seat and the security pass's subagent with the Agent tool's model `opus` and effort `medium`, and run a full scan only from such a subagent, since the scan's agents run on the model that starts them.\n\n", above)
def test_opens_a_fresh_session_by_name_and_resumes_an_open_one(self):
opened = session.session_named("A proj loop-claude", pathlib.Path("/h/.claude/projects"))
+4
View File
@@ -11,6 +11,10 @@ class Rung:
def flags(self) -> list[str]:
return ["--model", self.model, *(["--effort", self.effort] if self.effort else [])]
def family(self) -> str:
"""The model's family, such as opus, which the Agent tool takes as its model and runs that family's latest model; each rung names its family's latest, so the two match."""
return self.model.split("-")[1]
# The archive records this wording, and loop_claude.routing.ROUTED reads it back to resume a chunk on its rung.
def __str__(self) -> str:
return f"{self.model} at {self.effort} effort" if self.effort else self.model
+43
View File
@@ -0,0 +1,43 @@
"""Print the Agent tool's model and effort for a subagent's task: docs/decisions.md → `routing:`.
usage: subagent-rung <model> <R+C>
<model> is the project's model, such as claude-opus-5-5, and <R+C> the task's R + C, a whole
number from 2 to 20, scored as for a todo.md item. It prints the rung that R + C picks from the
model's cheapest rung, as the Agent tool takes it: `model sonnet, effort high`. A model off the
routing ladder routes nothing: it prints nothing, says so on stderr and exits 0, and the subagent
takes no model or effort.
Exit 1, saying why, on bad arguments.
"""
import re
import sys
from model_routing.ladder import picked, project_rung
USAGE = "usage: subagent-rung <model> <R+C>, R+C a whole number from 2 to 20"
def agent_args(model: str, risk_and_complexity: int) -> str | None:
"""The Agent tool's model and effort for the rung risk_and_complexity picks from model's cheapest rung; None for a model off the ladder."""
anchor = project_rung(model)
if anchor is None:
return None
rung = picked(anchor, risk_and_complexity)
return f"model {rung.family()}, effort {rung.effort}"
def main(argv: list[str]) -> int:
if argv[:1] in (["-h"], ["--help"]):
print(__doc__.strip())
return 0
if len(argv) != 2 or not re.fullmatch(r"[2-9]|1[0-9]|20", argv[1]):
print(f"subagent-rung: cannot read the arguments {' '.join(argv)}; {USAGE}", file=sys.stderr)
return 1
model, total = argv
args = agent_args(model, int(total))
if args is None:
print(f"subagent-rung: {model} is not on the routing ladder; pass the Agent tool no model or effort", file=sys.stderr)
else:
print(args)
return 0
+42
View File
@@ -0,0 +1,42 @@
import pathlib
import subprocess
import sys
import unittest
sys.path.insert(0, str(pathlib.Path(__file__).resolve().parents[1]))
from model_routing import subagent
TOOL = pathlib.Path(__file__).resolve().parents[1] / "subagent-rung"
class SubagentRung(unittest.TestCase):
def run_tool(self, *args: str) -> subprocess.CompletedProcess[str]:
return subprocess.run([sys.executable, str(TOOL), *args], capture_output=True, text=True)
def test_prints_the_agent_tools_model_and_effort_for_the_rung_an_r_plus_c_picks(self):
self.assertEqual(subagent.agent_args("claude-opus-5-5", 9), "model opus, effort medium")
self.assertEqual(subagent.agent_args("claude-opus-5-5", 7), "model sonnet, effort high")
self.assertEqual(subagent.agent_args("claude-opus-5-5", 20), "model fable, effort max")
self.assertEqual(subagent.agent_args("claude-haiku-5-5", 2), "model haiku, effort low")
def test_picks_nothing_for_a_model_off_the_ladder(self):
self.assertIsNone(subagent.agent_args("claude-opus-5", 9))
def test_refuses_an_r_plus_c_outside_2_to_20_or_a_wrong_count_of_arguments(self):
for argv in (["claude-opus-5-5", "1"], ["claude-opus-5-5", "21"], ["claude-opus-5-5", "x"], ["claude-opus-5-5"], ["9", "claude-opus-5-5"]):
result = self.run_tool(*argv)
self.assertEqual((result.returncode, result.stdout), (1, ""), argv)
self.assertIn("usage: subagent-rung <model> <R+C>", result.stderr)
def test_the_launcher_prints_the_rung_and_exits_0_on_and_off_the_ladder(self):
on = self.run_tool("claude-opus-5-5", "12")
self.assertEqual((on.returncode, on.stdout, on.stderr), (0, "model opus, effort high\n", ""))
off = self.run_tool("claude-opus-5", "12")
self.assertEqual((off.returncode, off.stdout), (0, ""))
self.assertEqual(off.stderr, "subagent-rung: claude-opus-5 is not on the routing ladder; pass the Agent tool no model or effort\n")
self.assertIn("usage: subagent-rung <model> <R+C>", self.run_tool("--help").stdout)
if __name__ == "__main__":
unittest.main()
+9
View File
@@ -0,0 +1,9 @@
#!/usr/bin/env python3
import pathlib
import sys
sys.path.insert(0, str(pathlib.Path(__file__).resolve().parent))
from model_routing import subagent
sys.exit(subagent.main(sys.argv[1:]))