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:
@@ -11,6 +11,8 @@ from loop_claude.project.records import HUMAN_RULE_NAMES
|
||||
from loop_claude.cycle.retry import Limited, retried
|
||||
from loop_claude.stop import Stop
|
||||
|
||||
# Routes the next cycle's worker; loop-claude never steps it down, so the item the chunk was routed on may count too.
|
||||
BUNDLED = "The highest R + C the agent states for a todo.md item it took into this chunk; 0 when it states none."
|
||||
# At 3 to 4 characters a token, 100,000 to 133,000 tokens, which leaves a 200,000-token context room for the reply; the largest session rendered here was 364,000 characters on 2026-10-03.
|
||||
JUDGE_PROMPT_CHARS = 400000
|
||||
JUDGE_RULES = (
|
||||
@@ -43,15 +45,14 @@ JUDGE_RULES = (
|
||||
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"
|
||||
"bundled is the highest R + C the agent says a todo.md item it took into this chunk scores, where that is "
|
||||
"higher than the R + C loop-claude's first prompt says it routed the chunk on; 0 otherwise."
|
||||
f"bundled: {BUNDLED}"
|
||||
)
|
||||
|
||||
|
||||
@dataclasses.dataclass(frozen=True)
|
||||
class Reply:
|
||||
answer: str = dataclasses.field(metadata={"description": "With interrupt false, the passage of README.md or the records that answers the agent's question, quoted verbatim, without elisions. Empty otherwise."})
|
||||
bundled: int = dataclasses.field(metadata={"description": "The highest R + C the agent says a todo.md item it took into this chunk scores, where that is higher than the R + C loop-claude's first prompt says it routed the chunk on. 0 otherwise."})
|
||||
bundled: int = dataclasses.field(metadata={"description": BUNDLED})
|
||||
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."})
|
||||
|
||||
@@ -1,8 +1,6 @@
|
||||
from loop_claude.project.records import HUMAN_RULE_NAMES, RECORD_FILES
|
||||
from todo_table import Item
|
||||
from markdown_text import quoted
|
||||
from loop_claude.cycle.routing import risk_and_complexity
|
||||
from model_routing.ladder import Rung
|
||||
from loop_claude.loop.routing import Route
|
||||
|
||||
def either(names: tuple[str, ...]) -> str:
|
||||
"""The names as `a, b or c`."""
|
||||
@@ -16,13 +14,13 @@ ANSWER_DESTINATIONS = "README.md's Goals or Audience, " + ", ".join(RECORD_FILES
|
||||
ANSWERS_RECORDED = f"every answer the human typed in it that a later chunk could need is recorded in {ANSWER_DESTINATIONS} at the one place it governs"
|
||||
|
||||
|
||||
def fresh(task: str, premises: str, routed: str = "") -> str:
|
||||
route = f"{routed}\n\n" if routed else ""
|
||||
return f"{task}\n\nContinue any open draft PR or worktree for the chunk before creating a new one.\n\n{route}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}"
|
||||
def fresh(task: str, premises: str, route: Route) -> str:
|
||||
routed = f"{routed_by(route)}\n\n" if route.item else ""
|
||||
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}"
|
||||
|
||||
|
||||
def routed(worker: Rung, item: Item) -> str:
|
||||
return f"loop-claude runs you on {worker}, the rung item {item.id}'s R + C of {risk_and_complexity(item)} picks. When the chunk takes in a todo.md item whose R + C is higher, say so, naming that item and its R + C."
|
||||
def routed_by(route: Route) -> str:
|
||||
return f"loop-claude runs you on {route.rung}, the rung item {route.item}'s R + C of {route.risk_and_complexity} picks. When the chunk takes in another todo.md item, say so, naming that item and its R + C."
|
||||
|
||||
|
||||
def resumed(unfinished_evidence: str) -> str:
|
||||
|
||||
@@ -1,36 +0,0 @@
|
||||
"""Which ladder rung a chunk's worker runs on: docs/decisions.md → `routing:`."""
|
||||
from failure import Failure
|
||||
from model_routing.ladder import climbed, steps
|
||||
from todo_table import Item, items
|
||||
|
||||
UNFINISHED_PER_STEP = 2
|
||||
|
||||
|
||||
def routed_item(todo: str) -> Item | None:
|
||||
"""The next release's first item that waits on no question, as rank_todo.py ranks the table; None when there is none, or it has no C."""
|
||||
found = items(todo)
|
||||
if not found or isinstance(found, Failure):
|
||||
return None
|
||||
next_release = min(item.release for item in found)
|
||||
takes = next((item for item in found if item.release == next_release and item.exempt != "question"), None)
|
||||
return takes if takes and "C" in takes.scores else None
|
||||
|
||||
|
||||
def risk_and_complexity(item: Item) -> int:
|
||||
return item.scores["R"] + item.scores["C"]
|
||||
|
||||
|
||||
def first_rung(anchor: int, item: Item | None) -> int:
|
||||
"""The rung a chunk starts on: the one its item's R + C picks from anchor, the project's rung, never below it."""
|
||||
return anchor if item is None else max(anchor, climbed(anchor, steps(risk_and_complexity(item))))
|
||||
|
||||
|
||||
def stepped(anchor: int, rung: int, unfinished: int, bundled: int) -> tuple[int, int]:
|
||||
"""The rung and the unfinished verdicts since it last stepped, after one more unfinished verdict.
|
||||
|
||||
bundled is the highest R + C the judge saw the worker say an item it took into the chunk scores, 0 for none.
|
||||
"""
|
||||
if bundled:
|
||||
rung = max(rung, climbed(anchor, steps(bundled)))
|
||||
unfinished += 1
|
||||
return (climbed(rung, 1), 0) if unfinished == UNFINISHED_PER_STEP else (rung, unfinished)
|
||||
@@ -14,8 +14,8 @@ from loop_claude.paths import Paths
|
||||
from loop_claude.cycle import prompts
|
||||
from claude_code.transcript import read_transcript, render
|
||||
from loop_claude.cycle.retry import retried
|
||||
from loop_claude.loop.routing import Route
|
||||
from loop_claude.cycle.worker import run_worker, worker_args
|
||||
from model_routing.ladder import Rung
|
||||
from loop_claude.stop import Stop
|
||||
|
||||
|
||||
@@ -30,9 +30,7 @@ class Cycle:
|
||||
root: str
|
||||
session: Session
|
||||
task: str
|
||||
worker: Rung
|
||||
# The fresh worker prompt's word on its route; empty when the chunk is under way or not routed.
|
||||
routed: str
|
||||
route: Route
|
||||
# Empty when the previous cycle's verdict was not Unfinished.
|
||||
unfinished_evidence: str
|
||||
|
||||
@@ -85,10 +83,10 @@ def work(cycle: Cycle, answered: QuotedAnswer | None) -> WorkerRan | Stop:
|
||||
|
||||
def worker_start(cycle: Cycle, answered: QuotedAnswer | None) -> list[str]:
|
||||
if answered is not None:
|
||||
return worker_args(cycle.session, cycle.worker, prompts.answered(answered.question, answered.answer), resume=True)
|
||||
return worker_args(cycle.session, cycle.route.rung, prompts.answered(answered.question, answered.answer), resume=True)
|
||||
if session_open(cycle.session):
|
||||
return worker_args(cycle.session, cycle.worker, prompts.resumed(cycle.unfinished_evidence), resume=True)
|
||||
return worker_args(cycle.session, cycle.worker, prompts.fresh(cycle.task, cycle.premises, cycle.routed), resume=False)
|
||||
return worker_args(cycle.session, cycle.route.rung, prompts.resumed(cycle.unfinished_evidence), resume=True)
|
||||
return worker_args(cycle.session, cycle.route.rung, prompts.fresh(cycle.task, cycle.premises, cycle.route), resume=False)
|
||||
|
||||
|
||||
def keep_answer(cycle: Cycle, answered: QuotedAnswer) -> Stop | None:
|
||||
@@ -111,7 +109,7 @@ def ask(cycle: Cycle, transcript_path: str, ruling: Interrupt | QuotedAnswer) ->
|
||||
# Archived now, so the transcript the question was asked on is kept with it; the human's answer then grows the transcript.
|
||||
if failure := archive(cycle.project_archive, transcript_path, cycle.task, outcomes.interrupted(question, ruling.evidence), cycle.effects.now()):
|
||||
return Stop(1, failure.reason)
|
||||
return interrupt(cycle.root, cycle.session.id, cycle.worker, transcript_path, question, cycle.paths, cycle.effects) or HumanAnswered()
|
||||
return interrupt(cycle.root, cycle.session.id, cycle.route.rung, transcript_path, question, cycle.paths, cycle.effects) or HumanAnswered()
|
||||
|
||||
|
||||
def question_for(ruling: Interrupt | QuotedAnswer) -> str:
|
||||
@@ -122,7 +120,7 @@ def question_for(ruling: Interrupt | QuotedAnswer) -> str:
|
||||
|
||||
def close(cycle: Cycle, transcript_path: str, verdict: Finished | Unfinished) -> Archived | Stop:
|
||||
finished = isinstance(verdict, Finished)
|
||||
if failure := archive(cycle.project_archive, transcript_path, cycle.task, outcomes.finished(str(cycle.worker), verdict.evidence) if finished else outcomes.unfinished(str(cycle.worker), verdict.evidence), cycle.effects.now()):
|
||||
if failure := archive(cycle.project_archive, transcript_path, cycle.task, outcomes.finished(str(cycle.route), verdict.evidence) if finished else outcomes.unfinished(str(cycle.route), verdict.evidence), cycle.effects.now()):
|
||||
return Stop(1, failure.reason)
|
||||
if finished and (failure := delete_session(cycle.session)):
|
||||
return Stop(1, failure.reason)
|
||||
|
||||
Reference in New Issue
Block a user