Worlds without code¶
You can test agents on your own situation without writing Python. Write the world in one YAML file, the world file, and AgentPlay plays it like any other world: models and people can play it, and reports, ratings, experiments, tournaments, benchmarks and the viewer all work on it.
A world file has one of three kinds:
| Kind | What it is | Examples |
|---|---|---|
matrix |
every player picks a move at the same time; a table says what each gets | the Prisoner's Dilemma, a pricing duel, a coordination game |
quiz |
questions with answers, scored automatically | your own benchmark, a classroom test |
conversation |
players with roles and private briefs talk in turns, then may make a final choice | a negotiation, an interview, persuasion |
The rules are in SPEC-029. Loading a world file never runs code, so you can use world files that other people send you.
Start from a working file¶
agentplaykit new world pricing --kind matrix
cd pricing
agentplaykit check pricing.yaml
agentplaykit play scenario.yaml
agentplaykit test pricing.yaml
new world NAME --kind matrix|quiz|conversation writes a commented world file and a
scenario.yaml that plays it with scripted agents, free and with no key. Change the file,
check it, and play it.
Every world file starts with the same fields:
agentplay_world: 1 # always 1: this is a world file
name: pricing # the name in reports
kind: matrix # matrix, quiz or conversation
rules: > # the text every agent gets; say everything a player needs
...
players: [a, b] # one agent per player in the scenario, with the same IDs
A scenario uses the file as its world, with a path relative to the scenario:
agentplay: 1
name: pricing
seed: 1
world: {use: pricing.yaml, config: {rounds: 10}}
agents:
- {id: a, use: ollama, config: {model: "qwen2.5:7b", constrain: true}}
- {id: b, use: scripted/random}
config overrides any top-level field of the world file except agentplay_world and kind,
so one file serves many settings. In agentplaykit.yaml, envs: {pricing: worlds/pricing.yaml}
gives the file a short name (world: {use: pricing}).
A game of choices and payoffs¶
agentplay_world: 1
name: prisoners-dilemma
kind: matrix
rules: >
You and another player each choose to cooperate or defect, at the same time, for 10 rounds.
If you both cooperate, you each get 3. If you both defect, you each get 1. If one cooperates
and the other defects, the one who defects gets 5 and the other 0.
players: [a, b]
moves: [cooperate, defect]
payoffs:
cooperate/cooperate: [3, 3]
cooperate/defect: [0, 5]
defect/cooperate: [5, 0]
defect/defect: [1, 1]
rounds: 10
Each key of payoffs is a joint move: the players' moves in the order of players, joined
by /. Its value is each player's payoff, as a list in player order or as a map by player
({a: 0, b: 5}). Every joint move needs a payoff, and check lists the missing ones.
Players can have different moves: moves: {seller: [high, low], buyer: [buy, pass]}. More than
two players works the same way, with longer joint moves (a/b/c).
Players choose at the same time, so no one sees the others' choice for the round. The score is the total payoff; the winners are the players with the highest total, or none when all are equal.
A quiz¶
agentplay_world: 1
name: capitals
kind: quiz
rules: Answer with the name of the capital city only.
players: 2
questions_file: capitals.csv
ask: 20
question,answer,accept
What is the capital of France?,Paris,
What is the capital of India?,New Delhi,Delhi
What is the capital of Thailand?,Bangkok,Krung Thep
The questions can be in the world file under questions, or in a data file next to it:
.csv, .json, .jsonl or .yaml. In a CSV file, accept and choices list several values
separated by |. A data file must be in the world file's folder or below, and is read when the
scenario loads.
Each question has question and answer, and may have:
questions:
- question: What is 12 times 12?
answer: 144
type: number # matched as a number
tolerance: 0.5 # within 0.5 counts as right
- question: Which planet is known as the red planet?
answer: Mars
choices: [Venus, Mars, Jupiter] # the player picks one
- question: Name a primary colour.
answer: red
accept: [blue, yellow] # more answers that count as right
points: 2
A text answer is right when it matches after ignoring case, spaces at the ends and final
punctuation: " paris. " matches Paris. With players: 2 the players are p1 and p2,
unless the scenario names them: the scenario's agent IDs are used.
Every player answers every question, at the same time. The score is the points for right
answers, and run_end.outcome.accuracy gives each player's correct count and the questions it
got wrong.
A conversation¶
agentplay_world: 1
name: job-offer
kind: conversation
rules: >
A recruiter and a candidate talk about a job offer for three turns each. Then each decides,
at the same time, whether to agree or walk away.
players: [recruiter, candidate]
roles:
recruiter:
public: You hire engineers for a small startup.
brief: Your budget is up to 95k a year.
candidate:
public: You are a senior engineer.
brief: You have another offer at 90k. You would take this job at 92k or more.
turns: 3
final:
moves: [agree, walk away]
payoffs:
agree/agree: [1, 1]
agree/walk away: [0, 0]
walk away/agree: [0, 0]
walk away/walk away: [0, 0]
Players speak in the order of players, one message per turn, for turns rounds. A message is
free text. With final, each player then makes one choice at the same time, scored with its
moves and payoffs exactly as in a matrix world: cheap talk, then action.
Without final, nothing in the world says who did better, so the world declares that a judge
decides: add a judge evaluator to the scenario (SPEC-010),
and the run's outcome has no winners.
Every field¶
Fields for every kind:
| Field | Default | Meaning |
|---|---|---|
agentplay_world |
required | always 1 |
name |
required | the world's name in reports: letters, digits, - and _ |
kind |
required | matrix, quiz or conversation |
rules |
required | the text every agent gets |
players |
required | a list of player IDs; a quiz may give a number of players instead |
version |
"1" |
change it when you change the rules: reports group runs by name and version |
description |
none | one line about the world |
chat |
true |
false turns off messages between players (say) |
matrix:
| Field | Default | Meaning |
|---|---|---|
moves |
required | a list for every player, or a map from player to its list |
payoffs |
required | a map from each joint move to each player's payoff |
rounds |
1 |
how many rounds |
show_history |
true |
players see every past round's moves and payoffs |
quiz:
| Field | Default | Meaning |
|---|---|---|
questions |
one of the two | a list of questions in the file |
questions_file |
one of the two | a .csv, .json, .jsonl or .yaml file in the same folder or below |
ask |
all | how many questions to ask, sampled with the run's seed |
shuffle |
true |
ask in an order drawn from the seed |
feedback |
false |
players see whether each past answer was right |
A question: question and answer (required), choices, accept, type (text or
number, default text), tolerance (default 0) and points (default 1).
conversation:
| Field | Default | Meaning |
|---|---|---|
roles |
required | per player: public (told to everyone) and brief (told only to that player) |
turns |
4 |
messages per player |
max_chars |
600 |
the longest message, in characters |
final |
none | moves and payoffs for a final choice, as in a matrix world; without it a judge decides |
For completion and checks in your editor, the format is published as a JSON Schema:
world.schema.json.
With the VS Code YAML extension, add this first line to a world file:
# yaml-language-server: $schema=https://raw.githubusercontent.com/thetejasmagade/agentplay/master/specs/schemas/world.schema.json
Checking a world file¶
agentplaykit check reports every problem at once, with the file and field, and a hint:
error: unknown field "payofs" for a matrix world (prisoners.yaml:payofs) -> did you mean "payoffs"? [config.invalid]
error: "defekt" is not a move of player b (prisoners.yaml:payoffs.cooperate/defekt) -> did you mean "defect"? [config.invalid]
error: 1 combination(s) of moves have no payoff: cooperate/defect (prisoners.yaml:payoffs) -> give every combination of moves a payoff [config.invalid]
check works on the world file alone, or on a scenario that uses it (then it also checks that
the scenario has one agent per player). agentplaykit test my-world.yaml runs the world
conformance kit, as for a Python world.
What each player sees¶
Every agent gets the rules, its legal moves and an observation. The observation has a view,
the same information as text, which people see in the terminal and the replay page.
- matrix:
you_are,roundandrounds,players,your_moves, thepayoffstable,your_total, and withshow_historythehistoryof past rounds. Never another player's choice for the current round. - quiz:
you_are, thequestion, its number and the number ofquestions,choicesif any,answer_type(textornumber), andpointsif set. Withfeedback,your_scoreandpastanswers marked right or wrong. Never another player's answer. - conversation:
you_are,your_role(yourpublictext),your_brief, theothers' public texts, theconversationso far andturns_left. Never another player's brief. When the talking is over and there is afinal,decide,your_movesand thepayoffs.
Legal moves are listed for matrix worlds, quiz questions with choices and final choices; a
text answer or a message is free text. A person can play every kind with
agentplaykit play scenario.yaml --human <id>.
In the replay page, each matrix round shows the moves and payoffs, each quiz question shows every player's answer marked right or wrong, and a conversation's messages appear in the chat panel.
Examples¶
examples/no-code/
has three worlds, each with a scenario that runs with scripted agents and no key:
agentplaykit play examples/no-code/prisoners-scenario.yaml # the Prisoner's Dilemma, 10 rounds
agentplaykit play examples/no-code/capitals-scenario.yaml # 20 capitals from a CSV file
agentplaykit play examples/no-code/job-offer-scenario.yaml # a negotiation with private briefs
The scripted agents are stand-ins: scripted/random picks a random legal move, and
scripted/lines types its lines in turn when a move is free text. Put a model in their place
to see what a model does.
When to write a Python world¶
World files cover games of choices, quizzes and conversations. Write a Python world when you need:
- payoffs computed from numbers, such as an auction or any contribution in a public-goods game (list the moves you need, or write Python);
- a board, a map, or a state that moves (
agentplaykit new world NAMEwrites a starter); - answers checked by code, such as running a program or a test;
- moves with several fields, such as an offer with a price and a date;
- turns that depend on what happened, such as a player who leaves the game.
The world helpers make a Python world short, and the same test kit checks it.