SPEC-004: Runner¶
- Status: Implemented
- Milestone: M1
- Owners: lead maintainer
1. Purpose¶
Define how an episode runs: turn order, limits, illegal moves, forfeits and error handling. The runner is the only part that connects worlds, agents, messages and the log.
2. Terms¶
- Step: one agent action applied via
step. Round: in a simultaneous world, one set of actions applied together. - Illegal move: a
stepreturningok=false. Model failure:AgentError. Provider error:ProviderError(SPEC-002).
3. Requirements¶
Lifecycle¶
- RUN-001 The runner MUST: validate inputs; call
world.reset(seed)andagent.reset(...); writerun_start; loop turns untilworld.done()or a limit; writerun_end. - RUN-002 Each turn the runner MUST ask
to_act(), send each listed agent a Request (SPEC-002), apply the Reply viastep, and log events per SPEC-003. - RUN-003 For simultaneous worlds the runner MUST collect all actions from the round's agents before applying any, then apply in
to_act()order. Each agent MUST see only the state from before the round. - RUN-004 Seeds: the run seed MUST derive per-agent seeds deterministically (agent id and run seed), recorded in the log.
Limits (on by default)¶
- RUN-005 Limits
max_steps(default 200),max_seconds(default 600) andmax_cost_usd(default 1.00) MUST apply unless explicitly set otherwise; a scenario MAY set a limit tonullonly with an explicit value. - RUN-006 When a limit is reached the runner MUST stop before the next agent call, write
limit_hit, and end with the matching reason (step_limit,time_limit,budget_exceeded). - RUN-007 Cost MUST be checked before each call against cumulative cost; a call whose reported cost pushes the total over the cap ends the run after that call.
Illegal moves and forfeits¶
- RUN-008 On an illegal move the runner MUST send the error back to the agent in its next Request and let it retry; the world state is unchanged.
- RUN-009 After
max_illegalconsecutive illegal moves by one agent (default 3), the runner MUST logforfeitand end the run with reasonforfeit(two-agent worlds: the other agent wins inoutcome; the world decides scores). - RUN-010 A model failure (
AgentError) MUST count as an illegal move.
Errors¶
- RUN-011 A
ProviderErrorMUST be logged asprovider_error, never counted as an illegal move or forfeit. After retries are exhausted the run ends with reasonabortedand the log says which provider failed. - RUN-012 An exception from the world (a bug) MUST be logged, end the run with
world_error, and surface a short message naming the world and method. - RUN-013 An exception from an evaluator MUST NOT change the run log or result of the episode.
- RUN-014 User mistakes (bad scenario, missing key) MUST produce a one-line error naming the file, field and fix, not a stack trace (SPEC-007).
Messages and isolation¶
- RUN-015 Messages from
sayMUST be delivered through the bus (SPEC-008) and appear in the next Requestinboxof recipients. - RUN-016 The runner MUST pass agents plain data copies; agents MUST NOT hold references to world state.
- RUN-018 In a simultaneous round every Request MUST carry the step number at the start of the round; the applied actions then take consecutive step numbers in
to_actorder. An agent whose action was illegal stays into_actand acts again, alone, before the round resolves. - RUN-019 When an agent reports
cost_usd: null, the runner MUST log onewarningfor that agent and enforcemax_tokens(default 200000, total input plus output tokens of all agents); exceeding it ends the run withbudget_exceededafter alimit_hitwith limit"tokens". - RUN-020 For each entry in a reply's
meta.retriesthe runner MUST log aprovider_error(retryable true) before that reply's action. - RUN-021 The runner MUST call
close()on every agent that has it, and on the world when it has one, when the episode ends, including on errors and interruptions (Ctrl+C). - RUN-022 A world that declares
outcome_on_limit: trueindescribe()MUST haveoutcome()called when the run ends by a limit (step_limit,time_limit,budget_exceeded);run_end.outcomerecords it and the reason stays the limit (SPEC-014 SBX-003). - RUN-017 Each Request MUST include
last_error: the error from that agent's previous illegal move or agent error, or null (how RUN-008 sends the error back).
4. Acceptance criteria¶
| Requirement | Test ID | Notes |
|---|---|---|
| RUN-001..004 | RUN-001..RUN-004 |
tic-tac-toe run end to end |
| RUN-005..007 | RUN-005..RUN-007 |
fake agent with cost per call |
| RUN-008..010 | RUN-008..RUN-010 |
agent that always plays illegally |
| RUN-011..014 | RUN-011..RUN-014 |
429 fixture; buggy world |
| RUN-015..016 | RUN-015, RUN-016 |
5. Open questions¶
- Per-call timeout vs. whole-run timeout (draft: whole-run only plus adapter timeouts).
- Should forfeits be configurable per scenario? (Yes via
max_illegal.)
6. Change log¶
- 2026-11-30: Initial draft.
- 2026-11-30: Accepted by the lead maintainer.
- 2026-11-30: Added RUN-017 (
last_errorfield), already implemented in M1. - 2026-11-30: Added RUN-018 (step numbers in simultaneous rounds).
- 2026-11-30: Added RUN-019 (token cap for unknown cost), RUN-020 (retries logged), RUN-021 (agents closed).
- 2026-11-30: Implemented in v0.1.0; every requirement has a test (PRO-004, PRO-011).
- 2026-11-30: The reference world
oxis renamedtic-tac-toe(ADR-0006); no alias. - 2026-12-01: RUN-021 covers the world's
close(); added RUN-022 (outcome_on_limit), with SPEC-014.