Hand the security pass back to the run, and accept a judge's elided quote
This commit is contained in:
@@ -40,5 +40,5 @@ def part_line(part: object, tool_input_chars: int) -> str:
|
||||
return text
|
||||
if call := tool_call(part):
|
||||
name, arguments = call
|
||||
return f"[tool {name}] {json.dumps(arguments)[:tool_input_chars]}"
|
||||
return f"[tool {name}] {json.dumps(arguments, ensure_ascii=False)[:tool_input_chars]}"
|
||||
return ""
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
import dataclasses
|
||||
import json
|
||||
import re
|
||||
import typing
|
||||
|
||||
from loop_claude.claude_code.entries import hit_limit, limit_said, parse_entry, structured_output
|
||||
@@ -43,7 +44,7 @@ JUDGE_RULES = (
|
||||
@dataclasses.dataclass(frozen=True)
|
||||
class Reply:
|
||||
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; for a quoted answer, the agent's question; else what shows the chunk finished or the work remaining."})
|
||||
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
|
||||
interrupt: bool
|
||||
question: str = dataclasses.field(metadata={"description": "With interrupt true, the single question to put to the human. With a quoted answer, the agent's question that the answer field answers. Empty otherwise."})
|
||||
@@ -90,7 +91,7 @@ def run_judge(root: str, args: list[str], prompt: str, rendered_transcript: str,
|
||||
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 | QuotedAnswer) else ""))
|
||||
# Not a Failure: a misquote would otherwise exit an unattended loop.
|
||||
if isinstance(verdict, QuotedAnswer) and not grounded(verdict.answer, quotable):
|
||||
if isinstance(verdict, QuotedAnswer) and not verbatim(verdict.answer, quotable):
|
||||
return Interrupt(verdict.evidence, verdict.question)
|
||||
return verdict
|
||||
|
||||
@@ -126,8 +127,21 @@ def verdict_from(output: object) -> Verdict | Failure:
|
||||
|
||||
|
||||
def grounded(evidence: str, rendered_transcript: str) -> bool:
|
||||
quoted = plain(evidence)
|
||||
return quoted != "" and quoted in plain(rendered_transcript)
|
||||
# The judge joins passages with an ellipsis though told to quote one; an elided answer stays rejected, since stitched fragments can say what the records do not.
|
||||
fragments = [fragment.strip() for fragment in re.split(r"\.\.\.|…", plain(evidence)) if fragment.strip()]
|
||||
transcript = plain(rendered_transcript)
|
||||
at = 0
|
||||
for fragment in fragments:
|
||||
found = transcript.find(fragment, at)
|
||||
if found < 0:
|
||||
return False
|
||||
at = found + len(fragment)
|
||||
return fragments != []
|
||||
|
||||
|
||||
def verbatim(quote: str, text: str) -> bool:
|
||||
quoted = plain(quote)
|
||||
return quoted != "" and quoted in plain(text)
|
||||
|
||||
|
||||
def plain(text: str) -> str:
|
||||
|
||||
@@ -52,7 +52,8 @@ Exit 1, saying why, when:
|
||||
- the worker or the judge fails three times running, retried a minute apart within the cycle. A
|
||||
worker fails when claude cannot start, exits non-zero, is killed, or ends without a result event;
|
||||
a judge when claude cannot start or exits non-zero, or its reply misses or mistypes a field,
|
||||
interrupts or quotes an answer without a question, or quotes a line the transcript does not hold.
|
||||
interrupts or quotes an answer without a question, or quotes a line the transcript does not hold;
|
||||
where the quote elides with an ellipsis, the transcript must hold each fragment, in order.
|
||||
A usage limit is not a failure, and restarts the count of three: the worker or the judge is
|
||||
retried 2 minutes after the limit resets, or every 10 minutes when the reset time is unknown or
|
||||
more than 2 minutes past. The judge's reply gives its reset time only as text, so the judge is
|
||||
|
||||
Reference in New Issue
Block a user