Answer principles round 1: 1 🔴, 2 🟡; name the worker's rung on an interrupt and archive its step-up at once, step from the taken-in item, drop every escalation after the first step of a cycle, and state stepped's rules once
This commit is contained in:
@@ -89,6 +89,8 @@ class Interrupt:
|
||||
question: str
|
||||
# The judge's quote showing that the worker's cited escalation trigger fired; empty for none.
|
||||
escalation: str = ""
|
||||
# The bundled L the judge saw, 0 for none, as on Unfinished: an escalation steps up from the rung that item picks.
|
||||
bundled: int = 0
|
||||
|
||||
|
||||
@dataclasses.dataclass(frozen=True)
|
||||
@@ -125,18 +127,18 @@ def verdict_from(output: object) -> Verdict | Failure:
|
||||
# type(), not isinstance(): JSON true is no integer.
|
||||
if type(output.get(name)) is not kind:
|
||||
return Failure(f"the judge's reply has no {name} of type {JSON_TYPES[kind]}")
|
||||
# A bundled level off its scale counts as none: holding the rung is safe, and three failures would stop an unattended loop.
|
||||
bundled = output["bundled"] if 0 <= output["bundled"] <= HIGHEST_L else 0
|
||||
if output["interrupt"]:
|
||||
if not output["question"].strip():
|
||||
return Failure("the judge interrupted without a question")
|
||||
return Interrupt(output["evidence"], output["question"], output["escalation"])
|
||||
return Interrupt(output["evidence"], output["question"], output["escalation"], bundled)
|
||||
if output["answer"].strip():
|
||||
if not output["question"].strip():
|
||||
return Failure("the judge quoted an answer without a question")
|
||||
return QuotedAnswer(output["evidence"], output["question"], output["answer"])
|
||||
if output["finished"]:
|
||||
return Finished(output["evidence"])
|
||||
# A bundled level off its scale counts as none: holding the rung is safe, and three failures would stop an unattended loop.
|
||||
bundled = output["bundled"] if 0 <= output["bundled"] <= HIGHEST_L else 0
|
||||
bundled_escape_and_impact = output["bundled_escape_and_impact"] if on_its_scale(output["bundled_escape_and_impact"]) else 0
|
||||
return Unfinished(output["evidence"], bundled, output["escalation"], bundled_escape_and_impact)
|
||||
|
||||
|
||||
@@ -7,7 +7,7 @@ from transcript_archive.write import archive
|
||||
from claude_code.session import delete_session, Session, session_open, transcript_file
|
||||
from loop_claude.effects import Effects
|
||||
from failure import Failure
|
||||
from loop_claude.cycle.judge import Finished, Interrupt, judge, plain, QuotedAnswer, Rejected, Unfinished, Verdict
|
||||
from loop_claude.cycle.judge import Finished, Interrupt, judge, QuotedAnswer, Rejected, Unfinished, Verdict
|
||||
from loop_claude.cycle.interrupt import interrupt
|
||||
from loop_claude.routing import judge_rung, stepped_by_interrupt
|
||||
from transcript_archive import outcomes
|
||||
@@ -40,8 +40,11 @@ class Cycle:
|
||||
anchor: Rung | None
|
||||
# Empty when the previous cycle's verdict was not Unfinished.
|
||||
unfinished_evidence: str
|
||||
# The judge's quote that stepped the route up as an interrupt; a later ruling quoting it again steps nothing.
|
||||
escalation_spent: str = ""
|
||||
# The route changes within a cycle only as an interrupt carries an escalation, and no transition reads it or the fields below, so they stay out of the states.
|
||||
# The route that interrupt left, for ask to archive; None unless the latest event stepped the route up.
|
||||
stepped_from: Route | None = None
|
||||
# Whether an interrupt of this cycle took an escalation, after which no ruling of the cycle carries one.
|
||||
escalation_spent: bool = False
|
||||
|
||||
|
||||
@dataclasses.dataclass(frozen=True)
|
||||
@@ -66,11 +69,12 @@ def run_cycle(cycle: Cycle) -> Stop | Concluded:
|
||||
|
||||
|
||||
def escalated(cycle: Cycle, event: Event) -> Cycle:
|
||||
"""The cycle after the judge interrupted with an escalation: its route stepped up before the human is asked, so the work after the answer runs on it."""
|
||||
"""The cycle after event. Where the judge interrupted with an escalation, its route steps up before the human is asked, so the work after the answer runs on it."""
|
||||
cycle = dataclasses.replace(cycle, stepped_from=None)
|
||||
if not (isinstance(event, Ruled) and isinstance(event.verdict, Interrupt) and event.verdict.escalation):
|
||||
return cycle
|
||||
route = stepped_by_interrupt(cycle.anchor, cycle.route) if cycle.anchor else cycle.route
|
||||
return dataclasses.replace(cycle, route=route, escalation_spent=event.verdict.escalation)
|
||||
route = stepped_by_interrupt(cycle.anchor, cycle.route, event.verdict.bundled) if cycle.anchor else cycle.route
|
||||
return dataclasses.replace(cycle, route=route, stepped_from=cycle.route if route != cycle.route else None, escalation_spent=True)
|
||||
|
||||
|
||||
def stopped(cycle: Cycle, stop: Stop, why: str) -> Stop:
|
||||
@@ -139,9 +143,9 @@ def rule(cycle: Cycle, transcript_path: str) -> Ruled | Stop:
|
||||
return verdict if isinstance(verdict, Stop) else Ruled(unspent(verdict, cycle.escalation_spent))
|
||||
|
||||
|
||||
def unspent(verdict: Verdict, spent: str) -> Verdict:
|
||||
"""The verdict without an escalation that already stepped the route as an interrupt, so one trigger buys one step."""
|
||||
if isinstance(verdict, Interrupt | Unfinished) and verdict.escalation and plain(verdict.escalation) == plain(spent):
|
||||
def unspent(verdict: Verdict, spent: bool) -> Verdict:
|
||||
"""The verdict without its escalation once an interrupt of the cycle took one. The judge may quote another passage for the trigger that stepped the route, which no comparison of quotes can tell, so one trigger buys one step. It lives here, not in judge.quotes_checked, since it reads the cycle, and judge-replay replays the judge alone."""
|
||||
if spent and isinstance(verdict, Interrupt | Unfinished) and verdict.escalation:
|
||||
return dataclasses.replace(verdict, escalation="")
|
||||
return verdict
|
||||
|
||||
@@ -156,8 +160,11 @@ def keep_rejection(cycle: Cycle, transcript_path: str, rejected: Rejected) -> St
|
||||
def ask(cycle: Cycle, transcript_path: str, ruling: Interrupt | QuotedAnswer) -> HumanAnswered | Stop:
|
||||
question = question_for(ruling)
|
||||
# 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, str(judge_of(cycle)), ruling.escalation if isinstance(ruling, Interrupt) else ""), cycle.effects.now()):
|
||||
return Stop(1, failure.reason)
|
||||
# The interrupt names the rung the worker ran on until it, and a step-up then the rung it runs on from it, so the figures charge each stretch to its own rung.
|
||||
interrupted = outcomes.interrupted(question, ruling.evidence, str(judge_of(cycle)), ruling.escalation if isinstance(ruling, Interrupt) else "", str(cycle.stepped_from or cycle.route))
|
||||
for outcome in (interrupted, outcomes.stepped_up(str(cycle.route))) if cycle.stepped_from else (interrupted,):
|
||||
if failure := archive(cycle.project_archive, transcript_path, cycle.task, outcome, cycle.effects.now()):
|
||||
return Stop(1, failure.reason)
|
||||
return interrupt(cycle.root, cycle.session.id, cycle.route.rung, transcript_path, question, cycle.paths, worker_environment(cycle), cycle.effects) or HumanAnswered()
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user