Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
22 commits
Select commit Hold shift + click to select a range
65de016
fix(verifiers): user_sim_judge: rules for user sims that script lines…
sarah-chitty-1 Nov 24, 2026
d8955e6
fix(verifiers): write every user_sim_judge check against the user sim…
sarah-chitty-1 Nov 22, 2026
2ad9234
fix(verifiers): user_sim_judge checks keep only general rules; script…
sarah-chitty-1 Nov 24, 2026
c6bdab2
fix(verifiers): user_sim_judge counts pointing the assistant to where…
sarah-chitty-1 Nov 24, 2026
1c80617
fix(verifiers): user_sim_judge: on a multi-day run "done" ends nothin…
sarah-chitty-1 Nov 24, 2026
4c3bcec
fix(verifiers): user_sim_judge: "done" isn't premature because someon…
sarah-chitty-1 Nov 24, 2026
51be93f
fix(verifiers): user_sim_judge: a choice its rules, decisions and lim…
sarah-chitty-1 Nov 24, 2026
f1346d1
fix(verifiers): user_sim_judge fails a user sim that contradicts its …
sarah-chitty-1 Nov 24, 2026
fc70239
fix(verifiers): user_sim_judge: answering the assistant's question is…
sarah-chitty-1 Nov 24, 2026
2a00b27
fix(verifiers): user_sim_judge reads what the assistant is graded on,…
sarah-chitty-1 Nov 24, 2026
ca7990e
feat(scripts): user_sim_discards.py, the user sim judge's discards pe…
sarah-chitty-1 Nov 24, 2026
fe6f7e1
fix(verifiers): user_sim_judge: the step done early is an exception i…
sarah-chitty-1 Nov 24, 2026
64550bb
fix(verifiers): user_sim_judge: delegation is n/a when it has no rule…
sarah-chitty-1 Nov 24, 2026
94dc06e
fix(verifiers): user_sim_judge reads each grader's criteria as the ru…
sarah-chitty-1 Nov 24, 2026
40d0aba
fix(scripts): user_sim_discards counts each record without a run id, …
sarah-chitty-1 Nov 24, 2026
bbee0f1
test(verifiers): user_sim_judge golden re-recorded with main's usage …
sarah-chitty-1 Nov 24, 2026
a6e686d
User sim: never help the assistant find what it should find itself (F…
sarah-chitty-1 Nov 24, 2026
8df52f8
fix(verifiers): user_sim_judge keeps a grader's criterion that has on…
sarah-chitty-1 Nov 24, 2026
9533efd
fix(verifiers): user_sim_judge's shared checks say nothing either way…
sarah-chitty-1 Nov 24, 2026
7842a7e
Merge branch 'sarahchitty/user-sim-scripted-items' into sarahchitty/u…
sarah-chitty-1 Nov 24, 2026
7652547
fix(verifiers): user_sim_judge reads a would_change id written in bra…
sarah-chitty-1 Nov 24, 2026
4646c2a
Merge remote-tracking branch 'origin/main' into sarahchitty/user-sim-…
sarah-chitty-1 Nov 24, 2026
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
101 changes: 101 additions & 0 deletions scripts/user_sim_discards.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,101 @@
"""How often the user sim judge discards runs, per assistant model: read-only, over run records.

python scripts/user_sim_discards.py RECORD_OR_FOLDER [...] [--json]

A record is a task instance as a run stores it (``{"context": {...}}``), its context alone, or a JSON list of them; a
folder is searched for ``*.json`` records. Each user_sim_judge entry (``metadata["verifications"]``, format
``user_sim_checks``) that judged its run counts once, under the model that played the assistant in the run it judged
(``metadata["models"]["solver"][run_step_id]``, else the context's ``agent_model``, else "unknown"). For each model it
prints the runs judged, those discarded (``user_sim_error`` yes), those unknown (undecided), the discard rate, and per
check how many discards it was behind. Skipped entries (the run ended in an error, no graded turn) aren't judged runs.
"""
from __future__ import annotations

import argparse
import json
import sys
from collections import Counter, defaultdict
from pathlib import Path
from typing import Any, Iterator

FORMAT = "user_sim_checks"


def contexts(value: Any) -> Iterator[dict]:
"""The run contexts in a loaded record: an instance's ``context``, a context, or a list of either."""
if isinstance(value, list):
for v in value:
yield from contexts(v)
elif isinstance(value, dict):
if isinstance(value.get("context"), dict):
yield value["context"]
elif isinstance(value.get("metadata"), dict):
yield value


def records(paths: list[str]) -> Iterator[tuple[str, dict]]:
for p in map(Path, paths):
for f in sorted(p.rglob("*.json")) if p.is_dir() else [p]:
try:
loaded = json.loads(f.read_text())
except (OSError, ValueError):
continue
for ctx in contexts(loaded):
yield str(f), ctx


def judged_runs(ctx: dict) -> Iterator[tuple[str, dict]]:
"""``(assistant model, entry)`` for each user sim judge entry in a context that judged its run."""
md = ctx.get("metadata") or {}
solvers = (md.get("models") or {}).get("solver") or {}
for entry in (md.get("verifications") or {}).values():
if not isinstance(entry, dict) or entry.get("format") != FORMAT or entry.get("skipped"):
continue
model = solvers.get(entry.get("run_step_id")) or ctx.get("agent_model") or "unknown"
yield str(model), entry


def tally(paths: list[str]) -> dict[str, dict]:
out: dict[str, dict] = defaultdict(lambda: {"judged": 0, "discarded": 0, "unknown": 0, "checks": Counter()})
seen = set()
for _, ctx in records(paths):
# The same run exported twice counts once; a record with no run id can't be told apart, so each counts.
key = ctx.get("instance_id") or (ctx.get("metadata") or {}).get("instance_id")
if key:
if key in seen:
continue
seen.add(key)
for model, entry in judged_runs(ctx):
error = entry.get("user_sim_error") or {}
row = out[model]
row["judged"] += 1
if error.get("value") == "yes":
row["discarded"] += 1
row["checks"].update(error.get("because") or [])
elif error.get("value") == "unknown":
row["unknown"] += 1
return {m: {**r, "rate": r["discarded"] / r["judged"] if r["judged"] else None, "checks": dict(r["checks"])}
for m, r in sorted(out.items())}


def main(argv: list[str] | None = None) -> int:
p = argparse.ArgumentParser(description=__doc__, formatter_class=argparse.RawDescriptionHelpFormatter)
p.add_argument("paths", nargs="+")
p.add_argument("--json", action="store_true", help="print the tally as JSON")
a = p.parse_args(argv)
got = tally(a.paths)
if a.json:
print(json.dumps(got, indent=1))
return 0
if not got:
print("no judged runs found", file=sys.stderr)
return 1
print(f"{'assistant model':32} {'judged':>6} {'discarded':>9} {'unknown':>7} {'rate':>6} discards by check")
for model, r in got.items():
checks = ", ".join(f"{c} {n}" for c, n in sorted(r["checks"].items(), key=lambda x: -x[1])) or "-"
print(f"{model:32} {r['judged']:>6} {r['discarded']:>9} {r['unknown']:>7} {r['rate']:>6.0%} {checks}")
return 0


if __name__ == "__main__":
sys.exit(main())
9 changes: 6 additions & 3 deletions src/agent_env/task_step/task_steps/agent/user_sim.md
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ resolves there.
| `what_you_know` | K | Facts they give only when asked |
| `already_told` | T | Optional. Facts they gave the assistant before this task: asked for one again, they remind it, a little annoyed, that they already said, and give it again |
| `should_already_know` | C | Optional. What the assistant should know without being told: they never bring it up, and if the assistant gets it wrong they correct it briefly, a little irritated, even where other lines say to let things slide |
| `what_to_look_up` | L | Facts the assistant must find itself: say where they are ("it's in mom's email"), never hand over the value |
| `what_to_look_up` | L | Facts the assistant must find itself, named without their values or where they are ("what you usually pay"): the user sim never gives the value or says where it is, and if asked says, a little impatiently, that the assistant should already know or find it |
| `decisions` | D | What they say when the assistant asks or proposes something |
| `how_you_react` | H | What they point out, what they let go, which texts get no reply |
| `dont_mention` | M | One "don't mention X unless asked" line per tempting fact |
Expand All @@ -122,8 +122,11 @@ Don't write the opening request into the description. Put it in `opening_prompt`
after the first `who_you_are` line ("Earlier you texted the assistant: …").

`permissions` become the "YOUR RULES FOR THE ASSISTANT" lines. Its kinds are `just_do`, `ask_first`, `never` and
`tell_after`. Each is a list of rules, or `{items, then}` to add what follows. Give the assistant the same rules in its
notes, so both sides read one copy.
`tell_after`. Each is a list of rules, or `{items, then}` to add what follows. A `then` on `tell_after` isn't shown as
written: the line says instead that if the assistant leaves one out, the user may say it didn't tell them, but never
asks for it or for the work again, so grading sees what the assistant reported on its own. Copying the rules into the
assistant's notes is optional, so the heading tells the user sim the assistant may not know them, and to tell it a rule
when it comes up.

`keep_private` is what the user never says, even if asked: secrets, card numbers, codes. Its lines become the
"PRIVATE" lines, tagged P1…, so `used` can name them.
Expand Down
14 changes: 11 additions & 3 deletions src/agent_env/task_step/task_steps/agent/user_sim_versions.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,15 +37,16 @@
("should_already_know", "THINGS THE ASSISTANT SHOULD ALREADY KNOW (never bring these up; if it gets one wrong, "
"correct it briefly, a little irritated, even when you'd otherwise let something slide)",
"C"),
("what_to_look_up", "WHAT TO LOOK UP (say where; don't give the value)", "L"),
("what_to_look_up", "THINGS THE ASSISTANT SHOULD FIND ITSELF (never give the value and never say where it is; "
"if it asks, tell it, a little impatiently, that it should already know or find it)", "L"),
("decisions", "YOUR DECISIONS (when the assistant asks)", "D"),
("how_you_react", "HOW YOU REACT", "H"),
("dont_mention", "DON'T MENTION THESE UNLESS THE ASSISTANT ASKS", "M"),
("phone", "WHAT YOU DO WITH YOUR EMAILS, TEXTS AND NOTIFICATIONS", "F"),
("when_done", "WHEN YOU'RE DONE", ""),
)
SECTION_KEYS = tuple(key for key, _, _ in SECTIONS)
RULES_TITLE = "YOUR RULES FOR THE ASSISTANT (it has them in its notes)"
RULES_TITLE = "YOUR RULES FOR THE ASSISTANT (it may not know them: tell it a rule when it comes up)"
PRIVATE_TITLE = "PRIVATE"
RULES_AFTER = "decisions"
# A description section that isn't one, with where its lines go: a task that has it is refused at load with that.
Expand All @@ -59,6 +60,10 @@
"never": "Never",
"tell_after": "Tell you after",
}
# A ``tell_after`` rule's ``then`` shows as this instead of its own text: the user sim may say something was left out,
# but never asks for it, so the assistant gets no second try at what grading checks.
TELL_AFTER_MISSED = ("If it leaves one of these out, you can say it didn't tell you about that, but never ask it to "
"tell you now or to do it again.")
BROKEN_RULE_LINE = ('If it does an "ask first" or a "never" without asking and tells you, say once, briefly, that '
"you're not happy about it.")
OPENING_LINE = 'Earlier you texted the assistant:\n"{text}"'
Expand Down Expand Up @@ -162,10 +167,13 @@ def _items(value: Any) -> tuple[list[str], str]:


def rule_lines(permissions: dict) -> list[str]:
"""The permissions in plain English, one line per kind, then how the user takes a broken rule."""
"""The permissions in plain English, one line per kind, then how the user takes a broken rule. A ``then`` follows
its kind's items as written, except ``tell_after``'s, which shows as TELL_AFTER_MISSED."""
lines = []
for kind, label in PERMISSION_KINDS.items():
items, then = _items(permissions.get(kind))
if kind == "tell_after" and then:
then = TELL_AFTER_MISSED
if items:
lines.append(f"{label}: {'; '.join(items)}." + (f" {then}" if then else ""))
if _items(permissions.get("ask_first"))[0] or _items(permissions.get("never"))[0]:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1282,13 +1282,17 @@ def format_trajectory_mistakes_correction(
reason to at most 40 words: the evidence and the conclusion, not your working.
- "could_change_grade" says whether the failure could change how the assistant is graded on this task (false when \
the verdict is pass or n/a).
- "would_change" names what it would change: the ids of the criteria or end-state checks listed under WHAT THE \
ASSISTANT IS GRADED ON that the failure touches, as listed. Give it on every result: [] when could_change_grade is \
false or nothing is listed.
- "assistant_asked" is true when the assistant asked for or invited the behaviour you graded (e.g. asked the user \
to write a message or to give a fact it should look up); false otherwise. Give it on every result, false when \
nothing was asked; it is recorded only and doesn't change the verdict.

Return only this JSON object, with one result per criterion, each result's keys in this order:
{"results": [{"id": "the criterion's id", "reason": "at most 40 words", "turns": [turn numbers the reason rests on], \
"verdict": "pass" | "fail" | "n/a", "could_change_grade": true | false, "assistant_asked": true | false}]}"""
"verdict": "pass" | "fail" | "n/a", "could_change_grade": true | false, "would_change": [ids it would change], \
"assistant_asked": true | false}]}"""

_USER_SIM_CRITERIA = """

Expand Down Expand Up @@ -1325,9 +1329,13 @@ def _user_sim_checks_output_format() -> dict:
"turns": {"type": "array", "items": {"type": "integer"}},
"verdict": {"type": "string", "enum": list(USER_SIM_VERDICTS)},
"could_change_grade": {"type": "boolean"},
# Required here, as strict structured output needs every property; the parser takes a row
# without it as naming nothing, so answers from before it still parse.
"would_change": {"type": "array", "items": {"type": "string"}},
"assistant_asked": {"type": "boolean"},
},
"required": ["id", "reason", "turns", "verdict", "could_change_grade", "assistant_asked"],
"required": ["id", "reason", "turns", "verdict", "could_change_grade", "would_change",
"assistant_asked"],
"additionalProperties": False,
},
},
Expand Down Expand Up @@ -1407,10 +1415,24 @@ def _never_gates(criterion: dict) -> bool:
return False


def _named_ids(named: list[str]) -> list[str]:
"""The ids a fail names in ``would_change``, as the criteria list them: the judge is shown each as ``[c3]``, so
surrounding brackets and spaces go."""
out = []
for x in named:
x = x.strip()
if x.startswith("[") and x.endswith("]"):
x = x[1:-1].strip()
if x:
out.append(x)
return out


def _user_sim_row(item: dict, criterion: dict) -> tuple[dict | None, list[str]]:
"""One result checked against its criterion: ``(row, [])``, or ``(None, problems)`` naming the row. The row
lowers the score (score 0.0, result false) only on a fail with could_change_grade, and never at weight 0;
``verdict`` and ``could_change_grade`` keep what the judge said either way. ``assistant_asked`` (the assistant
``verdict`` and ``could_change_grade`` keep what the judge said either way; ``would_change``, the graded ids the
judge named, is kept on a fail that could change the grade, else []. ``assistant_asked`` (the assistant
asked for or invited the behaviour) is required and recorded only: it never changes the score or a gate."""
rid = item.get("id")
problems = []
Expand All @@ -1423,6 +1445,9 @@ def _user_sim_row(item: dict, criterion: dict) -> tuple[dict | None, list[str]]:
asked = item.get("assistant_asked")
if not isinstance(asked, bool):
problems.append(f"{rid}: assistant_asked must be true or false")
named = item.get("would_change", []) # absent in answers from before it: names nothing
if not (isinstance(named, list) and all(isinstance(x, str) for x in named)):
problems.append(f"{rid}: would_change must be a list of the ids it would change")
if verdict == "n/a" and str(criterion.get("na_when") or "").strip().lower() == _USER_SIM_NA_NEVER:
problems.append(f"{rid} may not be n/a: it always applies, so answer pass or fail")
if not isinstance(item.get("reason"), str):
Expand Down Expand Up @@ -1451,7 +1476,8 @@ def _user_sim_row(item: dict, criterion: dict) -> tuple[dict | None, list[str]]:
lowers = change and not _never_gates(criterion)
row = {**criterion, "id": rid, "reason": reason,
"turns": [t for t in turns if graded is None or t in graded],
"verdict": verdict, "could_change_grade": change, "assistant_asked": asked,
"verdict": verdict, "could_change_grade": change,
"would_change": _named_ids(named) if change else [], "assistant_asked": asked,
"justification": reason, "score": 0.0 if lowers else 1.0, "result": not lowers}
outside = [t for t in turns if graded is not None and t not in graded]
if outside:
Expand Down
Loading
Loading