From 407c4439211b40d4cef005e2c1944c66665d78e4 Mon Sep 17 00:00:00 2001 From: Edgar Arakelyan Date: Sun, 22 Nov 2026 21:30:18 -0800 Subject: [PATCH 1/2] feat(lint): a judge that runs in the solver's own agent is an error An agent judge whose agent_name names the agent a step prompts as the agent under test grades the solver's own work, and posts its own model and settings to that agent first. Lint now refuses it (judge-as-solver), as training already did; --skip-lint runs it anyway. solver_agents, beside user_sim_agents, is the one definition of the solver's agents: solver_steps, the lint rule and training's check read it, and a name that isn't a string names no agent, so lint answers rather than crashing on one. Tests also pin that a judge out of retries writes a failed grade. Co-Authored-By: Claude Opus 5.5 --- AGENTS.md | 2 +- src/agent_env/bundle/plan.py | 9 ++-- src/agent_env/task/lint.py | 18 +++++++ .../task_step/task_steps/prompt_agent.py | 21 ++++++-- src/agent_env/training/harness.py | 6 +-- tst/unit/task/lint_test.py | 53 +++++++++++++++++++ .../verifiers/test_rubrics_family_grades.py | 31 ++++++++++- 7 files changed, 124 insertions(+), 16 deletions(-) diff --git a/AGENTS.md b/AGENTS.md index f0914a63b..a966de89d 100644 --- a/AGENTS.md +++ b/AGENTS.md @@ -140,7 +140,7 @@ and deserialized through a registry. |---|---| | `env/` | `Env` base class: a subclass declares `type`, implements `from_dict` and `async deploy(...) -> DeployedEnv`, and may override `reset`, `close` and `load_file_artifact_universe`; teardown closes each env a run deployed before terminating its sandboxes by id. Built-ins in `env/envs/`: `MCPServerEnv` (`mcp_server`), `MultiEnv` (`multi`, MCP servers plus websites and computers; its website browser is the one its `browser_envs` names, none for `[]`, else the run's when it has websites: an MCP server env such as `playwright-mcp` runs among the gateway's MCP servers, and a browser computer such as `chromium` on a sandbox of its own as one more computer child, sized by its `child_envs` entry, its tools under its name and `_`, routing the multi env's synthetic sites unless that entry's `site_routing` says, its network its own env's, as any computer child's; a website env deployed alone refuses a browser computer as the run's browser), `ServiceDBEnv` (`service_db`, PostgreSQL), `WebsiteEnv` (`website`, one site: a server image, `backend_image` in its env.toml, serving the pages and API, ready when its card's `website/v1` `ready` answers a `WebsiteReadiness` that says so, as `agentenv_protocol.website` (`website_readiness`, `env_readiness`) defines a website env's health for the deploy and `DeployedEnv.readiness()` alike, or, for a card without `ready`, when its `health` path answers 200, which is deprecated; its env.toml's `ready_timeout_s`, how long it may take from its server's container starting to ready, is that container's health check `start_period` and what the deploy waits, or its card's `ready` timeout if longer, and its `shm_mb` is the container's `shm_size`, each left to the gateway and Docker without them; the gateway container's `env/gateway/constants.py` mirrors the URI and op, a test keeping them equal; a separate frontend image is deprecated, warned of at put and optional in a bundle, and a stored `backend_docker_image_artifact` reads as the server image; a live one, `live = true`, is a real site whose server serves none of its pages, its `live`, `domains` and `allow_hosts` read at put from its server's `@website(...)` (`utils/card_naming.py` `WebsiteSource`) unless given, its `settings`' secrets only as references the gateway resolves as it writes the site's container (`WEBSITE_SETTINGS_ENV`); the gateway gives it no site route, a computer's site table leaves it out, a computer whose network is an allowlist is let reach its names (`MultiEnv.live_hosts`), a browser alone's forward port takes them straight to the real site (`site_proxy.py` `direct`), as the browser base's stand-in proxy takes any host, refusing nothing, each proxy logging each such connection as a JSON line, and a run that deploys one is marked live, `reproducible: false`), `GatewayEnv` (`gateway_server`), `ComputerDriverEnv` (`computer_driver`, `env/envs/computer/driver_env.py`: a computer driver's files and what its class declares for each platform it supports, read at put in a process of its own, `agentenv_protocol.computer._declare`, where the driver's own dependencies needn't be installed, with the `port` it serves on and its install by OS, `[install.]`, or for one distribution `[install."/"]`, which replaces its OS type's there, as its `known_failures` do (`env/envs/computer/utils/install.py`): files, apt `packages` with extra `sources`, a `python` requirements file for a venv, `downloads` by URL and sha256, `run` scripts, the services the base's init runs, and `ports`; it deploys only as a computer env's driver), `ComputerEnv` (`computer`, in `env/envs/computer/`: a base computer and a driver, matched at put by gate 1 before anything is stored, then composed by `composer.py` into an image for each form and arch on a builder of the put's sandbox provider, by default the env's (`utils/builder.py`; `--sandbox` on `env build`): this machine's Docker for `local`, else a VM of the provider, which fetches the put's stored files by signed URL, takes the rest inline and pushes to the image store itself, so it builds only with stores a remote VM reaches; each arch goes to the first link that runs it natively, else one that emulates it (a VM registers QEMU; `--no-emulate` leaves it `skipped` instead, for a later put), and its pair records the provider that built it (`builder`); a run or register composes only the computer envs its tasks deploy (`materialize._composed_envs`: each env a task's steps name, and each env those hold but a computer env's own apps and driver, which run inside it) and those it pulls in from an installed bundle, whose one write every bundle shares, every one for a plan with no tasks, any other composing at its first deploy; one that reuses a computer env composes what it has left (`pending`), a run, and a register given a `--sandbox`, only the forms its sandbox's deploys boot (`booted_forms`: on each link, the first form it boots natively, by the deploy's own rule, `boot.first_native`; a compose of a disk adds its container), and a deploy composes first what it boots that no compose started, and a container it runs natively that was built but not probed, as one whose probe a setting that didn't resolve stopped, booting it only once ready (`ComputerEnv.compose_unstarted`); tagged `agentenv-computers:` in the image store by a key of the image's Dockerfile, build context and lock so any env with the same inputs reuses it; every layer's packages, requirements and downloads are resolved at put in a container of the base for each arch (`utils/packages.py`, `utils/resolve_in_base.py`), stored in the object store by sha256 under `agentenv-packages/`, and listed in a lock stored by a digest of its inputs, which any env with the same inputs reuses, and builds install only the lock's files, every install step `RUN --network=none`; each pair's status goes into its metadata, `composed`, the arches built are written as its computer, a `computer` artifact over one index, and `agent-env env build` resumes what a put left; gate 3 (`utils/probing.py`) then boots each native build on the put's sandbox provider and probes it at `full`, making it `ready` or `failed`, and a build no provider runs natively stays `unverified`. Its deploy, through the `computer` env provider (`providers/env_providers/env_computer_provider.py`), boots its first `ready` build on a sandbox provider that runs its arch natively (`native_platforms()`), with no gateway in front and the driver's card as the env card, its `/dev/shm` the most its apps' Linux installs ask for (`shm_mb`, in MiB, which its composed computer and the deploy record keep; `--shm-size` on a container, `AGENTENV_SHM_MB` read by a Linux disk's init, passed only to a provider whose `SHARED_MEMORY` says it gives that much, else the sandbox's default, which the deploy logs), then checks its `display`; `deploy_env` `env_params` take a `form`, `computer_settings` (deploy-phase values of the base's settings; a secret one, here or on the env, only as a bare `secret:`/`env:` reference) and `driver_settings` (the driver's `ComputerSettings`, such as its default coordinate space); a `network` that allows nothing runs it on local Docker's internal network behind a relay (`providers/sandbox_providers/local_docker/relay/`); `reset` and `close` have the driver end its recordings first (`computer-recording/v1` `end_all`, each uploading what's left and its manifest under the grant it started with), and `reset` then boots a fresh container in its place (`reset_container`), keeping the computer's address but not an agent's MCP session to the old driver; its `load_file_artifact_universe` writes files under the session user's home through the driver's `data/add`, `Downloads` by default, each file's bytes through a read grant when the store's grants reach it and its network allows everything, else inline (`env/envs/computer/utils/inside.py`)), `ComputerAppEnv` (`computer_app`, `env/envs/computer/app_env.py`: an app on a computer, a `ComputerAppEnvironment` class its env.toml's `module` names, read at put by the same `_declare`, which declares each OS with its own decorator (`@linux(...)`, or `@install(os_type, spec)` for any OS type; `@linux(distribution=...)` or `@install("/", spec)` for one distribution, which replaces its OS type's there) holding its install, its launch and, optionally, a skill and settings and build settings that add to the class's there, and install steps and ready checks for every OS or those their `os=` names; everything that reads its settings, launch or steps asks for the computer's OS type; deployed alone it is a one-app computer env, a `ComputerEnv` of the computer and driver its env.toml names, the composer installing it under `/opt/agentenv/apps//` with its services as supervisord programs beside its own server (`agentenv_protocol.computer.serve_app`, in a venv with the protocol's `app` extra, on `.agentenv/server.sock` in its folder), which adds its launcher, launches a `boot` app once per boot and says through `computer-app/v1` whether it's ready, as the driver's `computer-ready` asks, its card named after it, and `env_params` `app_settings` handing it values of its `Settings` in `AGENTENV_APP_SETTINGS`, a secret one only as a bare reference, over its env.toml's `[settings]` and a computer env's `settings` beside it in `apps`, each by top-level field (`params.app_settings`; checked at put, a required one left to the deploy; the deploy record keeps the merged values as `app_settings`, secrets withheld); its env.toml's `build_settings`, values of its `BuildSettings` checked at put, are written to `.agentenv/build_settings.json` in its folder, so they're part of the image's key, its install steps read them, and a deploy can't change them). An env type whose services take environment data defines `load_environment_artifact` and `load_environment_universe_artifact`; `load_artifact` refuses an environment artifact aimed at a type that doesn't, at save and before it loads. An env built on the protocol SDK can serve agents a skill (`@agent_skill`, `skill/v1`), which `add_skills` `env_ids` installs under its environment name (behind a gateway, each server's under that server's name); a skill with files beside its SKILL.md goes as a bundle stored once per content under `agentenv-env-skills/` in the object store. `env/gateway/gateway.py` is the env-side gateway server, container-only code. Its site route, `/website//`, never forwards a site's data plane or card (`/agentenv/…`, `/.well-known/agent-env.json`), which agentenv reaches through `/svc//`; a site with no frontend image is served by its server image there. A request from a computer's site proxy names its computer (`AgentEnv-Computer`, sent from the proxy's private upstream headers, a page's own copy and any `AgentEnv-Role` it sends dropped) and takes the role driving that computer now (the gateway's computers being those `COMPUTERS` names, a multi env's, with or without a control token): the last to make an input call to its tools, as the call starts, through `/mcp`, `/step` or a trigger action under its `as` (`Gateway._drive`); without one, or from a computer the gateway doesn't front, it is `default`, the role read once per request. `changes/v1` (`ChangeAttribution`) counts no write window for a call to a computer's tools, a trigger action's included, so a write the computer's browser made goes to its request and one another party made during the call to that party. Its CDP route, `/browser//cdp//` (`env/gateway/browser_proxy.py`), reaches the website browser behind the `/svc` child ``, found from that child's card (it, or an app among its children, offering `browser/v1` `cdp` with `/cdp/` in its `computer-app/v1` `agent_routes`): it relays the browser's discovery and WebSocket both ways, each leg pinged every 20 s, and every CDP address the browser hands out, in `json/version`, `json/list` and its `cdp` answer through `/svc//`, comes back at the gateway, everything before `/cdp//` becoming the address the caller reached the gateway at and `/browser/`, keeping the https or wss of an address the browser minted under an origin its caller named, as `browser_connect_cdp` names the agent's, since a tunnel that ends TLS, as Modal's, may send no `X-Forwarded-Proto`; each connection is a `browser_connection` trajectory event, without its token. Its clock (`env/gateway/clock.py`) has one opaque version, a per-boot id and a count, that every `set_time`, `advance` and `clear` changes; `set_rate` (`/clock/set-rate`) changes an armed clock's rate from its time at the write, keeping its `t0` and generation as `advance` does, so time triggers keep their marks. Every clock change goes through `Gateway._change_clock`, which wakes the triggers when the change kept the clock's generation, answers the held watches and waits for the followers. Its followers, the computers on it (`CLOCK_FOLLOWER_TOKENS`, each child whose card serves `clock/v1` `sync_time`, by its read token, its control token for now), long-poll `/clock/watch` naming the version they show, each watch held up to the card's `hold_s` (`env/gateway/clock_followers.py`), and a write given `wait_followers_s` waits for each, answering 504 naming those behind, but not for one that hasn't watched for longer than a hold and a reconnect (`ClockFollowers.QUIET_S`), which it names at once with when each last watched; a restarted gateway is unarmed. While its clock is armed it serves agents `get_time` (`env/gateway/get_time.py`), which answers in UTC and also in the universe's zone, the one `sync_env_clock`'s `timezone` armed it in, or in an IANA `time_zone` it's given; executors' working `hours` (`env/gateway/triggers.py`) take a fixed `utc_offset` or an IANA `time_zone`. | | `artifact/` | Immutable versioned artifacts; every `put()` creates a new version. The document goes to the document store, binary payloads to the object store. Every artifact but an environment universe, whose `metadata` key holds its legacy metadata file ids, carries a `metadata` dict outside its versioned fields, changed by compare-and-swap (`merge_metadata`). Built-ins: `CliArtifact` (`cli`), `ComputerArtifact` (`computer`, a base computer: its architectures, OS, session user, settings and container form, whose image `put` reads from its registry into `metadata.validated_images`), `FileArtifact` (`file`), `FileArtifactUniverse` (`file_artifact_universe`), `DockerImageArtifact` (`docker_image`), `EnvironmentArtifact` (`environment`: its environment's files by path, stored as the one wrapped `file_artifact_ref` every environment artifact had when it has one file at its filename, else as `file_artifact_refs`; `get_file_artifacts()` reads either, and a load hands each file to the env's `data/add` with its path, which a pre-v1 load, taking one file, refuses), `EnvironmentUniverseArtifact` (`environment_universe`), `SkillArtifact` (`skill`); `[artifacts] type_aliases` maps another stored spelling of a type onto one of them. A `DockerImageArtifact` holds a tar.gz of its image, or, written by `put_ref` (`--image-ref` on `env mcp-server put` and `a2a-agent put`), only a registry reference with its tag pinned to a digest, which sandboxes pull, or a published image's tag with its `image_digest` and its build context, which sandboxes pull by the digest and build from the context when they can't (the infra images, and a bundle agent built from a shipped agent's sources, `Plan.published`), or, written by `put_context`, only its build context, which a VM sandbox builds before running it (`VmSandbox.load_docker_images`) and Modal builds before creating its container (`ModalSandboxProvider.prepare_image`, outside a fallback chain's deadline); anything else that runs images by name (a container on the local provider, a lone server on any provider but Modal) refuses such an image. A build context (`utils/docker/context.py`) is what `docker build` would send, `.dockerignore` applied, written so equal files give equal bytes and an equal `source_digest`. | -| `task/`, `task_step/` | A `Task` holds its `TaskStep`s inline; `Task.run()` executes them as a DAG. Its `headline_verifiers`, step ids saved only when set, name the grades that are its reward: one is the reward, several a multi-reward over them, none a multi-reward over every grade; it refuses one that names no step of the task, or one named twice. `depends_on` (None means all prior steps) gates a step, independent steps run concurrently, `fail_task_on_error` makes a failure fatal or tolerated, `retry_config` rolls a failed span back through the step journal and re-dispatches it. `task/lint.py` is `agent-env task lint` (a bundle folder, a task file or a stored task): an error is what a task gets wrong before it runs (a field its step doesn't read, a step's own `config_problems`, a headline that grades nothing, an aggregate source no verifier writes) and refuses `agent-env run`, `bundle register`, `task create`, `task validate` and `eval run`, and the bundle plans `openenv`'s `build_app` and the trainers make (`run`, `register`, `build_app`, `prepare_bundle` and the trainers take `--skip-lint`/`skip_lint`, which lifts lint's own rules but not a step's `config_problems`, which refused a bundle before lint; `eval run`'s lifts every error, since it checked none before); a warning is what may be wrong (a step's `config_warnings`, a store entity read with no version, no verifier, several and no headline) and is only printed, each kind once by a run (`task.lint.said`), an eval run's unpinned references as one count (`unpinned_summary`), every one by `task lint`. `aggregate_verifiers` names its sources by step id (`sources`, `gates`) and reads their named grades: `combine` `pooled` (the default) pools their rows, `weighted_mean` weighs their scores, equally unless `weights` gives every source one, and a failing gate scores it 0; a failed or missing source fails it, and its older `verifier_ids` pools legacy entries as it always has. Built-in steps live in `task_step/task_steps/` (`deploy_env`, `deploy_agent`, `prompt_agent`, the verifiers under `verifiers/`, among them `start_computer_recording` (its driver draws each input over the frames in its caller's colour, and a pointer per role where the frames lack one, unless `annotation_settings` says `is_enabled: false`; a driver whose card lists no `annotate` records it plain, with a warning, and the run's recording entry says `annotated`) and `end_computer_recording`, `start_browser_recording` and `end_browser_recording` (`browser-recording/v1`: one recording per context, a lease's or the default one's, with a video of the tab its agent is on, its context's log, the browser's network log as HAR and opt-in frames keyed to the action log, the contexts its agents make recorded with it, one universe per recording, anything missing failing the run), and more). Every built-in verifier is on the `VerifierTaskStep` base (`verifiers/verifier.py`): it implements `verify` and returns a `Verification`, and the base writes the step's named grade to `context.metadata["grades"][]` (score, `min_passing_score`, `passed`, `verifier_status` graded, skipped or failed, criteria rows, type, version, and `verifier_settings`, the values the run graded with, its overrides applied and named in `overridden`, with `scoring_rules`) beside the legacy `verifications` entries every reader still takes; an exception from `verify` or a `Verification` with an `error`, as a timed-out `run_container_unit_tests_verifier`, is a failed grade, and `rubrics_verifier` still writes its `-trajectory-mistakes` entry itself. On an env whose card serves computer-exec/v1 (a computer), `run_code` with `env_id` and `run_container_unit_tests_verifier` with `env_id` run inside it as its session user through the driver: files staged with `data/add` and read with `data/get`, commands run with `run`; `computer_exec` runs one command there through `run` (a program and its arguments, or a string through `sh -c`; in a multi env, the computer it names), recorded under `computer_exec` in the run's metadata, a non-zero exit or a timeout failing it unless `check` is off, or with `background` starts it and leaves it running, as an app launched for the agent, a program that isn't there exiting 127; with `scope: "system"` it runs as root instead, through the computer's sandbox (`RootChannel`, `docker exec -u 0`), in the session user's folder and `HOME`, its output capped in the computer, never with `background` and not on a computer booted from a disk; on a Windows computer, which has no `sh`, a string or `background` command is refused; on a multi env, `load_artifact` with `env_id` puts an environment artifact named after one of its computers, or after an app of one, into that computer, the computer's own as files at their paths under the session user's home; `env_outcome_verifier` hands a `verify` that takes an `env_url` keyword the env's address. A computer's framework-only routes (everything but MCP and the card) take the per-deploy control token its provider boots it with (`DeployedEnv.control_token`, `AGENTENV_CONTROL_TOKEN`), a multi env's computers the multi env's own, which its gateway passes on only on their `/svc` routes and its clock watch (`CONTROL_TOKEN_CHILDREN`); framework calls send `deployed.control_headers`, `Task.run` runs every step under `protocol_v1.authorized` with each deployed env's (a `verify` included), and a `run_code` script inside the computer gets `input["env"]["headers"]`. `teardown_run` and the `teardown_sandboxes` step share one core (`task/teardown.py` `tear_down`): the recordings the run left open end with fresh grants, each env still up closes (`Env.close`; a computer env ends any recording still open), what stayed open is registered from its namespace, then every sandbox is terminated by id. A run whose teardown leaves sandboxes up, stopped by a second signal or failing, keeps on its instance the context it ended with (`record_teardown`), and `agent-env run` and `task run --keep` name `agent-env task teardown --instance `, which tears down what that context still records up, a running one only with `--force`. `task/episode/` runs a task with some of its agents played from outside, as a training loop does (`EpisodeSpec`). | +| `task/`, `task_step/` | A `Task` holds its `TaskStep`s inline; `Task.run()` executes them as a DAG. Its `headline_verifiers`, step ids saved only when set, name the grades that are its reward: one is the reward, several a multi-reward over them, none a multi-reward over every grade; it refuses one that names no step of the task, or one named twice. `depends_on` (None means all prior steps) gates a step, independent steps run concurrently, `fail_task_on_error` makes a failure fatal or tolerated, `retry_config` rolls a failed span back through the step journal and re-dispatches it. `task/lint.py` is `agent-env task lint` (a bundle folder, a task file or a stored task): an error is what a task gets wrong before it runs (a field its step doesn't read, a step's own `config_problems`, a headline that grades nothing, an aggregate source no verifier writes, a judge that runs in the solver's own agent) and refuses `agent-env run`, `bundle register`, `task create`, `task validate` and `eval run`, and the bundle plans `openenv`'s `build_app` and the trainers make (`run`, `register`, `build_app`, `prepare_bundle` and the trainers take `--skip-lint`/`skip_lint`, which lifts lint's own rules but not a step's `config_problems`, which refused a bundle before lint; `eval run`'s lifts every error, since it checked none before); a warning is what may be wrong (a step's `config_warnings`, a store entity read with no version, no verifier, several and no headline) and is only printed, each kind once by a run (`task.lint.said`), an eval run's unpinned references as one count (`unpinned_summary`), every one by `task lint`. `aggregate_verifiers` names its sources by step id (`sources`, `gates`) and reads their named grades: `combine` `pooled` (the default) pools their rows, `weighted_mean` weighs their scores, equally unless `weights` gives every source one, and a failing gate scores it 0; a failed or missing source fails it, and its older `verifier_ids` pools legacy entries as it always has. Built-in steps live in `task_step/task_steps/` (`deploy_env`, `deploy_agent`, `prompt_agent`, the verifiers under `verifiers/`, among them `start_computer_recording` (its driver draws each input over the frames in its caller's colour, and a pointer per role where the frames lack one, unless `annotation_settings` says `is_enabled: false`; a driver whose card lists no `annotate` records it plain, with a warning, and the run's recording entry says `annotated`) and `end_computer_recording`, `start_browser_recording` and `end_browser_recording` (`browser-recording/v1`: one recording per context, a lease's or the default one's, with a video of the tab its agent is on, its context's log, the browser's network log as HAR and opt-in frames keyed to the action log, the contexts its agents make recorded with it, one universe per recording, anything missing failing the run), and more). Every built-in verifier is on the `VerifierTaskStep` base (`verifiers/verifier.py`): it implements `verify` and returns a `Verification`, and the base writes the step's named grade to `context.metadata["grades"][]` (score, `min_passing_score`, `passed`, `verifier_status` graded, skipped or failed, criteria rows, type, version, and `verifier_settings`, the values the run graded with, its overrides applied and named in `overridden`, with `scoring_rules`) beside the legacy `verifications` entries every reader still takes; an exception from `verify` or a `Verification` with an `error`, as a timed-out `run_container_unit_tests_verifier`, is a failed grade, and `rubrics_verifier` still writes its `-trajectory-mistakes` entry itself. On an env whose card serves computer-exec/v1 (a computer), `run_code` with `env_id` and `run_container_unit_tests_verifier` with `env_id` run inside it as its session user through the driver: files staged with `data/add` and read with `data/get`, commands run with `run`; `computer_exec` runs one command there through `run` (a program and its arguments, or a string through `sh -c`; in a multi env, the computer it names), recorded under `computer_exec` in the run's metadata, a non-zero exit or a timeout failing it unless `check` is off, or with `background` starts it and leaves it running, as an app launched for the agent, a program that isn't there exiting 127; with `scope: "system"` it runs as root instead, through the computer's sandbox (`RootChannel`, `docker exec -u 0`), in the session user's folder and `HOME`, its output capped in the computer, never with `background` and not on a computer booted from a disk; on a Windows computer, which has no `sh`, a string or `background` command is refused; on a multi env, `load_artifact` with `env_id` puts an environment artifact named after one of its computers, or after an app of one, into that computer, the computer's own as files at their paths under the session user's home; `env_outcome_verifier` hands a `verify` that takes an `env_url` keyword the env's address. A computer's framework-only routes (everything but MCP and the card) take the per-deploy control token its provider boots it with (`DeployedEnv.control_token`, `AGENTENV_CONTROL_TOKEN`), a multi env's computers the multi env's own, which its gateway passes on only on their `/svc` routes and its clock watch (`CONTROL_TOKEN_CHILDREN`); framework calls send `deployed.control_headers`, `Task.run` runs every step under `protocol_v1.authorized` with each deployed env's (a `verify` included), and a `run_code` script inside the computer gets `input["env"]["headers"]`. `teardown_run` and the `teardown_sandboxes` step share one core (`task/teardown.py` `tear_down`): the recordings the run left open end with fresh grants, each env still up closes (`Env.close`; a computer env ends any recording still open), what stayed open is registered from its namespace, then every sandbox is terminated by id. A run whose teardown leaves sandboxes up, stopped by a second signal or failing, keeps on its instance the context it ended with (`record_teardown`), and `agent-env run` and `task run --keep` name `agent-env task teardown --instance `, which tears down what that context still records up, a running one only with `--force`. `task/episode/` runs a task with some of its agents played from outside, as a training loop does (`EpisodeSpec`). | | `store/` | Four store ABCs with local and cloud implementations: `DocumentStore` (SQLite, MongoDB, DynamoDB, Firestore with MongoDB compatibility), `ObjectStore` (filesystem, S3, Cloud Storage), `ImageStore` (local OCI registry, ECR), `SecretStore` (env vars or file, AWS Secrets Manager, Google Cloud Secret Manager). `VersionedEntityStore` implements the shared versioned get/put logic, `QueryBuilder` is the immutable chained query API, `store/base.py` holds the error types. `store/routing.py` is the local namespaces, `@local` and `@hf` (`is_local_id`), each with a documents file of its own: while the CLI or a `build_app` server runs, a local id and what a local task's run records go to local stores beside the configured ones, and that run's writes to the configured stores are refused. A new backend must pass the conformance kits in `tst/store/`. | | `config/` | The `Config` singleton (`get_config`, `configure`, `reset_config`) in `config/runtime.py`, file discovery in `config/loader.py`, and `load_impl`, which resolves `module:Class` pointers. `agent_env.store` re-exports the config names for compatibility. | | `providers/` | `providers/sandbox_providers/` holds the sandbox providers `local`, `modal`, `modal_vm`, `e2b`, `sail_vm` (the `sail` extra), `smol_vm` (the `smol` extra), `tensorlake` (the `tensorlake` extra), `tenki` (the `tenki` extra), `vercel` (the `vercel` extra), `boxd` (the `boxd` extra), `coreweave` (the `coreweave` extra), `daytona` (the `daytona` extra), `boat` (the `boat` extra), `agent37` (no extra), `kosa8` (no extra); `[sandbox] default` and `agent_default` accept a comma-separated fallback chain, whose deploys skip a provider that can't run them. A sandbox provider declares what it runs (`ON_THIS_MACHINE`, and for VMs on this machine the address their requests to it arrive at, `REACHES_HOST_AT`; `CONTAINER_ACCEPTS`, `PRIVATE_NETWORK`, `WEBSOCKETS`; `SUPPORTED_SANDBOX_MODES`, derived from whether it implements `create_sandbox` and `create_vm`; and `SANDBOX_ACCEPTS`, the images an agent's sandbox runs, which defaults to those a VM loads when it implements `create_vm` and to `CONTAINER_ACCEPTS` otherwise, so only a provider that implements `create_vm` yet gives an agent a container, like the local one, declares it), each sandbox carries the `platform` of the images it runs (linux/amd64 unless its provider sets another when it creates it; None, any, unchecked, for a local sandbox), and code outside `providers/sandbox_providers/` reads those, never which provider it has. `providers/env_providers/` holds the environment providers: `EnvironmentProvider` (an env's containers and state store), `EnvironmentGatewayProvider` (`gateway`, an env's default), which renders a docker-compose for the gateway and its MCP servers inside the sandbox, and `EnvironmentServerProvider` (`server`), one MCP server in its own container with no gateway in front and no state store; `providers/env_state/` holds env-state providers (`local_postgres` built in). | diff --git a/src/agent_env/bundle/plan.py b/src/agent_env/bundle/plan.py index 57d5f29e2..3ccc16ac9 100644 --- a/src/agent_env/bundle/plan.py +++ b/src/agent_env/bundle/plan.py @@ -64,7 +64,7 @@ from agent_env.task_step.task_steps.deploy_agent import DeployAgentTaskStep from agent_env.task_step.task_steps.install_agent import InstallAgentTaskStep from agent_env.task_step.task_steps.load_artifact import LoadArtifactTaskStep -from agent_env.task_step.task_steps.prompt_agent import is_prompt_step, user_sim_agents +from agent_env.task_step.task_steps.prompt_agent import solver_agents from ._fs import fold, relative, with_article from .authoring import AuthoringContext, entry_files, staged_build_context @@ -1266,12 +1266,11 @@ def folder_files(bundle: Bundle, entry: BundleEntry) -> Mapping[str, Path]: def solver_steps(steps: Any) -> tuple[str, ...]: """The ids of the steps in ``steps``, a task's config, that deploy or install an agent a step prompts as the agent - under test (``is_prompt_step``), and not as its user simulator: the solver's.""" - prompts = [step for step in steps if isinstance(step, dict) and is_prompt_step(step)] - prompted = {step.get("agent_name") or TaskStep.DEFAULT_AGENT_NAME for step in prompts} - user_sim_agents(steps) + under test, and not as its user simulator: the solver's (``solver_agents``).""" + solver = solver_agents([step for step in steps if isinstance(step, dict)]) return tuple(step["id"] for step in steps if isinstance(step, dict) and isinstance(step.get("id"), str) and step.get("type") in (DeployAgentTaskStep.type, InstallAgentTaskStep.type) - and (step.get("agent_name") or TaskStep.DEFAULT_AGENT_NAME) in prompted) + and (step.get("agent_name") or TaskStep.DEFAULT_AGENT_NAME) in solver) def _leaves_an_agent_unset(task: ResolvedEntry) -> bool: diff --git a/src/agent_env/task/lint.py b/src/agent_env/task/lint.py index 1120359c1..615556540 100644 --- a/src/agent_env/task/lint.py +++ b/src/agent_env/task/lint.py @@ -15,11 +15,13 @@ from agent_env.task.task import Task, _ancestor_ids, _dependency_ids from agent_env.task_step.registry import get_task_step_registry from agent_env.task_step.task_step import StepRole, TaskStep, attach_base_fields +from agent_env.task_step.task_steps.prompt_agent import solver_agents from agent_env.task_step.task_steps.verifiers.aggregate_verifiers import ( POOLED, AggregateVerifiersTaskStep, legacy_entry_writers, ) +from agent_env.task_step.task_steps.verifiers.rubrics_verifier import RubricsVerifierTaskStep from agent_env.task_step.task_steps.verifiers.scoring import ScoreAggregator from agent_env.task_step.task_steps.verifiers.verifier import VerifierTaskStep @@ -59,6 +61,7 @@ def lint(task: Task, step_dicts: Sequence[Mapping[str, Any]] | None = None, *, c *_step_warnings(task.steps), *_headlines(task), *_aggregate_sources(task.steps), + *_judge_as_solver(task.steps), *_lopsided(task.steps), *(_unpinned(task.steps) if unpinned else ()), *_coverage(task), @@ -274,6 +277,21 @@ def _named_sources(aggregate: AggregateVerifiersTaskStep, steps: Sequence[TaskSt yield Finding(Severity.ERROR, "aggregate-source", f"{field} names {name!r}, {problem}", aggregate.id) +def judges_in_solver(steps: Sequence[TaskStep]) -> list[RubricsVerifierTaskStep]: + """The agent judges that run in the solver's own agent: their ``agent_name`` names an agent a step prompts as the + agent under test (``solver_agents``), so the solver grades its own work.""" + solver = solver_agents(steps) + return [step for step in steps if isinstance(step, RubricsVerifierTaskStep) and step.use_agent_judge + and isinstance(step.agent_name, str) and step.agent_name in solver] + + +def _judge_as_solver(steps: Sequence[TaskStep]) -> Iterator[Finding]: + for judge in judges_in_solver(steps): + yield Finding(Severity.ERROR, "judge-as-solver", + f"its judge runs in {judge.agent_name!r}, the agent under test, so the solver grades its own work; " + "leave agent_name unset for a judge agent of its own, or name another agent", judge.id) + + def _lopsided(steps: Sequence[TaskStep]) -> Iterator[Finding]: """A pooled, weighted-average aggregate one of whose sources is under ``LOPSIDED_SHARE`` of its rows, so it barely moves the score, counting only the sources whose rows their config says (``criterion_rows``). An aggregate of diff --git a/src/agent_env/task_step/task_steps/prompt_agent.py b/src/agent_env/task_step/task_steps/prompt_agent.py index 513530368..5ba1ad3f3 100644 --- a/src/agent_env/task_step/task_steps/prompt_agent.py +++ b/src/agent_env/task_step/task_steps/prompt_agent.py @@ -1536,9 +1536,20 @@ def is_prompt_step(step: Any) -> bool: def user_sim_agents(steps: Any) -> set[str]: """The agents a task's prompting steps talk to as their user: an always_on step's ``user_sim``, a prompt_agent - step's ``user_agent_name`` (its default when unset). ``steps`` are steps or step dicts.""" - def field(step: Any, name: str) -> Any: - return step.get(name) if isinstance(step, dict) else getattr(step, name, None) + step's ``user_agent_name`` (its default when unset). ``steps`` are steps or step dicts; a name that isn't a string + names no agent.""" + return {name for step in steps if is_prompt_step(step) + if isinstance(name := _field(step, "user_sim") or _field(step, "user_agent_name") + or PromptAgentTaskStep.DEFAULT_USER_AGENT_NAME, str)} - return {field(step, "user_sim") or field(step, "user_agent_name") or PromptAgentTaskStep.DEFAULT_USER_AGENT_NAME - for step in steps if is_prompt_step(step)} + +def solver_agents(steps: Any) -> set[str]: + """The agents a task's prompting steps talk to as the agent under test, not as its user (``user_sim_agents``): the + solver's. ``steps`` are steps or step dicts; a name that isn't a string names no agent.""" + prompted = {name for step in steps if is_prompt_step(step) + if isinstance(name := _field(step, "agent_name") or PromptAgentTaskStep.DEFAULT_AGENT_NAME, str)} + return prompted - user_sim_agents(steps) + + +def _field(step: Any, name: str) -> Any: + return step.get(name) if isinstance(step, dict) else getattr(step, name, None) diff --git a/src/agent_env/training/harness.py b/src/agent_env/training/harness.py index aecd0754f..2f325d0f5 100644 --- a/src/agent_env/training/harness.py +++ b/src/agent_env/training/harness.py @@ -32,13 +32,13 @@ from agent_env.bundle.run import planned_tasks, prepare_bundle, solver_params from agent_env.store.routing import namespace_routing from agent_env.openenv.reward import reward_of +from agent_env.task.lint import judges_in_solver from agent_env.task.task import Task, recorded_scores from agent_env.task.teardown import teardown_run from agent_env.task_step.context import TaskStepContext, sandbox_overrides from agent_env.task_step.task_steps.agent.user_sim_common import opening_parts, opening_text from agent_env.task_step.task_steps.deploy_agent import DeployAgentTaskStep from agent_env.task_step.task_steps.prompt_agent import is_prompt_step, user_sim_agents -from agent_env.task_step.task_steps.verifiers.rubrics_verifier import RubricsVerifierTaskStep from agent_env.training._openenv import on_session_loop logger = logging.getLogger(__name__) @@ -210,9 +210,7 @@ def _untrainable(config: list[dict[str, Any]]) -> str | None: deploys = [step for step in steps if step.id in solver] if not deploys or not all(isinstance(step, DeployAgentTaskStep) for step in deploys): return "training needs the agent a step prompts deployed by a deploy_agent step" - agents = {step.agent_name for step in deploys} - if any(isinstance(step, RubricsVerifierTaskStep) and step.use_agent_judge and step.agent_name in agents - for step in steps): + if judges_in_solver(steps): return "its rubric judge is its solver, whose grading would be trained on" return None diff --git a/tst/unit/task/lint_test.py b/tst/unit/task/lint_test.py index 1a9a2bf57..ca333d4b9 100644 --- a/tst/unit/task/lint_test.py +++ b/tst/unit/task/lint_test.py @@ -321,6 +321,46 @@ def test_sources_given_as_objects_are_a_config_error_not_a_crash(sources): assert ("error", "step-config", f"step 'final': sources must be a list of step ids, not {sources!r}") in found +SOLVER = {"id": "solver", "type": "deploy_agent", "agent_name": "default-agent"} +JUDGE_AGENT = {"id": "judge-agent", "type": "deploy_agent", "agent_name": "judge"} +ASK = {"id": "ask", "type": "prompt_agent", "prompt": "Help Linda.", "prompt_id": "ask", "user_agent_name": "linda"} +VERIFY = {"id": "verify", "type": "rubrics_verifier", "prompt_id": "ask", "verifier_id": "verify", + "criteria": [{"criterion": "helps"}]} + + +def _judging(**fields) -> list[tuple[str, str, str]]: + found = _found(_task(SOLVER, JUDGE_AGENT, ASK, {**VERIFY, **fields}, headline_verifiers=["verify"])) + return [finding for finding in found if finding[1] == "judge-as-solver"] + + +def test_an_agent_judge_in_the_agent_under_test_is_an_error(): + assert _judging(agent_name="default-agent") == [( + "error", "judge-as-solver", "step 'verify': its judge runs in 'default-agent', the agent under test, so the " + "solver grades its own work; leave agent_name unset for a judge agent of its own, " + "or name another agent")] + + +@pytest.mark.parametrize("fields", [ + {}, + {"agent_name": "judge"}, + {"agent_name": "linda"}, + {"agent_name": "default-agent", "use_agent_judge": False}, +]) +def test_a_judge_of_its_own_in_the_user_simulator_or_calling_its_model_directly_is_not_the_solver(fields): + assert _judging(**fields) == [] + + +@pytest.mark.parametrize(("ask", "judge"), [ + ({}, {"agent_name": ["default-agent"]}), + ({"agent_name": ["default-agent"]}, {"agent_name": "default-agent"}), + ({"user_agent_name": {}}, {"agent_name": {}}), +]) +def test_an_agent_name_that_isnt_a_string_names_no_agent_and_lint_still_answers(ask, judge): + task = _task(SOLVER, {**ASK, **ask}, {**VERIFY, **judge}, headline_verifiers=["verify"]) + + assert not [finding for finding in lint(task) if finding.rule == "judge-as-solver"] + + def test_with_no_headline_an_aggregate_naming_every_other_verifier_by_step_id_is_the_one_to_name(): found = _found(_task(BOX, TESTS, MORE, _combined(combine="weighted_mean", sources=["tests"], gates=["more"]))) @@ -573,6 +613,19 @@ def test_a_run_of_a_bundle_with_a_lint_error_is_refused_unless_it_skips_lint_but assert "--skip-lint" not in config.output +def test_a_run_of_a_bundle_whose_judge_is_its_solver_is_refused_unless_it_skips_lint(bundle_dir): + _write(bundle_dir, "j", {"headline_verifiers": ["verify"], + "steps": [SOLVER, ASK, {**VERIFY, "agent_name": "default-agent"}]}) + + refused = CliRunner().invoke(cli, ["run", str(bundle_dir), "--task", "j", "--dry-run"]) + skipped = CliRunner().invoke(cli, ["run", str(bundle_dir), "--task", "j", "--dry-run", "--skip-lint"]) + + assert refused.exit_code != 0 + assert "tasks/j.json: step 'verify': its judge runs in 'default-agent', the agent under test" in refused.output + assert skipped.exit_code == 0, skipped.output + assert "Would run:\n tasks/j.json v1\n" in skipped.output + + def test_bundle_register_with_skip_lint_registers_a_task_lint_refuses_saying_why_once(bundle_dir): _write(bundle_dir, "t", {"headline_verifiers": ["box"], "steps": [BOX, TESTS]}) diff --git a/tst/unit/task_step/verifiers/test_rubrics_family_grades.py b/tst/unit/task_step/verifiers/test_rubrics_family_grades.py index 95a609510..d15c7a3dd 100644 --- a/tst/unit/task_step/verifiers/test_rubrics_family_grades.py +++ b/tst/unit/task_step/verifiers/test_rubrics_family_grades.py @@ -10,7 +10,7 @@ from agent_env.config import get_config from agent_env.task_step.context import TaskStepContext, VerifierNotPassingError from agent_env.task_step.task_steps.verifiers.always_on_agent_verifier import AlwaysOnAgentVerifier -from agent_env.task_step.task_steps.verifiers.rubrics_verifier import RubricsVerifierTaskStep +from agent_env.task_step.task_steps.verifiers.rubrics_verifier import JudgeTimeoutError, RubricsVerifierTaskStep from agent_env.task_step.task_steps.verifiers.user_sim_judge import UserSimJudge from tst.unit.task_step.verifiers.test_rubrics_verifier_golden import ( CASES, @@ -178,6 +178,35 @@ def test_the_user_sim_judges_settings_leave_out_what_its_judge_never_uses(): assert settings["overridden"] == ["judge_batch_size", "judge_batch_concurrency", "judge_model"] +@pytest.mark.asyncio +async def test_a_direct_judge_out_of_retries_writes_a_failed_grade(): + step, context = CASES["a_judge_that_cannot_be_reached"]() + + with pytest.raises(RuntimeError, match="LLM judge failed after 3 attempts"): + await step.execute(context) + + grade = context.metadata["grades"][step.id] + assert (grade["verifier_status"], grade["score"], grade["passed"]) == ("failed", None, False) + assert grade["verifier_error_reasoning"] == "RuntimeError: LLM judge failed after 3 attempts" + + +@pytest.mark.asyncio +async def test_an_agent_judge_out_of_timeout_retries_writes_a_failed_grade(): + step, context = CASES["an_agent_judge_timing_out_once"]() + + async def times_out(**_): + raise JudgeTimeoutError("ran out", "mem://judge/timed-out.json") + + step._invoke_judge_a2a = times_out + + with pytest.raises(JudgeTimeoutError): + await step.execute(context) + + grade = context.metadata["grades"][step.id] + assert (grade["verifier_status"], grade["score"]) == ("failed", None) + assert grade["verifier_error_reasoning"].startswith("JudgeTimeoutError: ran out") + + @pytest.mark.asyncio async def test_an_always_on_verifier_refusing_a_runs_overrides_fails_its_grade_and_writes_no_entry(): step = AlwaysOnAgentVerifier(id="judge", version=1, criteria=_criteria(1), prompt_id="ask", use_agent_judge=False, From 0cfa698ca37f765eb143aaaf8d0a78a4495b035b Mon Sep 17 00:00:00 2001 From: Edgar Arakelyan Date: Sun, 22 Nov 2026 21:48:16 -0800 Subject: [PATCH 2/2] refactor(bundle): played_deploys and the training harness read solver_agents, and one agent_name_of names a step's agent played_deploys was a fourth copy of the solver's agents, and the harness's first-prompt pick a fifth; both now read solver_agents. agent_name_of is the one fallback to the default agent's name, for solver_agents, solver_steps, played_deploys and the harness. Co-Authored-By: Claude Opus 5.5 --- src/agent_env/bundle/plan.py | 4 ++-- src/agent_env/bundle/resolve.py | 17 ++++++----------- .../task_step/task_steps/prompt_agent.py | 8 ++++++-- src/agent_env/training/harness.py | 6 +++--- 4 files changed, 17 insertions(+), 18 deletions(-) diff --git a/src/agent_env/bundle/plan.py b/src/agent_env/bundle/plan.py index 3ccc16ac9..a4cbdcad5 100644 --- a/src/agent_env/bundle/plan.py +++ b/src/agent_env/bundle/plan.py @@ -64,7 +64,7 @@ from agent_env.task_step.task_steps.deploy_agent import DeployAgentTaskStep from agent_env.task_step.task_steps.install_agent import InstallAgentTaskStep from agent_env.task_step.task_steps.load_artifact import LoadArtifactTaskStep -from agent_env.task_step.task_steps.prompt_agent import solver_agents +from agent_env.task_step.task_steps.prompt_agent import agent_name_of, solver_agents from ._fs import fold, relative, with_article from .authoring import AuthoringContext, entry_files, staged_build_context @@ -1270,7 +1270,7 @@ def solver_steps(steps: Any) -> tuple[str, ...]: solver = solver_agents([step for step in steps if isinstance(step, dict)]) return tuple(step["id"] for step in steps if isinstance(step, dict) and isinstance(step.get("id"), str) and step.get("type") in (DeployAgentTaskStep.type, InstallAgentTaskStep.type) - and (step.get("agent_name") or TaskStep.DEFAULT_AGENT_NAME) in solver) + and agent_name_of(step) in solver) def _leaves_an_agent_unset(task: ResolvedEntry) -> bool: diff --git a/src/agent_env/bundle/resolve.py b/src/agent_env/bundle/resolve.py index 4a5fa6ea8..d04e339e9 100644 --- a/src/agent_env/bundle/resolve.py +++ b/src/agent_env/bundle/resolve.py @@ -35,7 +35,7 @@ from agent_env.task_step.context import ENV_KEYED_METADATA, context_path, context_path_segments from agent_env.task_step.registry import get_task_step_registry from agent_env.task_step.task_step import TaskStep, attach_base_fields, dependencies -from agent_env.task_step.task_steps.prompt_agent import is_prompt_step, user_sim_agents +from agent_env.task_step.task_steps.prompt_agent import agent_name_of, solver_agents from ._fs import fold, relative, show from .authoring import AuthoringContext, default_dockerfile @@ -133,16 +133,15 @@ def resolve_bundle(bundle: Bundle) -> ResolvedBundle: def played_deploys(entry: ResolvedEntry) -> frozenset[str]: - """The ``deploy_agent`` steps of a task's only agent under test, the one a step prompts as it and no step talks to - as its user (``user_sim_agents``), which a caller playing that agent itself (``EpisodeSpec``) stands in for; none - when the entry isn't a task, or prompts no agent or several.""" + """The ``deploy_agent`` steps of a task's only agent under test (``solver_agents``), which a caller playing that + agent itself (``EpisodeSpec``) stands in for; none when the entry isn't a task, or prompts no agent or several.""" if entry.entry.kind is not BundleKind.TASK: return frozenset() - prompted = {_agent_name(step) for step in entry.config if is_prompt_step(step)} - user_sim_agents(entry.config) - if len(prompted) != 1: + solver = solver_agents(entry.config) + if len(solver) != 1: return frozenset() return frozenset(step.get("id") for step in entry.config - if step.get("type") == "deploy_agent" and _agent_name(step) in prompted) + if step.get("type") == "deploy_agent" and agent_name_of(step) in solver) def without_played_agents(resolved: ResolvedBundle) -> ResolvedBundle: @@ -158,10 +157,6 @@ def kept(entry: ResolvedEntry) -> ResolvedEntry: return replace(resolved, entries=tuple(kept(entry) for entry in resolved.entries)) -def _agent_name(step: dict) -> str: - return step.get("agent_name") or TaskStep.DEFAULT_AGENT_NAME - - class _Skip(Exception): """An entry that can't be resolved; its problem is already recorded.""" diff --git a/src/agent_env/task_step/task_steps/prompt_agent.py b/src/agent_env/task_step/task_steps/prompt_agent.py index 5ba1ad3f3..84c17be3a 100644 --- a/src/agent_env/task_step/task_steps/prompt_agent.py +++ b/src/agent_env/task_step/task_steps/prompt_agent.py @@ -1546,10 +1546,14 @@ def user_sim_agents(steps: Any) -> set[str]: def solver_agents(steps: Any) -> set[str]: """The agents a task's prompting steps talk to as the agent under test, not as its user (``user_sim_agents``): the solver's. ``steps`` are steps or step dicts; a name that isn't a string names no agent.""" - prompted = {name for step in steps if is_prompt_step(step) - if isinstance(name := _field(step, "agent_name") or PromptAgentTaskStep.DEFAULT_AGENT_NAME, str)} + prompted = {name for step in steps if is_prompt_step(step) if isinstance(name := agent_name_of(step), str)} return prompted - user_sim_agents(steps) +def agent_name_of(step: Any) -> Any: + """The agent ``step``, a step or a step dict, names: its ``agent_name``, else the default agent's name.""" + return _field(step, "agent_name") or PromptAgentTaskStep.DEFAULT_AGENT_NAME + + def _field(step: Any, name: str) -> Any: return step.get(name) if isinstance(step, dict) else getattr(step, name, None) diff --git a/src/agent_env/training/harness.py b/src/agent_env/training/harness.py index 2f325d0f5..89b927c69 100644 --- a/src/agent_env/training/harness.py +++ b/src/agent_env/training/harness.py @@ -38,7 +38,7 @@ from agent_env.task_step.context import TaskStepContext, sandbox_overrides from agent_env.task_step.task_steps.agent.user_sim_common import opening_parts, opening_text from agent_env.task_step.task_steps.deploy_agent import DeployAgentTaskStep -from agent_env.task_step.task_steps.prompt_agent import is_prompt_step, user_sim_agents +from agent_env.task_step.task_steps.prompt_agent import agent_name_of, is_prompt_step, solver_agents from agent_env.training._openenv import on_session_loop logger = logging.getLogger(__name__) @@ -238,9 +238,9 @@ def _first_prompt(task: Task) -> str: names (an always_on step's ``user_sim``, a prompt_agent step's ``user_agent_name``), as it was written (its text, for an opening with files). A step that prompts an agent another step talks to as its user (the user sim, say a briefing) isn't the agent under test's.""" - users = user_sim_agents(task.steps) + solver = solver_agents(task.steps) step = next((each for each in task.steps - if is_prompt_step(each) and getattr(each, "agent_name", None) not in users), None) + if is_prompt_step(each) and agent_name_of(each) in solver), None) if step is None: return "" if getattr(step, "prompt", None):