Skip to content

SPEC-001: Environment

  • Status: Implemented
  • Milestone: M1
  • Owners: lead maintainer

1. Purpose

Define the one interface a world (environment) implements so that any agent plugin can play in it. The core knows only this interface and the Agent interface (SPEC-002).

2. Terms

Keywords MUST, SHOULD and MAY follow RFC 2119. - World / Environment: an object implementing this interface. - Agent ID: a string naming one participant, unique within an episode. - Plain data: values made only of null, booleans, numbers, strings, lists and string-keyed objects (JSON-serializable). - Observation: plain data describing what one agent can see now. - Action: plain data an agent submits. Legal action: one the world accepts in the current state. - Episode: one run from reset until done.

3. Requirements

Lifecycle

  • ENV-001 An environment MUST provide reset(seed: int) -> None, which starts a new episode and discards all earlier state.
  • ENV-002 After reset with the same seed and the same configuration, the environment MUST behave identically for the same sequence of actions (determinism). All randomness MUST derive from the seed.
  • ENV-003 An environment MUST expose agents() -> list[str]: the agent IDs, fixed for the whole episode and non-empty.
  • ENV-004 An environment MUST expose done() -> bool, true once the episode has ended. After done() is true, step MUST NOT change state.

Turns

  • ENV-005 An environment MUST expose to_act() -> list[str]: the agent IDs allowed to act now. Empty if and only if done() is true.
  • ENV-006 In a sequential world to_act() MUST contain exactly one ID. A simultaneous world MAY return several; the runner then collects one action from each and applies them in to_act() order within one round (decision 2: sequential is the default).

Observations and actions

  • ENV-007 observe(agent: str) -> dict MUST return plain data containing only what that agent is allowed to see (per-agent views).
  • ENV-008 actions(agent: str) -> list | dict MUST return plain data describing the legal actions for that agent now: either an explicit list of legal actions or a JSON Schema describing them.
  • ENV-009 observe and actions MUST NOT change state.

Stepping

  • ENV-010 step(agent: str, action) -> StepResult MUST apply the action for that agent. StepResult is plain data with the fields ok (bool), error (string or null), done (bool), rewards (object, agent ID to number, possibly empty) and info (object, possibly empty).
  • ENV-011 If the agent is not in to_act(), step MUST return ok=false with a non-empty error and MUST NOT change state.
  • ENV-012 If the action is illegal, step MUST return ok=false with an error that names the problem and the legal choices when practical, and MUST NOT change state.
  • ENV-013 A legal action MUST produce ok=true and error=null. StepResult.done MUST equal done() after the step.
  • ENV-014 step MUST NOT raise for any agent-supplied action; exceptions are reserved for bugs in the world, which the runner records as a world error (SPEC-004).

Outcome

  • ENV-015 When done() is true, outcome() -> dict MUST return plain data with winners (list of agent IDs, possibly empty) and scores (object, agent ID to number). Scores come from world rules, never from an agent.

Plain data and metadata

  • ENV-016 Everything crossing the interface MUST be plain data; the core MUST reject non-serializable values with an error naming the method and field.
  • ENV-017 An environment SHOULD expose describe() -> dict with name, version, a short rules text for agents, and simultaneous (bool, default false).
  • ENV-019 describe() MAY include view, a plain-data hint telling viewers how to draw observations (SPEC-012 VWR-012).
  • ENV-018 Environments MUST NOT read or write files, use the network, or write logs; only core writes the log (SEC-005). The one exception is the built-in sandbox world, which controls containers as SPEC-014 describes and reads only its task folders; ENV-001 to ENV-004 (same seed, same state) are relaxed for it, since programs inside a container may use the clock.

4. Acceptance criteria

Each requirement gets a conformance test with the same ID in tests/conformance/, run against every built-in world and against third-party worlds through agentplaykit test (later milestone).

Requirement Test ID Notes
ENV-001..004 ENV-001..ENV-004 same seed, same actions, same states
ENV-005..006 ENV-005, ENV-006
ENV-007..009 ENV-007..ENV-009 observe/actions called twice leave state equal
ENV-010..014 ENV-010..ENV-014 fuzz with random actions: never raises, illegal leaves state unchanged
ENV-015 ENV-015
ENV-016..018 ENV-016..ENV-018

5. Examples

Illustrative (the Python base class is defined at implementation time and MUST follow this spec):

class Counter(Environment):  # a world in a few lines
    def reset(self, seed):
        self.n = 0

    def agents(self):
        return ["a"]

    def done(self):
        return self.n >= 3

    def to_act(self):
        return [] if self.done() else ["a"]

    def observe(self, agent):
        return {"n": self.n}

    def actions(self, agent):
        return ["inc"]

    def step(self, agent, action): ...

Illegal tic-tac-toe move result: {"ok": false, "error": "cell 4 is taken; legal cells: [0,1,2,5,6,7,8]", "done": false, "rewards": {}, "info": {}}

6. Open questions

  • Should rewards be per-step or only in outcome()? (Current draft allows both; evaluators use outcome().)
  • Do we need snapshot()/restore() for replays? Deferred to v0.2 (viewer); the log carries what a viewer needs.
  • Should actions allow free text (for chat-like worlds)? Messaging is a bus concern (SPEC-008).

7. Change log

  • 2026-11-30: Initial draft.
  • 2026-11-30: Accepted by the lead maintainer.
  • 2026-11-30: Implemented in v0.1.0; every requirement has a test (PRO-004, PRO-011).
  • 2026-11-30: The reference world ox is renamed tic-tac-toe (ADR-0006); no alias.
  • 2026-12-01: Added ENV-019 (view in describe()), with SPEC-012.
  • 2026-12-01: ENV-018 exception for the sandbox world, with SPEC-014.