SPEC-017: World helpers and text-move worlds¶
- Status: Implemented
- Milestone: v0.9 "Build your own"
- Owners: lead maintainer
1. Purpose¶
Make common kinds of worlds short to write and robust with small models. The debate example
needed about 100 lines, mostly bookkeeping: whose turn it is, counting rounds, checking and
cutting text. Helpers do that once, so a world author writes only what makes their world
different. This spec also closes two gaps found while building the debate example: the testkit
cannot check worlds whose move is free text, and rejected replies use up max_steps.
2. Terms¶
Keywords MUST, SHOULD and MAY follow RFC 2119.
- Helper: a base class in agentplaykit.worlds that implements part of the world interface
(SPEC-001) on top of the public API.
- Text-move world: a world whose action is free text (its action schema is a JSON Schema of
type: string), such as a debate or a negotiation message.
- Choice-move world: a world whose actions are a list, such as tic-tac-toe squares.
3. Requirements¶
Helpers¶
- WLD-001 The framework MUST ship helpers in
agentplaykit.worlds, built only on the publicEnvironmentinterface, so a world made with them behaves exactly like a hand-written one and the runner needs no special cases. - WLD-002
TurnBasedMUST provide turn order and the end of the game: agents act one at a time in the order ofagents(), the game ends afterroundsmoves per agent (from config or a class attribute) or when the world says so, and every accepted move is kept inself.historyas{"by", "move", "step"}. The author implementsobserve, the legal moves and what a move does. - WLD-003
TextMovesMUST implement the action schema and checking for text-move worlds:max_chars;too_long(reject, the default, orcut, which shortens the text with no penalty and recordsinfo.cut); an error with a hint when the text is only a placeholder word such as "argument"; and acceptance of{"<key>": text}for a configurable key. Every error MUST say what a valid move looks like. - WLD-004
ChoiceMovesMUST accept a move that matches a legal action after a documented normalisation (numbers sent as text, letter case, surrounding spaces), and MUST recordinfo.normalisedwhen it did. Normalisation MUST be the same for every agent. - WLD-005 Worlds built with the helpers MUST pass
agentplaykit test(CLI-009) with no extra code.
Examples built with the helpers¶
- WLD-006
examples/debateMUST be rewritten withTurnBasedandTextMoves, with at most 40 lines of world code outside docstrings and comments, and the same behaviour (its tests keep passing). - WLD-007 The framework MUST ship
examples/negotiation: two agents split 100 points by making offers in text and accepting or rejecting them, with private values each agent cannot see, a deal or no-deal outcome, and scores from each agent's private values. It uses the helpers and runs with scripted agents and no key.
Illegal moves and steps¶
- WLD-008 A scenario MAY set
limits.count_rejected_steps: false. Thenmax_stepscounts only accepted moves, while rejected replies are still logged with their own step numbers and still bounded bymax_illegal,max_seconds,max_cost_usdandmax_tokens. The default staystrue(today's behaviour), so existing results do not change.
Testing text-move worlds¶
- WLD-009 The testkit MUST be able to play text-move worlds: for a string schema it MUST
sample from the schema's
exampleswhen given, and otherwise from a fixed list of short, varied texts that respectminLengthandmaxLength. - WLD-010 The testkit's illegal-move probe (ENV-012) MUST use a value the action schema
rejects (for a string schema, a number or
null) instead of a fixed string that a text-move world would rightly accept. A world MAY declareillegal_exampleindescribe()to name its own probe.
4. Acceptance criteria¶
| Requirement | Test ID | Notes |
|---|---|---|
| WLD-001..005 | WLD-001..WLD-005 |
each helper alone and combined; normalisation table; helper worlds pass agentplaykit test |
| WLD-006..007 | WLD-006, WLD-007 |
line count of the debate world; negotiation plays to deal and no-deal with scripted agents |
| WLD-008 | WLD-008 |
8 rounds finish with 20 rejected replies under max_steps: 16 when the option is false; unchanged by default |
| WLD-009..010 | WLD-009, WLD-010 |
the debate world passes the testkit; a world that accepts everything is still caught |
5. Examples¶
The debate world with the helpers:
from agentplaykit.worlds import TextMoves, TurnBased
class Debate(TurnBased, TextMoves):
name, version = "debate", "2"
rounds, max_chars, too_long = 4, 400, "cut"
def observe(self, agent):
sides = self.config["sides"]
return {
"topic": self.config["topic"],
"your_side": sides[agent],
"other_sides": {a: s for a, s in sides.items() if a != agent},
"debate_so_far": self.history,
}
def outcome(self):
return {"winners": [], "scores": {a: 0.0 for a in self.agents()}}
limits:
max_steps: 16
count_rejected_steps: false # only accepted arguments count toward max_steps
6. Open questions¶
- A
Simultaneoushelper for worlds where everyone moves at once (rock-paper-scissors style). - A
HiddenInfohelper that keeps per-agent private state out of other agents' observations.
7. Change log¶
- 2026-12-01: Initial draft.
- 2026-12-01: Accepted by the lead maintainer for v0.9.
- 2026-12-03: Implemented in v0.9.0; every requirement has a test.
Changes to other specs on acceptance¶
- SPEC-004, new RUN-023:
limits.count_rejected_steps(WLD-008). - SPEC-005: the new limit in the scenario schema.
- SPEC-007, CLI-009: the testkit rules for text-move worlds (WLD-009, WLD-010).