Files
aji/docs/evaluation/harness.md
T
dev d7bb9273f3 E0-3/E0-4 groundwork: provider options, pinned docs, Track A/B in the protocol
- providers: per-model request extras (e.g. reasoning_effort), key_env,
  token_param (max_completion_tokens on api.openai.com); recorded
- docs pinned to the toolchain being run: Rust offline docs from the
  sysroot, Zig langref and std source of the same installation; several
  mounts under a read-only /docs; hashes recorded (cached for big trees)
- protocol: neutral model labels and calibration before classes (§2);
  smoke gates, fixed Aji commit, fixed per-model reasoning mode, slope of
  degradation (§39a); Track A controlled vs Track B native agents (§39b)
- plan: E-C calibration, E-G gates, E-N native-agent run
2026-10-04 17:28:15 +03:00

153 lines
7.3 KiB
Markdown

# Evaluation Harness
Non-normative. The language-neutral agent scaffold and run recorder of plan item E0-3 (protocol §3–§5, §13–§17, §27–§29). Code: [`tools/eval/`](../../tools/eval/). Python standard library only.
```sh
cd tools/eval
python3 -m ajieval run --task DIR --language aji_air --provider anthropic --model MODEL --class frontier \
--evaluator CMD --out runs/
python3 -m ajieval matrix PLAN.json # every cell of a plan; resumable
python3 -m ajieval report runs/ [--json] # VSR, repair cycles, context, cost per correct solution
python3 -m ajieval classify RUN_DIR CATEGORY [--caught-by verifier|runtime|test] [--cause CAUSE]
python3 -m unittest discover tests # harness self-tests (needs `zig build`, Rust, Zig)
```
## One run
One model + one language + one task + one fresh workspace + one fresh agent context (protocol §3). The task's starter workspace for the language is copied into `RUN/workspace`, and the agent loop runs until the model calls `finish`, ends its turn without a tool call, or a budget runs out. Then the evaluator judges the final workspace and the first-generation snapshot.
**One loop for every language.** The system prompt, the tools and the termination rules are the same for Aji, Rust and Zig. A language contributes only its profile ([`tools/eval/languages/`](../../tools/eval/languages/)): how to invoke the toolchain, where its pinned documentation is, and which commands count as verifier, compiler or test runs. Profiles carry no solution hints (protocol §5).
**Tools.** `list_files`, `read_file`, `write_file`, `edit_file`, `run` (a shell command in the workspace) and `finish`. Paths are confined to `/work` (the repository, writable) and `/docs` (documentation, read-only).
**Sandbox.** `bwrap` (bubblewrap) is the default:
- no network (protocol §4);
- read-only system and toolchain;
- the workspace at `/work`;
- documentation at `/docs`;
- a fresh `/tmp` and `HOME`;
- a clean environment.
`--sandbox none` is for harness development only and is recorded.
**Termination.** One of:
| Reason | Meaning |
|---|---|
| `finished` | the model called `finish` |
| `model_end` | the model ended its turn without a tool call; the scaffold does not nudge, so stopping early is part of the measurement |
| `max_tokens` | the reply hit the output-token limit |
| `budget_tool_calls`, `budget_tokens`, `wall_time` | a task limit ran out |
| `provider_error` | the model provider failed |
**Providers.** Each provider has a fixed role:
| Provider | Use |
|---|---|
| `anthropic` | Anthropic Messages API (`ANTHROPIC_API_KEY`) |
| `openai` | OpenAI-compatible chat completions (`OPENAI_API_KEY`); also local servers such as vLLM, llama.cpp or Ollama via `base_url` |
| `scripted` | replays fixed turns (self-tests) |
Per model, `extra` (JSON) is merged into every request body and recorded, for example `{"reasoning_effort": "medium"}`. `key_env` names the environment variable holding the key, and `token_param` chooses `max_tokens` or `max_completion_tokens`. Keys are never written to records.
**Documentation** is pinned to the toolchain being run:
| Language | Mounted under `/docs` |
|---|---|
| Aji | the Agent Reference Bundle |
| Rust | the toolchain's offline documentation from the sysroot: std API, the Reference, the Book |
| Zig | the matching language reference (`/docs/doc`) and standard library source (`/docs/std`) |
An environment variable (`AJI_EVAL_*_DOCS`) overrides this. Each mount's hash is recorded next to the compiler version, and hashes of large trees are cached in `~/.cache/ajieval`.
## Task directory (the interface to the private benchmark repository)
```text
<task>/task.json id, version, set (dev|validation|test), family, prompt,
languages {lang: {workspace, test}}, limits, concurrency
<task>/prompt.md language-neutral statement
<task>/<workspace>/ starter repository per language: README with the
interface, public tests, build files
```
`limits` may set:
| Limit | Default |
|---|---|
| `tool_calls` | 150 |
| `total_tokens` | 3 000 000 |
| `wall_seconds` | 3 600 |
| `command_timeout` | 300 |
| `output_chars` | 20 000 |
The `test` command is the public test. Invoking it counts as a test run.
Hidden tests, evaluators and reference implementations never enter this repository (protocol §29). The only task kept here is the harness development task [`dev-tasks/dev-echo`](dev-tasks/dev-echo/), which belongs to no benchmark family.
## Evaluator contract
The harness calls `CMD WORKSPACE LANGUAGE TASK_DIR` outside the agent's sandbox. The evaluator must print one JSON object:
```json
{"accepted": true, "gates": {"verifier": true, "public_tests": true, "hidden_functional": true, "hidden_regression": true, "fuzz": true, "resources": true, "deterministic_runs": true, "schedule_exploration": true}}
```
`accepted` follows protocol §13: all mandatory gates pass, with no partial success. The evaluator runs untrusted code, so it must sandbox that code itself. The record stores the hash of the evaluator, or of `--evaluator-hash-path`, and the full verdict.
## Run record (`RUN/run.json`, protocol §28)
Every run directory contains:
| Path | Contents |
|---|---|
| `run.json` | the record below |
| `events.jsonl` | every model reply (content and token usage), tool call and result, patch (unified diff), and command (exit code, output) |
| `workspace/` | the final repository |
| `first_generation/` | the workspace before the first toolchain invocation (protocol §14) |
`run.json` holds:
- **Identity:**
- task id, version, set and hash;
- evaluator command and hash;
- language, profile hash, toolchain versions, docs path and hash;
- model provider, id, class and parameters;
- scaffold version, commit and sandbox;
- system prompt hash and task prompt hash;
- limits, hardware, seed.
- **Metrics:**
- model and tool calls;
- input, output and cached tokens;
- patches, commands, check/build/test runs;
- failed verifier cycles and failed test cycles (§15);
- first check, build, public test and hidden test results (§14);
- files opened, repository and documentation bytes read (§16);
- elapsed time, termination.
- **Outcome:** `cost_usd` from an optional pricing table (USD per million tokens, §17), `verdict`, `first_generation_verdict`, `accepted`, the hashes of the final repository, and `classification`.
## Failure classification
`ajieval classify` records the primary category of a failed run (protocol §27). For Aji runs it also records where the failure was caught: verifier, runtime or test.
For the smoke test it also records the cause, decided before any language change is considered (protocol §38):
- `language`
- `documentation`
- `agent_bundle`
- `diagnostics`
- `harness`
- `model_capability`
- `task_ambiguity`
## Smoke test (E-S)
[`smoke-plan.example.json`](smoke-plan.example.json) is the shape of the 36-run plan (owner decision):
- families: a binary/stream parser and a concurrent bounded pipeline;
- languages: Aji/AIR, Rust and Zig;
- model classes: frontier, mid and small/local;
- runs: 2 independent runs per cell.
The tasks, evaluators and baselines come from E0-2 and E0-4. The smoke test checks infrastructure, not the hypothesis. Its headline numbers are still read: Verified Success Rate, repair cycles, context consumed and cost per correct solution.