Answer the stability and product passes: print each records answer, name its question, drop a misquote to an interrupt, budget the whole prompt
This commit is contained in:
@@ -10,8 +10,8 @@ from loop_claude.failure import Failure
|
||||
from loop_claude.limited import Limited
|
||||
from loop_claude.stop import Stop
|
||||
|
||||
# About 100,000 tokens, half a 200,000-token context; the largest session rendered here was 364,000 characters on 2026-10-03.
|
||||
JUDGED_TRANSCRIPT_TAIL = 400000
|
||||
# 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, or README.md and the project's records, "
|
||||
@@ -88,20 +88,22 @@ def run_judge(root: str, args: list[str], prompt: str, rendered_transcript: str,
|
||||
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 ""))
|
||||
# An answer the records do not hold verbatim is dropped, and the question goes to the human.
|
||||
if isinstance(verdict, AnsweredFromRecords) and not grounded(verdict.answer, recorded):
|
||||
return Failure(f"the judge answered {verdict.question!r} with {verdict.answer!r}, which README.md and the project's records do not hold")
|
||||
return Interrupt(verdict.evidence, verdict.question)
|
||||
return verdict
|
||||
|
||||
|
||||
def judge_prompt(task: str, premises: str, records: str, rendered_transcript: str) -> str:
|
||||
return (
|
||||
head = (
|
||||
f"From README.md:\n{premises}\n\n"
|
||||
f"The project's records, its working rules and decisions:\n{records or 'none'}\n\n"
|
||||
f"The task an agent was given:\n{task}\n\n"
|
||||
# The tail, where an interrupt or a finish lands; the session's transcript grows cycle over cycle.
|
||||
f"What the agent did and said, what the human typed on [human] lines and what loop-claude told it on [loop] lines, latest last:\n{rendered_transcript[-JUDGED_TRANSCRIPT_TAIL:]}\n\n"
|
||||
f"{JUDGE_RULES}"
|
||||
"What the agent did and said, what the human typed on [human] lines and what loop-claude told it on [loop] lines, latest last:\n"
|
||||
)
|
||||
room = max(0, JUDGE_PROMPT_CHARS - len(head) - len(JUDGE_RULES) - 2)
|
||||
# The tail, where an interrupt or a finish lands; the session's transcript grows cycle over cycle.
|
||||
return f"{head}{rendered_transcript[max(0, len(rendered_transcript) - room):]}\n\n{JUDGE_RULES}"
|
||||
|
||||
|
||||
def verdict_from(output: object) -> Verdict | Failure:
|
||||
@@ -110,8 +112,6 @@ 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]}")
|
||||
if output["answer"].strip() and not output["interrupt"]:
|
||||
return Failure("the judge answered without interrupting")
|
||||
# An interrupt outranks finished: the human answers before the chunk can close.
|
||||
if output["interrupt"]:
|
||||
if not output["question"].strip():
|
||||
|
||||
Reference in New Issue
Block a user