Small models¶
Small local models (3B to 8B, through Ollama or another local server) often lose games because of their replies, not their moves. They write the move in a sentence, put it under the wrong key, or keep sending moves that are not legal, and then forfeit. AgentPlay has three ways to help, and one command that tells you which one works for your model.
The rules are in SPEC-025.
Check a model¶
agentplaykit model check --agent '{use: ollama, config: {model: "qwen2.5:3b"}}'
The check plays short games of tic-tac-toe, rock-paper-scissors and chess (10 moves each)
against scripted/random. It plays each game three ways: as you configured the model, with the
format_hints wrapper, and with constrain: true. Then it shows how each did and recommends
one. No model installed? Try it with testkit/sloppy, the built-in stand-in for a small model
that makes a mistake on some replies:
agentplaykit model check --agent testkit/sloppy
model check: testkit/sloppy, 18 games (3 worlds x 2 games x 3 variants), local, cost $0
check-tic-tac-toe x=as-configured seed 1: finished
...
variant games moves readable legal 1st lenient forfeits s/move cost
as configured 6 47 89% 67% 3 0 0.0 $0.0000
+format_hints 6 47 89% 67% 3 0 0.0 $0.0000
+constrained 6 54 100% 65% 0 0 0.0 $0.0000
Recommended: as configured (no forfeits). In a scenario:
- id: x
use: testkit/sloppy
Logs: runs/model-check/testkit-sloppy (agentplaykit report runs/model-check/testkit-sloppy)
| Column | What it counts |
|---|---|
| games | games played (each world twice: once as each player) |
| moves | replies the model sent |
| readable | replies AgentPlay could read as a move |
| legal 1st | turns where the first reply was a legal move |
| lenient | replies read leniently (see below) |
| forfeits | games lost by too many bad replies in a row |
| s/move | seconds per reply (the scripted opponent takes almost no time) |
| cost | what the games cost; local models are free |
It recommends the setting with the fewest forfeits, then the most legal first tries, then the fastest. When no setting finishes every game, it says so, shows the most common error, and exits with code 1.
A variant the agent already has is skipped, with the reason under the table: +format_hints
when it already uses that wrapper, +constrained when it is already constrained or its adapter
cannot be.
Options: --games N (games per world per setting, default 2), --worlds rps,chess,
--out DIR (default runs/model-check), --workers N and --budget USD. For a paid model it
prints the most the check can cost before it starts. The games use fixed seeds, so a second
check of the same model plays the same openings; finished games are reused, not played again.
Constrained output¶
- id: x
use: ollama
config: {model: "qwen2.5:3b", constrain: true}
With constrain: true, AgentPlay asks the model server for structured output: the server
only lets the model write a JSON reply whose action is one of the legal moves. Every reply can
be read, and the move is legal unless the world rejects it for another reason. The prompt does
not change; only the reply format does.
- It works with
chat_apiand every preset built on it (ollama,openai,openrouter,geminiand the others), when the server supports structured output: Ollama 0.5 or later, llama.cpp, vLLM, LM Studio, OpenAI and Gemini do. Other agents rejectconstrain. - When the server does not support it, the run stops with the error code
provider.no_structured_output. - Use it instead of
json_mode, not with it. - With
tool_calls: true, theacttool's parameters carry the legal moves instead, and the model must call it. - Reports list a constrained model apart from the same model unconstrained:
ollama:qwen2.5:3b+constrained.
A constrained model can still play badly. It only stops it from writing replies that are not moves.
Lenient reading¶
Every model's reply is read by the same parser, so models are compared fairly. Besides a JSON
object with action, it reads:
| Reading | Example | Read as |
|---|---|---|
json |
{"action": 4} |
4 |
text |
Sure! {"action": 4} |
4 |
bare |
4 |
4 |
other_key |
{"move": 4} (also answer, choice, play, Action) |
4 |
list |
{"action": [4]} |
4 |
prose |
I will take square 4. |
4 |
The last three are lenient readings, new in 0.15:
- other_key needs exactly one of those keys.
- list needs a list of one legal move.
- prose needs a reply with no JSON in it that names exactly one legal move as a whole word.
Letter case does not matter, and in chess + and # are ignored. A reply that names two
legal moves, such as "rock beats scissors", is not read; the error says which moves it named
and shows a valid reply.
The log records how each reply was read, as read on the action event, and the
behaviour metrics count lenient readings as lenient_read. To compare with runs
made before 0.15, turn lenient reading off:
config: {model: "qwen2.5:3b", strict_replies: true}
Other settings that help¶
wrap: [format_hints]: after a rejected reply, the next request shows a valid reply built from the legal moves (wrappers).limits.max_illegal: 5: more tries before a forfeit.- A lower
temperature, such as 0.3.