Render the human's typed turns for the judge, so an answered question is not asked again #55
+10
-6
@@ -26,7 +26,8 @@ boundary, once the new file answers --help.
|
|||||||
Claude Code internals this rests on, observed on 2.1.282:
|
Claude Code internals this rests on, observed on 2.1.282:
|
||||||
- The transcript is ~/.claude/projects/*/<session-id>.jsonl, one JSON object per line. A <session-id>/
|
- The transcript is ~/.claude/projects/*/<session-id>.jsonl, one JSON object per line. A <session-id>/
|
||||||
folder and <session-id>.superseded-*/ and .orphaned-*.jsonl siblings belong to the same session.
|
folder and <session-id>.superseded-*/ and .orphaned-*.jsonl siblings belong to the same session.
|
||||||
- Claude Code writes "user" entries of its own into the transcript; typed() tells a human's from them.
|
- Claude Code writes "user" entries of its own into the transcript, and a `claude -p` prompt lands as one
|
||||||
|
with promptSource "sdk"; typed() tells a human's from them.
|
||||||
- An "assistant" entry, in the transcript and in --output-format stream-json, carries message.content
|
- An "assistant" entry, in the transcript and in --output-format stream-json, carries message.content
|
||||||
parts of type "text" (text) and "tool_use" (name, input); stream-json ends with a "result" event.
|
parts of type "text" (text) and "tool_use" (name, input); stream-json ends with a "result" event.
|
||||||
- `claude -p --output-format json --json-schema` returns the verdict under "structured_output".
|
- `claude -p --output-format json --json-schema` returns the verdict under "structured_output".
|
||||||
@@ -59,8 +60,8 @@ JUDGE_RULES = (
|
|||||||
"rule the rejected one out - and the choice materially changes the deliverable\n"
|
"rule the rejected one out - and the choice materially changes the deliverable\n"
|
||||||
"ask=false otherwise. A sensible preference is not a derivation. Bookkeeping the agent settled "
|
"ask=false otherwise. A sensible preference is not a derivation. Bookkeeping the agent settled "
|
||||||
"silently - what to document, wording, where a note goes - is not on its own a reason to "
|
"silently - what to document, wording, where a note goes - is not on its own a reason to "
|
||||||
"interrupt. The human may have replied inside the transcript: judge only what is still open, "
|
"interrupt. The human may have replied inside the transcript, on a [human] line: judge only what "
|
||||||
"never a question they already answered there.\n"
|
"is still open, never a question they already answered there.\n"
|
||||||
"The question must be one the agent itself raised. Never construct a question from facts the agent "
|
"The question must be one the agent itself raised. Never construct a question from facts the agent "
|
||||||
"stated. When ask=true, quote the agent's own wording where it already framed the question.\n"
|
"stated. When ask=true, quote the agent's own wording where it already framed the question.\n"
|
||||||
"finished=true when the chunk is complete: merged, or nothing remains that the agent could do on "
|
"finished=true when the chunk is complete: merged, or nothing remains that the agent could do on "
|
||||||
@@ -171,12 +172,15 @@ def render(entries):
|
|||||||
for entry in entries:
|
for entry in entries:
|
||||||
if entry.get("type") == "assistant":
|
if entry.get("type") == "assistant":
|
||||||
lines += [line for part in entry.get("message", {}).get("content", []) if (line := said(part))]
|
lines += [line for part in entry.get("message", {}).get("content", []) if (line := said(part))]
|
||||||
|
elif typed(entry):
|
||||||
|
content = entry["message"]["content"]
|
||||||
|
lines.append("[human] " + (content if isinstance(content, str) else "".join(part.get("text", "") for part in content)))
|
||||||
return "\n\n".join(lines)
|
return "\n\n".join(lines)
|
||||||
|
|
||||||
|
|
||||||
def typed(entry):
|
def typed(entry):
|
||||||
"""A human turn: a "user" entry, not isMeta, whose message.content is a string not starting with "<" (<command-name> and its kind) or one or more text parts, none starting with "[Request interrupted"."""
|
"""A human turn: a "user" entry, not isMeta, not promptSource "sdk" (the loop's own prompts), whose message.content is a string not starting with "<" (<command-name> and its kind) or one or more text parts, none starting with "[Request interrupted"."""
|
||||||
if entry.get("type") != "user" or entry.get("isMeta"):
|
if entry.get("type") != "user" or entry.get("isMeta") or entry.get("promptSource") == "sdk":
|
||||||
return False
|
return False
|
||||||
content = entry.get("message", {}).get("content")
|
content = entry.get("message", {}).get("content")
|
||||||
if isinstance(content, str):
|
if isinstance(content, str):
|
||||||
@@ -286,7 +290,7 @@ def judge_prompt(task, premises, transcript):
|
|||||||
f"From README.md:\n{premises}\n\n"
|
f"From README.md:\n{premises}\n\n"
|
||||||
f"The task an agent was given:\n{task}\n\n"
|
f"The task an agent was given:\n{task}\n\n"
|
||||||
# The tail, where an ask or a finish lands; the session's transcript grows cycle over cycle.
|
# The tail, where an ask or a finish lands; the session's transcript grows cycle over cycle.
|
||||||
f"What the agent then did and said, latest last:\n{transcript[-40000:]}\n\n"
|
f"What the agent did and said, and what the human typed on [human] lines, latest last:\n{transcript[-40000:]}\n\n"
|
||||||
f"{JUDGE_RULES}"
|
f"{JUDGE_RULES}"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|||||||
@@ -66,13 +66,17 @@ class ReadPremises(unittest.TestCase):
|
|||||||
|
|
||||||
|
|
||||||
class Render(unittest.TestCase):
|
class Render(unittest.TestCase):
|
||||||
def test_joins_assistant_text_and_tool_calls_and_skips_the_rest(self):
|
def test_joins_assistant_text_and_tool_calls_and_human_turns_and_skips_the_rest(self):
|
||||||
said = loop.render([
|
said = loop.render([
|
||||||
human("do it"),
|
human("do it"),
|
||||||
assistant({"type": "text", "text": "Starting."}, {"type": "tool_use", "name": "Bash", "input": {"command": "ls"}}),
|
assistant({"type": "text", "text": "Starting."}, {"type": "tool_use", "name": "Bash", "input": {"command": "ls"}}),
|
||||||
assistant({"type": "text", "text": " "}),
|
assistant({"type": "text", "text": " "}),
|
||||||
|
human([{"type": "tool_result", "content": "not typed"}]),
|
||||||
|
human("<command-name>/exit</command-name>"),
|
||||||
|
human([{"type": "text", "text": "yes, "}, {"type": "text", "text": "merge it"}]),
|
||||||
|
{**human("Continue the task; the previous run stopped before it was finished."), "promptSource": "sdk"},
|
||||||
])
|
])
|
||||||
self.assertEqual(said, 'Starting.\n\n[tool Bash] {"command": "ls"}')
|
self.assertEqual(said, '[human] do it\n\nStarting.\n\n[tool Bash] {"command": "ls"}\n\n[human] yes, merge it')
|
||||||
|
|
||||||
|
|
||||||
class HumanTurns(unittest.TestCase):
|
class HumanTurns(unittest.TestCase):
|
||||||
@@ -83,6 +87,7 @@ class HumanTurns(unittest.TestCase):
|
|||||||
human([{"type": "tool_result", "content": "not typed"}]),
|
human([{"type": "tool_result", "content": "not typed"}]),
|
||||||
human("<command-name>/model</command-name>"),
|
human("<command-name>/model</command-name>"),
|
||||||
{**human("peer message"), "isMeta": True},
|
{**human("peer message"), "isMeta": True},
|
||||||
|
{**human("the loop's own prompt"), "promptSource": "sdk"},
|
||||||
human([{"type": "text", "text": "[Request interrupted by user]"}]),
|
human([{"type": "text", "text": "[Request interrupted by user]"}]),
|
||||||
human([]),
|
human([]),
|
||||||
assistant({"type": "text", "text": "said"}),
|
assistant({"type": "text", "text": "said"}),
|
||||||
|
|||||||
Reference in New Issue
Block a user