Answer architecture round 1: 3 🔴, 8 🟡; have the judge quote the worker's record of the trigger word for word, name the worker's rung on resume, give kept and stepped one floor and name stepped's two conditions
This commit is contained in:
@@ -30,7 +30,8 @@ JUDGE_RULES = (
|
||||
"- it chose between alternatives that neither README.md nor the records discriminate "
|
||||
"between - neither rules the rejected one out - and the choice materially changes the deliverable\n"
|
||||
"interrupt=false otherwise. Bookkeeping the agent settled silently - what to document, wording, "
|
||||
"where a note goes - is not on its own a reason to interrupt. The human may have replied inside the transcript, on a [human] line: judge only what "
|
||||
"where a note goes - is not on its own a reason to interrupt, nor is a run ending with a request for a higher rung, "
|
||||
"which is for loop-claude. The human may have replied inside the transcript, on a [human] line: judge only what "
|
||||
"is still open, never a question they already answered there. A [loop] line is what loop-claude told "
|
||||
"the agent, such as an answer quoted from README.md or the records.\n\n"
|
||||
"Where the agent asked or flagged something itself, the question is that one, in the agent's own "
|
||||
@@ -45,11 +46,7 @@ JUDGE_RULES = (
|
||||
f"where README.md or the records above hold it, {', '.join(HUMAN_RULE_NAMES)} included. It also counts where "
|
||||
f"the transcript shows the agent writing it into {ANSWER_DESTINATIONS}; writing it into "
|
||||
f"{either(HUMAN_RULE_NAMES)} does not count. finished=false when work remains that a further run can "
|
||||
"continue: an open PR, a review not yet run, CI not yet reported, an answer not yet recorded.\n\n"
|
||||
"The agent may end its run asking for a higher rung, citing an escalation trigger that ~/.claude/CLAUDE.md lists. "
|
||||
"That request is for loop-claude, not a question for the human. Where the chunk is unfinished, quote in "
|
||||
"escalation the passage that shows the trigger fired, such as the finding or the failing test. Leave "
|
||||
"escalation empty where the agent asks for no higher rung, or where only its own claim shows the trigger."
|
||||
"continue: an open PR, a review not yet run, CI not yet reported, an answer not yet recorded."
|
||||
)
|
||||
|
||||
|
||||
@@ -59,7 +56,7 @@ class Reply:
|
||||
# Routes the next cycle's worker. Counting the item the chunk was routed on is harmless: loop-claude never steps the worker down.
|
||||
bundled: int = dataclasses.field(metadata={"description": "The highest R + C the agent states for a todo.md item it took into this chunk; 0 when it states none."})
|
||||
# Routes the next cycle's worker one rung up: docs/decisions.md → `routing: a worker that ends its run asking for a higher rung`.
|
||||
escalation: str = dataclasses.field(metadata={"description": "Where the chunk is unfinished and the agent's run ends asking for a higher rung, citing an escalation trigger: a verbatim quote, without elisions, of the transcript passage that shows that trigger fired, other than the agent's own claim. Empty otherwise."})
|
||||
escalation: str = dataclasses.field(metadata={"description": "Where the chunk is unfinished and the agent's run ends asking for a higher rung, citing an escalation trigger: a verbatim quote, without elisions, of an earlier transcript passage that shows that trigger fired, such as a review round's commit title or the agent's report of the finding or the failing test; never the request itself. Empty otherwise."})
|
||||
evidence: str = dataclasses.field(metadata={"description": "A verbatim quote of the one transcript passage the verdict rests on, without elisions: what triggers the interrupt; for a quoted answer, the agent's question; else what shows the chunk finished or the work remaining."})
|
||||
finished: bool = dataclasses.field(metadata={"description": "Whether the chunk is finished."})
|
||||
interrupt: bool = dataclasses.field(metadata={"description": "Whether the human must now be interrupted."})
|
||||
@@ -158,11 +155,11 @@ def run_judge(root: str, args: list[str], prompt: str, shown: str, quotable: str
|
||||
return Failure(f"{verdict.reason}; it replied: {json.dumps(reply, ensure_ascii=False)}")
|
||||
if not grounded(verdict.evidence, shown):
|
||||
return Failure(f"the judge quoted {verdict.evidence!r}, which is not in the transcript" + (f", for the question: {verdict.question}" if isinstance(verdict, Interrupt | QuotedAnswer) else ""))
|
||||
# Not a Failure: a misquote would otherwise exit an unattended loop. Never elided: stitched fragments can say what the records do not.
|
||||
# A misquoted answer or escalation is no Failure, which would otherwise exit an unattended loop: the question goes to the human, and the worker's rung holds.
|
||||
# Never elided: stitched fragments can say what the records or the transcript do not.
|
||||
if isinstance(verdict, QuotedAnswer) and not verbatim(verdict.answer, quotable):
|
||||
return Interrupt(verdict.evidence, verdict.question)
|
||||
# Not a Failure either: the worker's rung then holds, which is safe.
|
||||
if isinstance(verdict, Unfinished) and verdict.escalation and not grounded(verdict.escalation, shown):
|
||||
if isinstance(verdict, Unfinished) and verdict.escalation and not verbatim(verdict.escalation, shown):
|
||||
return dataclasses.replace(verdict, escalation="")
|
||||
return verdict
|
||||
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
from model_routing.ladder import climbed, highest, LADDER, Rung
|
||||
from loop_claude.routing import escalation_cap, escalation_rungs
|
||||
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
|
||||
from markdown_text import quoted
|
||||
|
||||
@@ -38,7 +38,8 @@ def off_the_projects_rung(route: Route, anchor: Rung | None) -> str:
|
||||
|
||||
|
||||
def escalation(route: Route, anchor: Rung | None) -> str:
|
||||
"""The prompt's escalation sentences: the rungs escalation_rungs opens, the marker, and while a rung opens, the offer to resume the worker higher; empty off the ladder or on its top rung."""
|
||||
"""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 it opens to a subagent, and offer to resume the worker one rung up for the rest of the chunk, up to the same rung."""
|
||||
if anchor is None or route.rung not in LADDER[:-1]:
|
||||
return ""
|
||||
marked = f" Open the subagent's prompt with `{ESCALATION_MARKER} <n>:`, n the trigger's number."
|
||||
@@ -46,7 +47,7 @@ def escalation(route: Route, anchor: Rung | None) -> str:
|
||||
if not rungs:
|
||||
return f" An escalation trigger in `~/.claude/CLAUDE.md` lets you hand the hard part of a task to a subagent with the Agent tool set to `{climbed(route.rung, 1).agent_args()}`, one rung above yours, only once the human agrees.{marked}"
|
||||
further = f", and on each further trigger one rung higher, up to {rungs[-1]}" if len(rungs) > 1 else ""
|
||||
resumed_higher = f" Where the hard part is the rest of the chunk, end your run instead, asking for a higher rung and naming the trigger that fired: once the judge finds it in your transcript, the next cycle resumes you one rung up, up to {escalation_cap(anchor, route)}."
|
||||
resumed_higher = f" Where the hard part is the rest of the chunk, end your run instead, asking for a higher rung and naming the trigger that fired: once the judge finds it in your transcript, the next cycle resumes you one rung up, up to {rungs[-1]}."
|
||||
return f" When an escalation trigger in `~/.claude/CLAUDE.md` fires, hand the hard part of the task to a subagent with the Agent tool set to {rungs[0]}, one rung above yours{further}; above that, ask the human first.{marked}{resumed_higher}"
|
||||
|
||||
|
||||
@@ -65,9 +66,10 @@ def reruns(route: Route, anchor: Rung | None) -> str:
|
||||
|
||||
|
||||
def resumed(unfinished_evidence: str, route: Route, anchor: Rung | None) -> str:
|
||||
"""Names the project's rung again, since a step-up between cycles may have taken the worker above it."""
|
||||
"""Names the worker's rung and the project's again, since a step-up between cycles may have taken the worker above the project's, and the worker learns whether its request for a higher rung went through."""
|
||||
on = f" loop-claude runs you on {route.rung}." if anchor else ""
|
||||
ruled = f" A judge ruled the chunk unfinished, quoting this passage of your transcript as the work remaining:\n\n{quoted(unfinished_evidence)}\n\n" if unfinished_evidence else " "
|
||||
return f"Continue the task; the previous run ended before the chunk was finished.{ruled}The chunk is finished once it is merged, or nothing remains that you could do on your own. Even then, it is finished only once {ANSWERS_RECORDED}.{off_the_projects_rung(route, anchor)}{escalation(route, anchor)}{reruns(route, anchor)}"
|
||||
return f"Continue the task; the previous run ended before the chunk was finished.{ruled}The chunk is finished once it is merged, or nothing remains that you could do on your own. Even then, it is finished only once {ANSWERS_RECORDED}.{on}{off_the_projects_rung(route, anchor)}{escalation(route, anchor)}{reruns(route, anchor)}"
|
||||
|
||||
|
||||
def answered(question: str, answer: str) -> str:
|
||||
|
||||
+26
-14
@@ -7,7 +7,7 @@ from todo_table import Item, items
|
||||
from model_routing.route import Route
|
||||
|
||||
UNFINISHED_PER_STEP = 2
|
||||
# How many rungs above item_rung the worker may escalate a task without the human's yes: docs/decisions.md → `routing: a worker hands a task one rung up`.
|
||||
# How many rungs above item_rung an escalation trigger takes the worker or a task without the human's yes, as escalation_cap applies it.
|
||||
ESCALATION_CAP = 2
|
||||
# The models `judge-replay` found returning, on their cheapest rung, every verdict the reference judge reproduced: docs/decisions.md → `routing: on a model judge-replay covered`.
|
||||
JUDGE_REPLAYED = ("claude-opus-5-5",)
|
||||
@@ -31,8 +31,13 @@ def first_route(anchor: Rung, item: Item | None) -> Route:
|
||||
|
||||
|
||||
def kept(route: Route, anchor: Rung) -> bool:
|
||||
"""Whether a chunk keeps route: its rung is on the ladder at or above item_rung, the floor stepped keeps too."""
|
||||
return highest(route.rung, item_rung(anchor, route)) == route.rung
|
||||
"""Whether a chunk keeps route: its rung is on the ladder and at or above item_rung."""
|
||||
return floor(anchor, route) == route.rung
|
||||
|
||||
|
||||
def floor(anchor: Rung, route: Route) -> Rung:
|
||||
"""The route's rung, raised to item_rung where it is lower or off the ladder; kept and stepped both hold a route to it."""
|
||||
return highest(route.rung, item_rung(anchor, route))
|
||||
|
||||
|
||||
def item_rung(anchor: Rung, route: Route) -> Rung:
|
||||
@@ -41,34 +46,41 @@ def item_rung(anchor: Rung, route: Route) -> Rung:
|
||||
|
||||
|
||||
def escalation_rungs(anchor: Rung, route: Route) -> tuple[Rung, ...]:
|
||||
"""The rungs an escalation trigger opens to the worker, least competent first: from one above its own up to ESCALATION_CAP above item_rung; none off the ladder.
|
||||
|
||||
A step-up between cycles raises the worker but not that limit, as lilleman set it from the rung the chunk started on.
|
||||
"""
|
||||
"""The rungs an escalation trigger opens to the worker, least competent first: from one above its own up to escalation_cap; none off the ladder."""
|
||||
if route.rung not in LADDER:
|
||||
return ()
|
||||
return LADDER[position(route.rung) + 1:position(escalation_cap(anchor, route)) + 1]
|
||||
|
||||
|
||||
def escalation_cap(anchor: Rung, route: Route) -> Rung:
|
||||
"""The highest rung an escalation trigger takes the worker or a task to without the human's yes."""
|
||||
"""The highest rung an escalation trigger takes the worker or a task to without the human's yes: docs/decisions.md → `routing: a worker hands a task one rung up`.
|
||||
|
||||
It counts from item_rung, the rung the chunk started on, so a step-up between cycles narrows what the worker may climb without a yes, and never widens it.
|
||||
"""
|
||||
return climbed(item_rung(anchor, route), ESCALATION_CAP)
|
||||
|
||||
|
||||
def stepped(anchor: Rung, route: Route, bundled: int, escalated: bool) -> Route:
|
||||
"""The route after one more unfinished verdict, never on a lower rung or below item_rung.
|
||||
"""The route after one more unfinished verdict, never on a lower rung: from taken_in's rung, one rung up when counted_out or escalates, else there.
|
||||
|
||||
bundled is the highest R + C the judge saw the worker take into the chunk, 0 for none; the route climbs to the rung it picks.
|
||||
From there it steps one rung up after every UNFINISHED_PER_STEP unfinished verdicts, or when escalated, as the judge found the escalation trigger the worker cited, up to escalation_cap.
|
||||
bundled and escalated are the verdict's fields, not the verdict, since loop_claude.cycle.judge imports this module through prompts.
|
||||
"""
|
||||
rung = highest(route.rung, item_rung(anchor, route))
|
||||
rung = highest(rung, picked(anchor, bundled)) if bundled else rung
|
||||
rung = taken_in(anchor, route, bundled)
|
||||
unfinished = route.unfinished + 1
|
||||
if unfinished >= UNFINISHED_PER_STEP or escalated and position(rung) < position(escalation_cap(anchor, route)):
|
||||
# Every UNFINISHED_PER_STEP unfinished verdicts.
|
||||
counted_out = unfinished >= UNFINISHED_PER_STEP
|
||||
# The judge found the escalation trigger the worker cited in asking for a higher rung, and escalation_cap leaves room.
|
||||
escalates = escalated and position(rung) < position(escalation_cap(anchor, route))
|
||||
if counted_out or escalates:
|
||||
return dataclasses.replace(route, rung=stepped_up(rung), unfinished=0)
|
||||
return dataclasses.replace(route, rung=rung, unfinished=unfinished)
|
||||
|
||||
|
||||
def taken_in(anchor: Rung, route: Route, bundled: int) -> Rung:
|
||||
"""floor, raised to the rung bundled picks from anchor; bundled is the highest R + C the judge saw the worker take into the chunk, 0 for none."""
|
||||
return highest(floor(anchor, route), picked(anchor, bundled)) if bundled else floor(anchor, route)
|
||||
|
||||
|
||||
def judge_rung(judge_model: str, route: Route) -> Rung:
|
||||
"""The rung the route's item picks from the judge model's cheapest rung, never below that rung, whatever rung the worker stepped to.
|
||||
|
||||
|
||||
@@ -401,7 +401,7 @@ class Cycles(unittest.TestCase):
|
||||
(checkout.root / "todo.md").write_text(TODO)
|
||||
run = checkout.run([
|
||||
worker(say="Stability round 2: a 🔴. Trigger 3 fired; I ask for a higher rung."), judge(evidence="I ask for a higher rung.", escalation="Stability round 2: a 🔴."),
|
||||
worker(say="Trigger 2 fired; I ask for a higher rung."), judge(evidence="I ask for a higher rung.", escalation="the test failed twice"),
|
||||
worker(say="Trigger 2 fired; I ask for a higher rung."), judge(evidence="I ask for a higher rung.", escalation="Trigger 2 fired; … a higher rung."),
|
||||
worker(say="merged"), judge(finished=True, evidence="merged"),
|
||||
worker(say="next chunk"),
|
||||
])
|
||||
@@ -521,7 +521,7 @@ class Cycles(unittest.TestCase):
|
||||
self.assertIn("LATE", run.calls[1]["stdin"])
|
||||
self.assertEqual(len(run.calls[1]["stdin"]), 400000)
|
||||
self.assertLess(run.calls[1]["stdin"].count("early"), 80000)
|
||||
self.assertTrue(run.calls[1]["stdin"].rstrip().endswith("or where only its own claim shows the trigger."))
|
||||
self.assertTrue(run.calls[1]["stdin"].rstrip().endswith("CI not yet reported, an answer not yet recorded."))
|
||||
|
||||
def test_skips_a_malformed_transcript_or_stream_line(self):
|
||||
checkout = Checkout(self)
|
||||
|
||||
@@ -663,6 +663,8 @@ class WorkerArgs(unittest.TestCase):
|
||||
stepped_up = prompts.resumed("", Route(Rung("claude-opus-5-5", "high"), 3, 9), opus)
|
||||
self.assertIn(" 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 set to model opus, effort medium. Run a full scan only from such a subagent, since the scan's agents run on the model that starts them. When an escalation trigger", stepped_up)
|
||||
self.assertNotIn("the project's", prompts.resumed("", Route(opus, 3, 9), opus))
|
||||
self.assertIn(f"{prompts.ANSWERS_RECORDED}. loop-claude runs you on claude-opus-5-5 at high effort. Your rung is above", stepped_up)
|
||||
self.assertNotIn("runs you on", prompts.resumed("", Route(Rung("m")), None))
|
||||
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 set to model opus, effort medium. Run a full scan only from such a subagent, since the scan's agents run on the model that starts them. When an escalation trigger", above)
|
||||
|
||||
def test_names_the_rungs_an_escalation_trigger_lets_the_worker_hand_a_task_to_at_most_two_above_its_items(self):
|
||||
@@ -675,11 +677,11 @@ class WorkerArgs(unittest.TestCase):
|
||||
self.assertIn("hand the hard part of the task to a subagent with the Agent tool set to `model fable, effort max`, one rung above yours;", prompts.resumed("", Route(Rung("claude-opus-5-5", "max"), 3, 13), opus))
|
||||
self.assertNotIn("escalation", prompts.resumed("", Route(Rung("m")), None))
|
||||
self.assertNotIn("escalation", prompts.resumed("", Route(Rung("claude-opus-5-5", "low"), 3, 9), opus))
|
||||
self.assertIn("before creating a new one.\n\nWhen an escalation trigger in `~/.claude/CLAUDE.md` fires, hand the hard part of the task to a subagent with the Agent tool set to `model opus, effort high`, one rung above yours, and on each further trigger one rung higher, up to `model opus, effort xhigh`; above that, ask the human first. Open the subagent's prompt with `Escalation trigger <n>:`, n the trigger's number. Where the hard part is the rest of the chunk, end your run instead, asking for a higher rung and naming the trigger that fired: once the judge finds it in your transcript, the next cycle resumes you one rung up, up to claude-opus-5-5 at xhigh effort. A reviewer", prompts.fresh("Do it.", "## Goals", Route(opus), opus))
|
||||
self.assertIn("before creating a new one.\n\nWhen an escalation trigger in `~/.claude/CLAUDE.md` fires, hand the hard part of the task to a subagent with the Agent tool set to `model opus, effort high`, one rung above yours, and on each further trigger one rung higher, up to `model opus, effort xhigh`; above that, ask the human first. Open the subagent's prompt with `Escalation trigger <n>:`, n the trigger's number. Where the hard part is the rest of the chunk, end your run instead, asking for a higher rung and naming the trigger that fired: once the judge finds it in your transcript, the next cycle resumes you one rung up, up to `model opus, effort xhigh`. A reviewer", prompts.fresh("Do it.", "## Goals", Route(opus), opus))
|
||||
|
||||
def test_offers_the_worker_a_higher_rung_for_the_rest_of_the_chunk_up_to_the_escalation_cap(self):
|
||||
opus = Rung("claude-opus-5-5", "medium")
|
||||
offer = " Where the hard part is the rest of the chunk, end your run instead, asking for a higher rung and naming the trigger that fired: once the judge finds it in your transcript, the next cycle resumes you one rung up, up to claude-opus-5-5 at xhigh effort."
|
||||
offer = " Where the hard part is the rest of the chunk, end your run instead, asking for a higher rung and naming the trigger that fired: once the judge finds it in your transcript, the next cycle resumes you one rung up, up to `model opus, effort xhigh`."
|
||||
self.assertIn(f"`Escalation trigger <n>:`, n the trigger's number.{offer}", prompts.fresh("Do it.", "## Goals", Route(opus, 3, 9), opus))
|
||||
self.assertIn(f"`Escalation trigger <n>:`, n the trigger's number.{offer}", prompts.resumed("", Route(Rung("claude-opus-5-5", "high"), 3, 9), opus))
|
||||
self.assertNotIn("Where the hard part", prompts.resumed("", Route(Rung("claude-opus-5-5", "xhigh"), 3, 9), opus))
|
||||
|
||||
+1
-1
@@ -222,7 +222,7 @@ Valid while the ladder orders its rungs by competence.
|
||||
|
||||
2026-10-15, lilleman asked for it. Serves goals 1.1 and 1.4: when the hard part is the rest of the chunk, handing it to subagents piece by piece leaves the worker, which reads and checks each of their diffs, on a rung that proved too low. The worker climbs only once a trigger proves the chunk hard.
|
||||
|
||||
loop-claude's prompt offers the step beside the escalated subagent of `routing: a worker hands a task one rung up`, while a rung opens to that subagent without the human's yes. The worker then ends its run asking for a higher rung and naming the trigger. The judge does not take the worker's word: it quotes the passage that shows the trigger fired, such as the finding or the failing test, and loop-claude checks that quote against the transcript as it checks the verdict's evidence. Without a quote the transcript holds, the rung holds. A misquote is no failure, since holding the rung is safe and three failures stop an unattended loop.
|
||||
loop-claude's prompt offers the step beside the escalated subagent of `routing: a worker hands a task one rung up`, while a rung opens to that subagent without the human's yes. The worker then ends its run asking for a higher rung and naming the trigger. The judge quotes an earlier passage that shows the trigger fired, such as a review round's commit title or the worker's report of the failing test, never the request itself. The judge sees the worker's text and tool calls but no tool results, so the quote shows that the run recorded the trigger, not that a tool's output bears it out. loop-claude checks the quote word for word, as it checks a quoted answer, since stitched fragments can make up a trigger. Without such a quote, the rung holds. A misquote is no failure, since holding the rung is safe and three failures stop an unattended loop. The next prompt names the worker's rung, so the worker learns whether the step went through.
|
||||
|
||||
The step is one rung, taken from the rung any item the judge saw taken in picks, and it restarts the count towards the step every second unfinished verdict takes; when both fall on one verdict, the worker steps once. It stops at the limit escalated subagents stop at, two rungs above the rung the chunk started on. Past that limit the rung holds: loop-claude takes no yes from the human between cycles, so a worker there asks the human for an escalated subagent instead. The judge keeps its rung, as `routing: on a model judge-replay covered` says.
|
||||
|
||||
|
||||
Reference in New Issue
Block a user