Answer architecture round 1: 1 🔴, 6 🟡; escalate in an unrouted chunk's first cycle, hold the limit and marker in routing.py, count escalations per starting rung, decline counting the limit from the current rung
This commit is contained in:
@@ -1,13 +1,9 @@
|
||||
from model_routing.ladder import climbed, highest, LADDER, position, Rung
|
||||
from loop_claude.routing import ESCALATION_MARKER, escalation_rungs
|
||||
from model_routing.ladder import highest, LADDER, Rung
|
||||
from loop_claude.project.records import HUMAN_RULE_NAMES, RECORD_FILES
|
||||
from loop_claude.routing import item_rung
|
||||
from markdown_text import quoted
|
||||
from model_routing.route import Route
|
||||
|
||||
# How many rungs above the one its item picks the worker may escalate a task without the human's yes: docs/decisions.md → `routing: a worker hands a task one rung up`.
|
||||
ESCALATION_CAP = 2
|
||||
|
||||
|
||||
def either(names: tuple[str, ...]) -> str:
|
||||
"""The names as `a, b or c`."""
|
||||
return f"{', '.join(names[:-1])} or {names[-1]}"
|
||||
@@ -21,7 +17,8 @@ ANSWERS_RECORDED = f"every answer the human typed in it that a later chunk could
|
||||
|
||||
|
||||
def fresh(task: str, premises: str, route: Route, anchor: Rung | None) -> str:
|
||||
routed = f"{routed_by(route, anchor)}\n\n" if route.item else ""
|
||||
# A chunk no item routed gets no route paragraph, but may still escalate.
|
||||
routed = f"{routed_by(route, anchor)}\n\n" if route.item else "".join(f"{text.lstrip()}\n\n" for text in [escalation(route, anchor)] if text)
|
||||
return f"{task}\n\nContinue any open draft PR or worktree for the chunk before creating a new one.\n\n{routed}The chunk's todo.md items, or else the task above, set its scope. The goals below choose between ways to deliver that scope, and never widen it.\n\nFrom README.md:\n{premises}"
|
||||
|
||||
|
||||
@@ -41,15 +38,15 @@ def off_the_projects_rung(route: Route, anchor: Rung | None) -> str:
|
||||
|
||||
|
||||
def escalation(route: Route, anchor: Rung | None) -> str:
|
||||
"""The rungs an escalation trigger lets the worker hand a task to: from one above its own up to ESCALATION_CAP above the rung its item picks; empty off the ladder or on its top rung."""
|
||||
if anchor is None or route.rung not in LADDER or route.rung == LADDER[-1]:
|
||||
"""The rungs routing.escalation_rungs opens to the worker, and how to mark an escalated subagent's prompt; empty off the ladder or on its top rung."""
|
||||
if anchor is None or route.rung not in LADDER[:-1]:
|
||||
return ""
|
||||
cap = position(climbed(item_rung(anchor, route), ESCALATION_CAP))
|
||||
rungs = [f"`{rung.agent_args()}`" for rung in LADDER[position(route.rung) + 1:cap + 1]]
|
||||
marked = f" Open the subagent's prompt with `{ESCALATION_MARKER} <n>:`, n the trigger's number."
|
||||
rungs = [f"`{rung.agent_args()}`" for rung in escalation_rungs(anchor, route)]
|
||||
if not rungs:
|
||||
return " An escalation trigger in `~/.claude/CLAUDE.md` lets you hand a task to a subagent above your rung only once the human agrees."
|
||||
return f" An escalation trigger in `~/.claude/CLAUDE.md` lets you hand a task to a subagent above your rung 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 ""
|
||||
return f" When an escalation trigger in `~/.claude/CLAUDE.md` fires, hand the task to a subagent with the Agent tool set to {rungs[0]}, one rung above yours{further}; above that, ask the human first."
|
||||
return f" When an escalation trigger in `~/.claude/CLAUDE.md` fires, hand 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}"
|
||||
|
||||
|
||||
def resumed(unfinished_evidence: str, route: Route, anchor: Rung | None) -> str:
|
||||
|
||||
@@ -1,12 +1,15 @@
|
||||
"""Which ladder rung a chunk's worker and judge run on: docs/decisions.md → `routing:`."""
|
||||
import dataclasses
|
||||
|
||||
from model_routing.ladder import climbed, floored, highest, LADDER, picked, position, project_rung, Rung, stepped_up
|
||||
from failure import Failure
|
||||
from model_routing.ladder import floored, highest, LADDER, picked, project_rung, Rung, stepped_up
|
||||
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, and how it opens an escalated subagent's prompt: docs/decisions.md → `routing: a worker hands a task one rung up`.
|
||||
ESCALATION_CAP = 2
|
||||
ESCALATION_MARKER = "Escalation trigger"
|
||||
# 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",)
|
||||
|
||||
@@ -38,6 +41,16 @@ def item_rung(anchor: Rung, route: Route) -> Rung:
|
||||
return picked(anchor, route.risk_and_complexity) if route.item else anchor
|
||||
|
||||
|
||||
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.
|
||||
"""
|
||||
if route.rung not in LADDER:
|
||||
return ()
|
||||
return LADDER[position(route.rung) + 1:position(climbed(item_rung(anchor, route), ESCALATION_CAP)) + 1]
|
||||
|
||||
|
||||
def stepped(anchor: Rung, route: Route, bundled: int) -> Route:
|
||||
"""The route after one more unfinished verdict; bundled is the highest R + C the judge saw the worker take into the chunk, 0 for none."""
|
||||
# An archived rung since removed from LADDER restarts from the project's rung.
|
||||
|
||||
@@ -660,11 +660,13 @@ class WorkerArgs(unittest.TestCase):
|
||||
def test_names_the_rungs_an_escalation_trigger_lets_the_worker_hand_a_task_to_at_most_two_above_its_items(self):
|
||||
opus = Rung("claude-opus-5-5", "medium")
|
||||
fresh = prompts.fresh("Do it.", "## Goals", Route(opus, 3, 9), opus)
|
||||
self.assertIn("whether or not it is item 3. When an escalation trigger in `~/.claude/CLAUDE.md` fires, hand 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.\n\n", fresh)
|
||||
self.assertTrue(prompts.resumed("", Route(Rung("claude-opus-5-5", "high"), 3, 9), opus).endswith(" When an escalation trigger in `~/.claude/CLAUDE.md` fires, hand the task to a subagent with the Agent tool set to `model opus, effort xhigh`, one rung above yours; above that, ask the human first."))
|
||||
self.assertTrue(prompts.resumed("", Route(Rung("claude-opus-5-5", "xhigh"), 3, 9), opus).endswith(" An escalation trigger in `~/.claude/CLAUDE.md` lets you hand a task to a subagent above your rung only once the human agrees."))
|
||||
self.assertIn("whether or not it is item 3. When an escalation trigger in `~/.claude/CLAUDE.md` fires, hand 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.\n\n", fresh)
|
||||
self.assertTrue(prompts.resumed("", Route(Rung("claude-opus-5-5", "high"), 3, 9), opus).endswith(" When an escalation trigger in `~/.claude/CLAUDE.md` fires, hand the task to a subagent with the Agent tool set to `model opus, effort xhigh`, one rung above yours; above that, ask the human first. Open the subagent's prompt with `Escalation trigger <n>:`, n the trigger's number."))
|
||||
self.assertTrue(prompts.resumed("", Route(Rung("claude-opus-5-5", "xhigh"), 3, 9), opus).endswith(" An escalation trigger in `~/.claude/CLAUDE.md` lets you hand a task to a subagent above your rung only once the human agrees. Open the subagent's prompt with `Escalation trigger <n>:`, n the trigger's number."))
|
||||
self.assertNotIn("escalation", prompts.resumed("", Route(Rung("claude-fable-5-1", "max"), 3, 20), 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 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.\n\nThe chunk's", prompts.fresh("Do it.", "## Goals", Route(opus), opus))
|
||||
|
||||
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"))
|
||||
|
||||
Reference in New Issue
Block a user