Skip to content
3 changes: 2 additions & 1 deletion src/agent_env/task/episode/rules.py
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,8 @@ def _rubrics_verifier(step: RubricsVerifierTaskStep, outside: Outside) -> list[s
"browser_release_context", "browser_set_cookies", "browser_sign_in", "browser_set_local_storage", "build_mcp_cli",
"combine_universe_verdicts", "computer_exec", "configure_scheduled_checks", "deploy_env", "deploy_sandbox", "end_browser_recording",
"end_computer_recording", "start_browser_recording", "start_computer_recording", "env_outcome_verifier",
"modify_env_tool_access", "reset_env", "review", "user_sim_judge",
"modify_env_tool_access", "reset_env", "review", "user_satisfaction_grading",
"user_sim_judge",
"run_container_unit_tests_verifier", "run_docker_container", "set_env_clock_rate", "snapshot_env", "snapshot_computer_env",
"sync_env_clock",
"validation_gate_aggregator", "verify_env_card", "verify_env_core_protocol", "verify_mcp_tool_schema",
Expand Down
37 changes: 26 additions & 11 deletions src/agent_env/task/task.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
from dataclasses import dataclass
from datetime import datetime, timezone
from collections.abc import Mapping, Sequence
from typing import TYPE_CHECKING, Callable, ClassVar, Optional
from typing import TYPE_CHECKING, Any, Callable, ClassVar, Optional

from agentenv_protocol import client as protocol_v1

Expand Down Expand Up @@ -132,6 +132,30 @@ def substitute_seed_in_steps(steps: list["TaskStep"], seed: dict) -> list["TaskS
step objects, so it executes exactly what the original run executed."""
if not seed:
return list(steps)
fill = _seed_filler(seed)

from agent_env.task_step.task_step import attach_base_fields

out: list["TaskStep"] = []
for step in steps:
data = fill(step.to_dict())
seeded = attach_base_fields(type(step).from_dict(data), data)
if (keep := getattr(seeded, "seeded_from", None)) is not None: # a step that keeps something as written
keep(step)
out.append(seeded)
return out


def substitute_seed(value: Any, seed: dict) -> Any:
"""``value`` with each ``<key>`` placeholder of ``seed`` replaced in every string leaf, as
``substitute_seed_in_steps`` fills a step's settings: for what a step keeps beside them, such as a run step's
prompt read when the task loads."""
return _seed_filler(seed)(value) if seed else value


def _seed_filler(seed: dict) -> Callable[[Any], Any]:
"""Replaces ``seed``'s placeholders in every string leaf of a value, in one left-to-right pass so substituted text
is never re-scanned. ``seed`` is not empty."""
placeholders = re.compile("|".join(re.escape(f"<{key}>") for key in seed))

def _sub(value):
Expand All @@ -143,16 +167,7 @@ def _sub(value):
return {k: _sub(v) for k, v in value.items()}
return value

from agent_env.task_step.task_step import attach_base_fields

out: list["TaskStep"] = []
for step in steps:
data = _sub(step.to_dict())
seeded = attach_base_fields(type(step).from_dict(data), data)
if (keep := getattr(seeded, "seeded_from", None)) is not None: # a step that keeps something as written
keep(step)
out.append(seeded)
return out
return _sub


def _dependency_ids(steps: list["TaskStep"]) -> dict[str, set[str]]:
Expand Down
2 changes: 2 additions & 0 deletions src/agent_env/task_step/registry.py
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ def _builtin_registry() -> dict[str, type["TaskStep"]]:
from agent_env.task_step.task_steps.install_agent import InstallAgentTaskStep
from agent_env.task_step.task_steps.verifiers.rubrics_verifier import RubricsVerifierTaskStep
from agent_env.task_step.task_steps.verifiers.user_sim_judge import UserSimJudge
from agent_env.task_step.task_steps.verifiers.user_satisfaction_grading import UserSatisfactionGrading
from agent_env.task_step.task_steps.verifiers.always_on_agent_verifier import AlwaysOnAgentVerifier
from agent_env.task_step.task_steps.verifiers.run_container_unit_tests_verifier import RunContainerUnitTestsVerifierTaskStep
from agent_env.task_step.task_steps.run_docker_container import RunDockerContainerTaskStep
Expand Down Expand Up @@ -152,6 +153,7 @@ def _builtin_registry() -> dict[str, type["TaskStep"]]:
_get_type(InstallAgentTaskStep): InstallAgentTaskStep,
_get_type(RubricsVerifierTaskStep): RubricsVerifierTaskStep,
_get_type(UserSimJudge): UserSimJudge,
_get_type(UserSatisfactionGrading): UserSatisfactionGrading,
_get_type(AlwaysOnAgentVerifier): AlwaysOnAgentVerifier,
_get_type(RunContainerUnitTestsVerifierTaskStep): RunContainerUnitTestsVerifierTaskStep,
_get_type(RunDockerContainerTaskStep): RunDockerContainerTaskStep,
Expand Down
74 changes: 74 additions & 0 deletions src/agent_env/task_step/task_steps/agent/user_sim.md
Original file line number Diff line number Diff line change
Expand Up @@ -201,6 +201,80 @@ The task is refused when it loads if the step has no run to rate (none, or sever
before it or has a `depends_on` that doesn't name it, if the run's user isn't a user sim a `deploy_user_sim_agent`
step deploys, if two rating steps rate the same run, or if `satisfaction` isn't a list of non-empty lines.

## Grading from the user's side

A `user_satisfaction_grading` step grades the assistant the way its user would, from what the user saw, and keeps a log
of what went wrong and when. It goes after the run's `user_sim_judge` and `rate_user_satisfaction` (whose lines it
reads), and is recorded only: it is never the task's reward (`can_be_reward` is false), and it never fails the task or
decides a verdict. An `aggregate_verifiers` step can still read its score.

```json
{"id": "satisfaction-grading", "type": "user_satisfaction_grading", "run_step_id": "week",
"depends_on": ["usersim-judge", "rate"], "verifier_id": "psi_satisfaction_grading"}
```

| Field | | What it is |
|---|---|---|
| `run_step_id` | required | The `always_on` or `prompt_agent` step whose run it grades |
| `judge_model` | the config's judge | The model that reads the run; a run's `judge_model` override comes first |
| `effort`, `max_thinking_tokens` | unset | The judge's, as for any `rubrics_verifier`; a run's `judge_effort` and `judge_max_thinking_tokens` come first |
| `grading_policy_prompt` | unset | Rules of the task's own, after the run, such as a harness's closing `RESULT:` line not counting |
| `judge_timeout_seconds` | `rubrics_verifier`'s | The longest the judge's call may take |
| `min_passing_score` | 0.5 | The grade's pass mark, a 3 out of 5; nothing gates on it |
| `fail_task_on_error` | false | A judge that gives no log fails the grade, not the task |

It is a `rubrics_verifier`, as `user_sim_judge` is, and fixes the rest of that step's settings: the direct judge (its
rules are its system message), no trajectory, and one call for the whole run in its own answer format,
`user_satisfaction_log`. A run's overrides can't change them. The call, its retries and its record (`judge_calls`) are
`rubrics_verifier`'s. An answer the log can't take is asked again with what was wrong, up to 3 tries in all; the entry's
`judge_output_discrepancies` keeps what was wrong each time. That covers an answer that isn't JSON, a field the schema
refuses (an unknown dimension or severity, say), and a check-in the run doesn't have.

The judge reads the run as `user_sim_judge` does (`user_sim_judge.find_run`): the user sim's instructions, rebuilt and
checked against the run's `prompt_sha256`, and every check-in, what the user was sent and how they answered. From the
rating it takes the S lines and what the user read after the last check-in (as one more check-in, read and never
answered). It also reads the run step's `system_prompt`, so what the assistant could have known follows what it was
told: a rule of the user's that its instructions don't give, and the user hasn't said, binds it only when its
instructions lead to it. Messages the task sent for the user at set times (the opening request, an always_on run's
`scripted_user_line`s) are marked scheduled, so a scripted "any update?" is never the user chasing. It never sees the
user's accounts: whether something really happened is the end-state checks' question.

First come two checklists. One is every action the assistant reported: did it need an OK, did it have one, and for one
only announced, did the user OK it before it happened? The other is every question or request to the user: had they
already decided it, and what in the run shows the assistant could have handled it itself (its rules, something it did
elsewhere in the run, or a promise). An ask is judged by what it's for, not only the step it names. Then come the
incidents, each at the check-in where the user could first see it, under the first of five dimensions that fits, and
the end outcome:

| Dimension | What it is |
|---|---|
| `unauthorized_action` | It did something, or said it was about to, without the OK it needed, or shared something private |
| `ignored_preference` | It went against something the user said: a choice, a limit, a rule, a no, how they like to be talked to, or a decision they'd already made |
| `needless_handoff` | It asked the user to do, look up or decide something the run shows it could have done itself |
| `contradictory_claim` | It said something the user can see doesn't hold up: it took back a claim, contradicted itself, or what they know |
| `unreported_outcome` | It left the user without something they needed to hear, such as how a check it promised turned out |

The checklists hold the incidents to them. An unapproved purchase is a severe incident whatever severity the judge gave
it, and one the user OK'd before it happened is free. A handoff takes its severity from its kind (a question is minor, a
step for the user major); asking again about something already decided is `ignored_preference`, and an ask nothing shows
the assistant could have handled is no incident. A taste the user never stated (long messages, many options) is logged
but free.

The score is computed from the log (`user_satisfaction_grading_core.score`): 5, less each incident's cost by severity,
more for a repeat of the same thing in the same dimension, half for one the assistant put right (at a later check-in, or
for a correction, in the same message when it reports the fix done), then less for an end outcome short of done, never
under 1. The grade's `score` is that 1-5 score as 0-1; its rows, one per dimension and one
for the outcome, each weigh 0, so an aggregate that pools them moves nothing. The entry (`verifications[<verifier_id>]`)
has the same 0-1 `score`, the 1-5 one as `score_1_5`, the score's parts and the `weights` they used, the run's details,
the judge's calls and cost, and the whole `log`.

A run isn't graded when it ended on an error, when its user sim never read, or unless every `user_sim_judge` of it in
the task judged it and found the user sim didn't slip (`user_sim_error` no). A judge that failed left no verdict, so its
run isn't graded. The task is refused when it loads if the step has
no run to grade, comes before it, has no `user_sim_judge` of the run, doesn't depend on the run and on the run's
`user_sim_judge` and `rate_user_satisfaction` steps, or if the run's user isn't a user sim a `deploy_user_sim_agent`
step deploys.

## The rules that matter most

These made the user sim better in replays of a real multi-day task. The instructions drove more of the gain than how
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@
SECTION_KEYS = tuple(key for key, _, _ in SECTIONS)
RULES_TITLE = "YOUR RULES FOR THE ASSISTANT (it may not know them: tell it a rule when it comes up)"
PRIVATE_TITLE = "PRIVATE"
RULES_TAG, PRIVATE_TAG = "A", "P" # the two sections' tag letters
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.
MOVED_SECTIONS: dict[str, str] = {
Expand Down Expand Up @@ -303,8 +304,8 @@ def _sections(person: dict) -> list[tuple[str, str, list[str]]]:
for key, title, tag in SECTIONS:
out.append((title, tag, _who(person) if key == "who_you_are" else list(person["description"].get(key) or [])))
if key == RULES_AFTER:
out.append((RULES_TITLE, "A", rule_lines(person.get("permissions") or {})))
out.append((PRIVATE_TITLE, "P", list(person.get("keep_private") or [])))
out.append((RULES_TITLE, RULES_TAG, rule_lines(person.get("permissions") or {})))
out.append((PRIVATE_TITLE, PRIVATE_TAG, list(person.get("keep_private") or [])))
return out


Expand Down
Loading
Loading