Let a worker hand a too-hard task to a subagent one rung up per escalation trigger, at most two above its item's rung

This commit is contained in:
2026-10-15 16:16:13 +02:00
parent 2190ec846b
commit f6d4d8c881
9 changed files with 80 additions and 33 deletions
+20 -3
View File
@@ -1,8 +1,13 @@
from model_routing.ladder import highest, Rung
from model_routing.ladder import climbed, highest, LADDER, position, 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 +26,7 @@ def fresh(task: str, premises: str, route: Route, anchor: Rung | None) -> str:
def routed_by(route: Route, anchor: Rung | None) -> str:
return 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}.{off_the_projects_rung(route, anchor)}"
return 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}.{off_the_projects_rung(route, anchor)}{escalation(route, anchor)}"
def off_the_projects_rung(route: Route, anchor: Rung | None) -> str:
@@ -35,10 +40,22 @@ def off_the_projects_rung(route: Route, anchor: Rung | None) -> str:
return f" Your rung is {'below' if below else 'above'} the project's, {anchor}: launch {launched} with the Agent tool set to {anchor.agent_args()}. Run a full scan only from such a subagent, since the scan's agents run on the model that starts them.{planning}"
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]:
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]]
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."
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."
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."""
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)}"
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)}"
def answered(question: str, answer: str) -> str: