Experiments: many runs from one file¶
An experiment runs many games from one file: several scenarios, several agents, several settings and many seeds, in parallel, stoppable and resumable, with a cost estimate first and one report at the end (SPEC-019).
agentplay: 1
experiment: tic-tac-toe-players # also the folder name under --out
scenarios: [../tic-tac-toe-chat/scenario.yaml]
entrants: # agents to seat in the scenarios' roles
- {name: minimax, use: scripted/minimax}
- {name: qwen-3b, use: ollama, config: {model: "qwen2.5:3b"}}
- {name: qwen-3b+memory, use: ollama, config: {model: "qwen2.5:3b"}, wrap: [memory]}
seating: all # every seating of distinct entrants
vary: # settings to compare, crossed with each other
limits.max_illegal: [3, 5]
seeds: 10 # each scenario's seed and the 9 after it
max_total_cost_usd: 2.00 # stop starting runs once this much is spent
The example is in
examples/experiment/tic-tac-toe.yaml,
and runs with no key.
The three steps¶
agentplaykit experiment plan experiment.yaml # cells, runs and a cost estimate; runs nothing
agentplaykit experiment run experiment.yaml --workers 4
agentplaykit report runs/tic-tac-toe-players # one report, with a section per varied setting
agentplaykit check experiment.yaml validates every generated scenario first, without running
anything.
What the file can say¶
| Key | Meaning |
|---|---|
scenarios |
Scenario files, relative to the experiment file |
seeds |
A count N (each scenario's own seed and the N-1 after it), or a list of exact seeds |
entrants |
Named agents (name, use, config, wrap) to seat in the scenarios' roles |
seating |
fixed (the scenarios' own agents, the default), all (every seating of distinct entrants, as tournaments do), or each (every entrant in every role, against the scenario's other agents) |
vary |
A setting path to a list of values. Paths go into the scenario: world.config.rounds, limits.max_illegal, or agents.<id>.config.temperature for one agent |
limits |
Limits applied to every scenario |
max_total_cost_usd |
Stop starting new runs once the experiment has spent this much |
max_parallel_per_provider |
Games at once per hosted provider (default 2), to avoid rate limits |
Each combination of scenario, seating and setting values is a cell; each cell plays every
seed. Every run plays exactly as agentplaykit play would play that scenario and seed.
Running¶
--workers Nplays N games at once, in separate processes. The logs are the same as with one worker, apart from timings.- A game counts against every hosted provider its agents use (
openrouter,gemini, achat_apihost...); at mostmax_parallel_per_providergames use one provider at once. Scripted, local (Ollama, transformers) and file agents don't count. Each worker loads its own copy of atransformersmodel, so more workers means more memory. - A failed run (
world_error,aborted) is recorded and the experiment carries on;--stop-on-errorstops starting new runs instead.
Stopping and resuming¶
Logs go to runs/<experiment>/<cell>/, where the cell folder is a readable label plus a hash of
its settings. runs/<experiment>/experiment.json (the manifest) lists every run with its
state, done, failed or not played, and is saved after every finished run.
- Ctrl+C leaves the manifest and every finished log valid. Run the same command again to continue: finished runs are skipped and the rest are played.
- Changing the file changes the affected cells' hashes, so their new runs go to new folders and are never mixed with the old results; unchanged cells stay done.
--freshstarts over in a new folder (runs/<experiment>-2).
agentplaykit experiment status runs/tic-tac-toe-players
experiment tic-tac-toe-players: 96 done, 2 failed, 22 left of 120 runs; cost so far $0.8312
2 x provider failed for x: 429 from https://openrouter.ai/...
The manifest also records what is needed to repeat the experiment: the file's hash, each cell's scenario hash, the agents' settings (keys never included), the AgentPlay, Python and platform versions, and the models that actually answered.
The report¶
agentplaykit report runs/<experiment> reads the logs from the manifest and adds an
Experiment section: for each varied setting, each value's results per competitor (rating or
pass rate with intervals, runs, cost and steps), so you can read the effect of a setting
directly. The rest of the report (leaderboard, head to head, runs) covers all the runs together.
In Python: run_experiment("experiment.yaml", out="runs", workers=4) from
agentplaykit.experiments returns the manifest.