Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
14 commits
Select commit Hold shift + click to select a range
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
2 changes: 1 addition & 1 deletion AGENTS.md

Large diffs are not rendered by default.

37 changes: 28 additions & 9 deletions src/agent_env/bundle/run.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,14 @@
from dataclasses import dataclass, replace
from enum import Enum
from pathlib import Path
from typing import Any

from agent_env.artifact.artifacts.docker_image import DockerImageArtifact
from agent_env.env.bootstrap import InfraSetup, ensure_default_envs
from agent_env.env.envs.computer.utils.composer import Composing
from agent_env.providers import build_sandbox_provider
from agent_env.task_step.task_steps.verifiers.judge_utils import judge_samples as judge_samples_rule
from agent_env.task_step.task_steps.verifiers.verifier import GRADES_KEY
from agent_env.store.base import NotFoundError
from agent_env.store.routing import namespace_routing, run_scope
from agent_env.task.store import find_task_instance, record_task_cancelled
Expand Down Expand Up @@ -94,6 +97,13 @@ def scores(self) -> dict[str, float]:
when that isn't a step's verifier id."""
return recorded_scores(self.task.steps, self.context)

@property
def splits(self) -> dict[str, list[str]]:
"""The criteria a sampled judge's samples split on in a grade that stood, by step id, each with its passes."""
grades = self.context.metadata.get(GRADES_KEY) or {}
return {step_id: split for step_id, grade in grades.items() if grade.get("verifier_status") == "graded"
and (split := judge_samples_rule.splits(grade.get("verifier_criteria") or []))}

@property
def models(self) -> dict[str, dict[str, str | None]]:
"""The model each step asked for, by role then step id; None leaves it to the agent."""
Expand Down Expand Up @@ -225,6 +235,8 @@ def run_bundle(
model: str | None = None,
user_model: str | None = None,
judge_model: str | None = None,
judge_samples: int | None = None,
min_judge_agreement: float | None = None,
agent: str | None = None,
sandbox: str | None = None,
on_progress: Callable[[str], None] | None = None,
Expand All @@ -237,8 +249,8 @@ def run_bundle(
) -> BundleRun:
"""Write what the tasks and evals selected in ``root`` need, as ``plan_bundle`` selects them, then run
each of their tasks once. ``model``, ``user_model`` and ``judge_model`` replace the models the solver, the
user simulator and the judges run on, and ``agent`` the agent the solver runs as (``Plan.agent``), leaving the
tasks as written; ``sandbox`` is the provider that envs, agents, sandboxes and the judge deploy on, whose deploys
user simulator and the judges run on, ``judge_samples`` how many times each judge that can grades each criterion and ``min_judge_agreement`` the share of those samples each criterion's verdict needs,
and ``agent`` the agent the solver runs as (``Plan.agent``), leaving the tasks as written; ``sandbox`` is the provider that envs, agents, sandboxes and the judge deploy on, whose deploys
pick the forms a computer env composes, on the env's default provider, this machine unless the config names
another; that compose emulates an arch no link of it runs natively unless ``emulate`` is False, which leaves it
skipped. ``on_progress`` is given a line of text
Expand All @@ -264,11 +276,13 @@ def run_bundle(
ends.

Before anything is written, raises RuntimeError when an event loop is already running, ValueError when
``sandbox`` names no provider, and BundleError when the bundle can't be planned or a deploy can't run where
``sandbox`` names no provider or ``judge_samples`` isn't a positive count or ``min_judge_agreement`` a number from 0 to 1, and BundleError when the bundle can't be planned or a deploy can't run where
it would (``preflight``). A task that fails its preflight raises BundleError once the entities it reads are
written, before any task is. Building an infra env the run needs raises what the build raises, before any task
runs."""
_refuse_a_running_loop()
judge_samples = judge_samples_rule.validated(judge_samples)
min_judge_agreement = judge_samples_rule.validated_agreement(min_judge_agreement)
composing = _composing(sandbox, emulate)
say = _progress(on_progress)
with namespace_routing():
Expand All @@ -277,7 +291,7 @@ def run_bundle(
variant=variant, skip_lint=skip_lint)
plan, entries = prepared.plan, [entry for entry, _ in prepared.tasks]
with Interrupts() as interrupts:
overrides = _overrides(sandbox, user_model, judge_model)
overrides = _overrides(sandbox, user_model, judge_model, judge_samples, min_judge_agreement)
runs = interrupts.run(_run_all(plan, list(prepared.tasks), model, overrides,
solver_params(plan, prepared.materialization), keep, say, interrupts,
source))
Expand Down Expand Up @@ -558,15 +572,20 @@ def solver_params(plan: Plan, materialization: Materialization) -> dict[str, dic
return {task_id: {step_id: dict(choice) for step_id in steps} for task_id, steps in plan.agent.steps.items()}


def _overrides(sandbox: str | None, user_model: str | None, judge_model: str | None) -> dict[str, str]:
"""The run's ``user_overrides``: where everything deploys, and the models the user simulator and judges run on."""
def _overrides(sandbox: str | None, user_model: str | None, judge_model: str | None,
judge_samples: int | None = None, min_judge_agreement: float | None = None) -> dict[str, Any]:
"""The run's ``user_overrides``: where everything deploys, the models the user simulator and judges run on, how
many samples the judges take and how many of them must agree."""
overrides = sandbox_overrides(sandbox) if sandbox else {}
return {**overrides, **{key: value for key, value in (("user_model", user_model), ("judge_model", judge_model))
if value}}
overrides.update({key: value for key, value in (("user_model", user_model), ("judge_model", judge_model),
("judge_samples", judge_samples)) if value})
if min_judge_agreement is not None:
overrides["min_judge_agreement"] = min_judge_agreement
return overrides


async def _run_all(
plan: Plan, to_run: list[tuple[BundleEntry, Task]], model: str | None, overrides: dict[str, str],
plan: Plan, to_run: list[tuple[BundleEntry, Task]], model: str | None, overrides: dict[str, Any],
step_params: Mapping[str, dict], keep: bool, say: Callable[[str], None], interrupts: Interrupts,
source: HubSource | None,
) -> tuple[TaskRun, ...]:
Expand Down
11 changes: 9 additions & 2 deletions src/agent_env/cli/eval/run.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import click

from agent_env.cli import submitted_runs
from agent_env.cli.utils import judge_samples_option, min_judge_agreement_option
from agent_env.cli.banner import print_banner
from agent_env.cli.identity import get_agent_env_client_id
from agent_env.cli.usage_output import cost_line, sources_line
Expand Down Expand Up @@ -36,10 +37,12 @@ def _write_context(context, task_id, output_dir, prefix=""):
@click.option("--agent-model", default=None, type=str, help="Override the model used by prompt_agent steps")
@click.option("--user-model", default=None, type=str, help="Override the model the user simulator runs on")
@click.option("--judge-model", default=None, type=str, help="Override the model rubrics_verifier judges grade with")
@judge_samples_option
@min_judge_agreement_option
@click.option("--agent-artifact-id", default=None, type=str, help="Override the agent image artifact for deploy_agent steps")
@click.option("--skip-lint", is_flag=True,
help="Run tasks agent-env task lint finds errors in, saying them, as eval run did before it linted")
def run(eval_id: str, eval_version: int | None, output_dir: str | None, k: int, max_concurrency: int | None, agent_model: str | None, user_model: str | None, judge_model: str | None, agent_artifact_id: str | None, skip_lint: bool):
def run(eval_id: str, eval_version: int | None, output_dir: str | None, k: int, max_concurrency: int | None, agent_model: str | None, user_model: str | None, judge_model: str | None, judge_samples: int | None, min_judge_agreement: float | None, agent_artifact_id: str | None, skip_lint: bool):
"""Run all tasks in an eval through the configured [runner], concurrently."""
if k < 1:
raise click.BadParameter("must be at least 1", param_hint="'--k'")
Expand Down Expand Up @@ -84,7 +87,11 @@ def run(eval_id: str, eval_version: int | None, output_dir: str | None, k: int,

client_id = get_agent_env_client_id()
base_metadata = {"agent_env_hub": {"caller": client_id}} if client_id else {}
if overrides := {key: value for key, value in (("user_model", user_model), ("judge_model", judge_model)) if value}:
overrides = {key: value for key, value in (("user_model", user_model), ("judge_model", judge_model),
("judge_samples", judge_samples)) if value}
if min_judge_agreement is not None:
overrides["min_judge_agreement"] = min_judge_agreement
if overrides:
base_metadata["user_overrides"] = overrides

submissions = [(f"[{task.id} run {i}]" if k > 1 else f"[{task.id}]", task, copy.deepcopy(base_metadata), None)
Expand Down
22 changes: 16 additions & 6 deletions src/agent_env/cli/run.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
from agent_env.bundle.installed import InstalledBundle, checked, installed_bundles, locate_bundle, run_name
from agent_env.bundle.plan import NotInStore
from agent_env.bundle.requires import UnmetRequirements
from agent_env.cli.utils import judge_samples_option, min_judge_agreement_option
from agent_env.cli._install_prompt import offer_to_install
from agent_env.cli.teardown_output import echo_finish_teardown, gone
from agent_env.cli.usage_output import cost_line, sources_line
Expand All @@ -40,6 +41,8 @@
@click.option("--model", default=None, help="The model the solver agent runs on, whatever the tasks name.")
@click.option("--user-model", default=None, help="The model the user simulator runs on, whatever the tasks name.")
@click.option("--judge-model", default=None, help="The model the judges grade with, whatever the tasks name.")
@judge_samples_option
@min_judge_agreement_option
@click.option("--agent", default=None,
help="The agent the solver runs as, whatever the tasks name: an alias such as pi, an agent of this "
"bundle or an installed one, or the store's.")
Expand All @@ -62,7 +65,8 @@
help="Run tasks agent-env task lint refuses for its own rules (a field no step reads, a headline or aggregate source that grades nothing), saying them; a step's own config problems still refuse it.")
@click.pass_context
def run(ctx: click.Context, bundle: str | None, tasks: tuple[str, ...], evals: tuple[str, ...], model: str | None,
user_model: str | None, judge_model: str | None, agent: str | None, settings: tuple[str, ...],
user_model: str | None, judge_model: str | None, judge_samples: int | None, min_judge_agreement: float | None, agent: str | None,
settings: tuple[str, ...],
sandbox: str | None, keep: bool, dry_run: bool, no_emulate: bool, skip_lint: bool):
"""Run a bundle's tasks and evals, or list the installed bundles.

Expand Down Expand Up @@ -106,10 +110,11 @@ def run(ctx: click.Context, bundle: str | None, tasks: tuple[str, ...], evals: t
exits 130 (143 for SIGTERM); a second one stops the teardown and prints what is still up.
"""
if bundle is None:
if tasks or evals or model or user_model or judge_model or agent or settings or sandbox or keep or dry_run \
or no_emulate or skip_lint:
raise click.UsageError("--task, --eval, --model, --user-model, --judge-model, --agent, --set, --sandbox, "
"--keep, --dry-run, --no-emulate and --skip-lint need a BUNDLE to run")
if tasks or evals or model or user_model or judge_model or judge_samples or min_judge_agreement is not None \
or agent or settings or sandbox or keep or dry_run or no_emulate or skip_lint:
raise click.UsageError("--task, --eval, --model, --user-model, --judge-model, --judge-samples, "
"--min-judge-agreement, --agent, --set, --sandbox, --keep, --dry-run, --no-emulate "
"and --skip-lint need a BUNDLE to run")
_list_installed()
return
verbose = ctx.find_root().params.get("verbose")
Expand All @@ -124,7 +129,9 @@ def run(ctx: click.Context, bundle: str | None, tasks: tuple[str, ...], evals: t
variant=variant, skip_lint=skip_lint))
return
result = run_bundle(root, tasks=tasks, evals=evals, model=model, user_model=user_model,
judge_model=judge_model, agent=agent, sandbox=sandbox, on_progress=click.echo,
judge_model=judge_model, judge_samples=judge_samples,
min_judge_agreement=min_judge_agreement, agent=agent, sandbox=sandbox,
on_progress=click.echo,
id_root=id_root, keep=keep, emulate=not no_emulate, source=hub.source if hub else None,
variant=variant, skip_lint=skip_lint)
except BundleError as e:
Expand Down Expand Up @@ -206,6 +213,9 @@ def _summarize(result: BundleRun, verbose: bool) -> None:
click.echo(f" models: {models}")
if cost := cost_line(run.usage_summary):
click.echo(f" {cost}")
if run.splits:
click.echo(" samples split: " + "; ".join(f"{step_id} on {', '.join(rows)}"
for step_id, rows in run.splits.items()))
if result.evals:
click.echo("Evals:")
for eval_run in result.evals:
Expand Down
Loading
Loading