Retry the worker and the judge through one counter, in retry.py
This commit is contained in:
@@ -1,12 +1,11 @@
|
||||
import dataclasses
|
||||
import itertools
|
||||
import json
|
||||
import subprocess
|
||||
import typing
|
||||
|
||||
from loop_claude.claude_code.formats import structured_output
|
||||
from loop_claude.outcome import Failure
|
||||
from loop_claude.retry import stop_or_sleep_a_minute
|
||||
from loop_claude.retry import retried
|
||||
|
||||
JUDGE_RULES = (
|
||||
"Decide whether the human must now be interrupted. interrupt=true when any of these appear:\n"
|
||||
@@ -57,26 +56,20 @@ def judge(root, task, premises, transcript, model):
|
||||
"--tools", "",
|
||||
]
|
||||
prompt = judge_prompt(task, premises, transcript)
|
||||
for failures in itertools.count(1):
|
||||
verdict = run_judge(root, args, prompt)
|
||||
if isinstance(verdict, Failure):
|
||||
reason = verdict.reason
|
||||
elif not grounded(verdict, transcript):
|
||||
reason = f"the judge quoted {verdict.evidence!r}, nothing in the transcript" + (f", for the question: {verdict.question}" if verdict.interrupt else "")
|
||||
else:
|
||||
return verdict
|
||||
if stop := stop_or_sleep_a_minute("judge", failures, reason):
|
||||
return stop
|
||||
return retried("judge", lambda: run_judge(root, args, prompt, transcript))
|
||||
|
||||
|
||||
def run_judge(root, args, prompt):
|
||||
def run_judge(root, args, prompt, transcript):
|
||||
try:
|
||||
proc = subprocess.run(["claude", *args], capture_output=True, cwd=root, input=prompt, text=True)
|
||||
except OSError as failure:
|
||||
return Failure(f"could not start claude: {failure.strerror}")
|
||||
if proc.returncode != 0:
|
||||
return Failure(proc.stderr.strip() or f"the judge exited {proc.returncode}")
|
||||
return verdict_from(structured_output(proc.stdout))
|
||||
verdict = verdict_from(structured_output(proc.stdout))
|
||||
if isinstance(verdict, Verdict) and not grounded(verdict, transcript):
|
||||
return Failure(f"the judge quoted {verdict.evidence!r}, nothing in the transcript" + (f", for the question: {verdict.question}" if verdict.interrupt else ""))
|
||||
return verdict
|
||||
|
||||
|
||||
def judge_prompt(task, premises, transcript):
|
||||
|
||||
Reference in New Issue
Block a user