Answer architecture round 1: 1 🔴, 5 🟡; track bin/model_routing, hand over the route by its rung, share the R + C mapping, record the routing item, and have the judge report R + C plainly
This commit is contained in:
@@ -20,10 +20,10 @@ from loop_claude.effects import Effects
|
||||
from claude_code import entries, session
|
||||
from failure import Failure
|
||||
from loop_claude.cycle.judge import Finished, Interrupt, QuotedAnswer, Unfinished, verdict_from
|
||||
from loop_claude.cycle import interrupt, judge, prompts, retry, routing, run, states, worker
|
||||
from loop_claude.cycle import interrupt, judge, prompts, retry, run, states, worker
|
||||
from model_routing.ladder import LADDER, project_rung, Rung
|
||||
from loop_claude.cycle.retry import Limited
|
||||
from loop_claude.loop import main, reload
|
||||
from loop_claude.loop import main, reload, routing
|
||||
from loop_claude import paths
|
||||
from transcript_archive.location import project_archive
|
||||
from loop_claude.stop import Stop
|
||||
@@ -170,7 +170,7 @@ class Cycles(unittest.TestCase):
|
||||
self.archive = project_archive(str(self.home / "code" / "proj"), self.home, {})
|
||||
|
||||
def cycle(self, fake, records="", unfinished_evidence=""):
|
||||
return run.Cycle(effects=fake.effects(), judge_model="judge-model", paths=self.paths, premises="## Goals", project_archive=self.archive, records=records, root=str(self.home), routed="", session=self.session, task="Do it.", unfinished_evidence=unfinished_evidence, worker=Rung("worker-model"))
|
||||
return run.Cycle(effects=fake.effects(), judge_model="judge-model", paths=self.paths, premises="## Goals", project_archive=self.archive, records=records, root=str(self.home), route=routing.Route(Rung("worker-model")), session=self.session, task="Do it.", unfinished_evidence=unfinished_evidence)
|
||||
|
||||
def archived_outcomes(self):
|
||||
return sorted(path.read_text() for path in self.archive.glob("*/*.outcomes.md"))
|
||||
@@ -396,6 +396,8 @@ TODO = """# todo
|
||||
|
||||
|
||||
class Routing(unittest.TestCase):
|
||||
OPUS = project_rung("claude-opus-5-5")
|
||||
|
||||
def test_routes_on_the_next_releases_top_item_that_waits_on_no_question(self):
|
||||
self.assertEqual(routing.routed_item(TODO).id, 3)
|
||||
self.assertIsNone(routing.routed_item(TODO.replace("| | **Do", "| question | **Do")))
|
||||
@@ -403,30 +405,35 @@ class Routing(unittest.TestCase):
|
||||
self.assertIsNone(routing.routed_item(TODO.replace("| 5 | 3 |", "| x | 3 |")))
|
||||
|
||||
def test_starts_a_chunk_on_the_rung_its_items_r_plus_c_picks_never_below_the_projects(self):
|
||||
opus = project_rung("claude-opus-5-5")
|
||||
item = routing.routed_item(TODO)
|
||||
self.assertEqual(LADDER[routing.first_rung(opus, item)], Rung("claude-opus-5-5", "high"))
|
||||
self.assertEqual(routing.first_route(self.OPUS, routing.routed_item(TODO)), routing.Route(Rung("claude-opus-5-5", "high"), 3, 11))
|
||||
cheap = routing.routed_item(TODO.replace("| 5 | 3 | 6 |", "| 1 | 3 | 1 |"))
|
||||
self.assertEqual(routing.first_rung(opus, cheap), opus)
|
||||
self.assertEqual(routing.first_rung(opus, None), opus)
|
||||
self.assertEqual(routing.first_route(self.OPUS, cheap), routing.Route(LADDER[self.OPUS], 3, 2))
|
||||
self.assertEqual(routing.first_route(self.OPUS, None), routing.Route(LADDER[self.OPUS]))
|
||||
|
||||
def test_steps_up_a_rung_after_every_second_unfinished_verdict(self):
|
||||
opus = project_rung("claude-opus-5-5")
|
||||
self.assertEqual(routing.stepped(opus, opus, 0, 0), (opus, 1))
|
||||
self.assertEqual(routing.stepped(opus, opus, 1, 0), (opus + 1, 0))
|
||||
self.assertEqual(routing.stepped(opus, len(LADDER) - 1, 1, 0), (len(LADDER) - 1, 0))
|
||||
route = routing.Route(LADDER[self.OPUS], 3, 9)
|
||||
once = routing.stepped(self.OPUS, route, 0)
|
||||
self.assertEqual(once, routing.Route(LADDER[self.OPUS], 3, 9, 1))
|
||||
self.assertEqual(routing.stepped(self.OPUS, once, 0), routing.Route(LADDER[self.OPUS + 1], 3, 9, 0))
|
||||
self.assertEqual(routing.stepped(self.OPUS, routing.Route(LADDER[-1], unfinished=1), 0).rung, LADDER[-1])
|
||||
|
||||
def test_steps_up_to_the_rung_a_bundled_items_r_plus_c_picks_and_never_down(self):
|
||||
opus = project_rung("claude-opus-5-5")
|
||||
self.assertEqual(routing.stepped(opus, opus, 0, 13), (opus + 2, 1))
|
||||
self.assertEqual(routing.stepped(opus, opus + 2, 0, 11), (opus + 2, 1))
|
||||
self.assertEqual(routing.stepped(opus, opus, 1, 13), (opus + 3, 0))
|
||||
self.assertEqual(routing.stepped(self.OPUS, routing.Route(LADDER[self.OPUS]), 13).rung, LADDER[self.OPUS + 2])
|
||||
self.assertEqual(routing.stepped(self.OPUS, routing.Route(LADDER[self.OPUS + 2]), 11).rung, LADDER[self.OPUS + 2])
|
||||
self.assertEqual(routing.stepped(self.OPUS, routing.Route(LADDER[self.OPUS], unfinished=1), 13).rung, LADDER[self.OPUS + 3])
|
||||
|
||||
def test_a_rung_an_edit_took_off_the_ladder_counts_as_the_projects(self):
|
||||
self.assertEqual(routing.stepped(self.OPUS, routing.Route(Rung("claude-opus-5-5", "low")), 0).rung, LADDER[self.OPUS])
|
||||
|
||||
def test_names_the_item_that_routed_the_chunk(self):
|
||||
self.assertEqual(str(routing.Route(Rung("claude-opus-5-5", "high"), 3, 11)), "claude-opus-5-5 at high effort, routed by item 3's R + C of 11")
|
||||
self.assertEqual(str(routing.Route(Rung("worker-model"))), "worker-model")
|
||||
|
||||
|
||||
class WorkerArgs(unittest.TestCase):
|
||||
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"))
|
||||
fresh = worker.worker_args(opened, Rung("m"), prompts.fresh("Do it.", "## Goals\n1. g\n\n## Audience\nme"), resume=False)
|
||||
fresh = worker.worker_args(opened, Rung("m"), prompts.fresh("Do it.", "## Goals\n1. g\n\n## Audience\nme", routing.Route(Rung("m"))), resume=False)
|
||||
self.assertEqual(fresh[fresh.index("--session-id") + 1], str(opened.id))
|
||||
self.assertEqual(fresh[fresh.index("--name") + 1], "A proj loop-claude")
|
||||
resumed = worker.worker_args(opened, Rung("m"), prompts.resumed(""), resume=True)
|
||||
@@ -535,6 +542,17 @@ class LoopRuns(unittest.TestCase):
|
||||
self.assertEqual(reload.decode_handed('{"count": 1, "name": "n"}', Stringly), Stringly(1, "n"))
|
||||
self.assertIsNone(reload.decode_handed('{"count": "1", "name": "n"}', Stringly))
|
||||
|
||||
def test_decodes_a_route_inside_the_state_or_none(self):
|
||||
state = main.LoopRun(cycle_number=1, root="/r", task="do it", unfinished_evidence="", route=routing.Route(Rung("claude-opus-5-5", "high"), 3, 11, 1))
|
||||
self.assertEqual(reload.decode_handed(json.dumps(dataclasses.asdict(state)), main.LoopRun), state)
|
||||
unrouted = dataclasses.replace(state, route=None)
|
||||
self.assertEqual(reload.decode_handed(json.dumps(dataclasses.asdict(unrouted)), main.LoopRun), unrouted)
|
||||
handed = dataclasses.asdict(state)
|
||||
handed["route"]["rung"]["effort"] = 1
|
||||
self.assertIsNone(reload.decode_handed(json.dumps(handed), main.LoopRun))
|
||||
del handed["route"]["rung"]
|
||||
self.assertIsNone(reload.decode_handed(json.dumps(handed), main.LoopRun))
|
||||
|
||||
def test_stops_when_the_reload_cannot_start_python(self):
|
||||
with tempfile.TemporaryDirectory() as root:
|
||||
launcher = pathlib.Path(root, "loop-claude")
|
||||
|
||||
Reference in New Issue
Block a user