Hand the security pass back to the run, and accept a judge's elided quote
This commit is contained in:
@@ -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:
|
||||
|
||||
Reference in New Issue
Block a user