Fix under the floor's Shape: interrupt means only the human, QuotedAnswer names the verdict, one owner for the record files, Limited beside its cycle
This commit is contained in:
@@ -3,20 +3,20 @@ import json
|
||||
import typing
|
||||
|
||||
from loop_claude.claude_code.entries import hit_limit, limit_said, parse_entry, structured_output
|
||||
from loop_claude.cycle.limited import Limited
|
||||
from loop_claude.cycle.retry import retried
|
||||
from loop_claude.cycle.verdicts import AnsweredFromRecords, Finished, Interrupt, Unfinished, Verdict
|
||||
from loop_claude.cycle.verdicts import Finished, Interrupt, QuotedAnswer, Unfinished, Verdict
|
||||
from loop_claude.effects import Effects
|
||||
from loop_claude.failure import Failure
|
||||
from loop_claude.limited import Limited
|
||||
from loop_claude.stop import Stop
|
||||
|
||||
# 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 = (
|
||||
"Decide whether the agent has something open that the human must answer, or that README.md or the "
|
||||
"project's records answer. interrupt=true when any of these appear:\n"
|
||||
"- the agent asks the human anything, seeks approval, or says a decision is the human's\n"
|
||||
"Decide whether the human must now be interrupted. interrupt=true when any of these appear:\n"
|
||||
"- the agent asks the human anything, seeks approval, or says a decision is the human's, and neither "
|
||||
"README.md nor the project's records answer it\n"
|
||||
"- it carried on under an assumption that decides the deliverable, that the human could "
|
||||
"reasonably reject and that neither README.md nor the project's records settle; a caveat about "
|
||||
"transient state it then handled is not one\n"
|
||||
@@ -29,11 +29,12 @@ JUDGE_RULES = (
|
||||
"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 "
|
||||
"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 project's records. A question a [loop] "
|
||||
"line answered is no longer open. If the agent asks it again, put it to the human, with answer empty.\n"
|
||||
"line answered is no longer open. If the agent asks it again, interrupt with that question.\n"
|
||||
"Where the agent asked or flagged something itself, the question is that one, in the agent's own "
|
||||
"wording; never construct another from facts it stated.\n"
|
||||
"Where README.md or the project's records answer that question, quote the passage that answers it "
|
||||
"in answer, verbatim, with interrupt=true; the agent is then given that passage in place of the human's reply.\n"
|
||||
"Where README.md or the project's records answer the agent's own question, set interrupt=false, put "
|
||||
"that question in question and quote the passage that answers it in answer, verbatim; the agent is "
|
||||
"then given that passage in place of the human's reply.\n"
|
||||
"finished=true when the chunk is complete: merged, or nothing remains that the agent could do on "
|
||||
"its own. finished=false when work remains that a further run can continue: an open PR, a review "
|
||||
"not yet run, CI not yet reported."
|
||||
@@ -41,11 +42,11 @@ JUDGE_RULES = (
|
||||
|
||||
@dataclasses.dataclass(frozen=True)
|
||||
class Reply:
|
||||
answer: str = dataclasses.field(metadata={"description": "The passage of README.md or the project's records that answers the agent's question, quoted verbatim. Empty when nothing there answers it, or when interrupt is false."})
|
||||
answer: str = dataclasses.field(metadata={"description": "With interrupt false, the passage of README.md or the project's records that answers the agent's question, quoted verbatim. Empty otherwise."})
|
||||
evidence: str = dataclasses.field(metadata={"description": "A verbatim quote of the transcript line the verdict rests on: what triggers the interrupt, else what shows the chunk finished or the work remaining."})
|
||||
finished: bool
|
||||
interrupt: bool
|
||||
question: str = dataclasses.field(metadata={"description": "The single question to put to the human. Empty when interrupt is false."})
|
||||
question: str = dataclasses.field(metadata={"description": "The single question to put to the human, or the agent's question that answer answers. Empty otherwise."})
|
||||
|
||||
|
||||
REPLY_TYPES = typing.get_type_hints(Reply)
|
||||
@@ -87,9 +88,9 @@ def run_judge(root: str, args: list[str], prompt: str, rendered_transcript: str,
|
||||
if isinstance(verdict, Failure):
|
||||
return Failure(f"{verdict.reason}; it replied: {proc.stdout.strip() or 'nothing'}")
|
||||
if not grounded(verdict.evidence, rendered_transcript):
|
||||
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 | AnsweredFromRecords) else ""))
|
||||
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.
|
||||
if isinstance(verdict, AnsweredFromRecords) and not grounded(verdict.answer, recorded):
|
||||
if isinstance(verdict, QuotedAnswer) and not grounded(verdict.answer, recorded):
|
||||
return Interrupt(verdict.evidence, verdict.question)
|
||||
return verdict
|
||||
|
||||
@@ -112,13 +113,13 @@ def verdict_from(output: object) -> Verdict | Failure:
|
||||
for name, kind in REPLY_TYPES.items():
|
||||
if not isinstance(output.get(name), kind):
|
||||
return Failure(f"the judge's reply has no {name} of type {JSON_TYPES[kind]}")
|
||||
# An interrupt outranks finished: the human answers before the chunk can close.
|
||||
# An interrupt outranks a quoted answer and finished: the human answers before the chunk can close.
|
||||
if output["interrupt"]:
|
||||
if not output["question"].strip():
|
||||
return Failure("the judge interrupted without a question")
|
||||
if output["answer"].strip():
|
||||
return AnsweredFromRecords(output["evidence"], output["question"], output["answer"])
|
||||
return Interrupt(output["evidence"], output["question"])
|
||||
if output["answer"].strip() and output["question"].strip():
|
||||
return QuotedAnswer(output["evidence"], output["question"], output["answer"])
|
||||
return Finished(output["evidence"]) if output["finished"] else Unfinished(output["evidence"])
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user