Manabot
Manabot is a project to train superhuman Magic: The Gathering bots. A manabot learns by playing itself: it sees only what a player would see, chooses among the legal actions, and finds out who won when the game ends. Nobody tells it which plays were good, and three things make that hard:
- The opponent learns too. The best play depends on a policy that keeps changing, so a good win rate against the latest self says little.
- Actions aren't a fixed list. A legal action can name any object in play, so the network scores what's offered rather than filling a fixed output layer.
- Cards change the rules. Each pairing of decks is close to its own game, and a new card can add a rule.
Built with two companion projects from Loopflow Studio:
- The system
- What it trains on now
- How a manabot learns
- How strength is measured
- Contracts the code enforces
- Beside the loop
- Scale
- What we know
- Not built yet
- Quickstart
- Experiment data
- Guides and map
The system
- The rules engine (
managym/, Rust;import managymin Python) runs full games of Magic, many at once, deterministically from a seed. It owns card meaning, match state, legality, decisions and Commands, committed events, viewer-safe observations, replay, exact forks and the hidden-hand domain. It plays forced choices itself and never chooses among a learner's legal actions. Every card is one Rust function in the engine's own rules types, so a new card is content and new behavior is a new rules variant, never card-specific logic (the rules engine). - The policy network (
manabot/model/) embeds every visible object, including what each card does, mixes them with attention, and scores each legal action with the objects it names through one action head. A value head predicts the outcome (observations and the policy network). - The learner (
manabot/training/) turns finished games into one weight update per batch (how a manabot learns). - Evaluation (
manabot/eval/) measures strength on held-out deals from outside the loop. Its scores never enter the loss (evaluation).
Two more pieces sit around the loop. Academy (academy/, academy/ui/)
is the browser UI for inspecting a bot or a replay by hand; it owns transport,
drafts and presentation, reconstructs no rules meaning, and nothing in
training depends on it (Academy). Etude launches remote
training and evaluation and records what they produce; the machine is chosen
at launch, never in the experiment (training).
Inside manabot/, sim runs games and registered players, eval scores and
rates, training learns, experiment declares and executes comparisons, and
infra.identity owns canonical byte identities. Imports follow one direction:
Academy may import manabot and managym, manabot imports managym and never
Academy, managym imports neither, and manabot.sim imports none of eval,
training, experiment or reports (tests/test_package_boundaries.py
enforces all of it). The observation and action encoding is versioned as a
world (WORLDS.md); checkpoints load only in the world they were
trained in.
What it trains on now
The current world is Avatar: The Last Airbender Limited. Every card in the
set is defined as a typed rules program (336 supported in
world w17), and training draws both seats of each game at random
from real trophy decks: 134 seven-win Premier Draft lists admitted whole from
the 17Lands public dataset (CC BY
4.0), built by experiments/tla_corpus.py and
frozen in the pilot's corpus and
regime
(protocol).
The pilot's question is whether the recipe learns on a population of real decks at all. Its first run learned for five updates before a capacity limit stopped it, and no trained checkpoint on this population exists yet (pilot evidence). The curriculum questions that follow, which matchups, opponents and mix of self-play to learn from, are in the research program. Earlier runs trained on one fixed matchup, UR Lessons versus GW Allies, which the older reports and the local evaluation check still use.
How a manabot learns
The only feedback is who won. Each iteration has four steps:
- Play. Many games step in lockstep so inference is batched, and one network plays them. By default both seats learn.
- Assign credit. The game result becomes a per-decision advantage and a value target, computed once with generalized advantage estimation.
- Filter. Only decisions with the largest advantages, about a quarter of the batch, stay in the update.
- Update. One pass of a clipped policy gradient, regularized toward both the policy that played the batch and a fixed reference policy. The batch is then discarded.
An EMA of the weights and annealed step sizes complete the recipe. Each piece has a source and is a separate switch we test on Magic rather than adopt on a paper's authority (influences). Reward is win or loss only: shaped rewards bought nothing over it (exp-04). How a manabot learns walks each step down to the code.
How strength is measured
Two players meet on the same seeded deal four times, swapping decks and seats,
and only finished, replay-verified games count. Uncertainty resamples whole
deals. A rule-based heuristic bot and frozen checkpoints anchor the scale,
ratings are fit across the whole population, and tactical scenarios and
bounded attacks probe what a win rate hides (evaluation).
Most runs are exploratory and need no prediction. A result cited as a finding commits its question, numeric prediction, refuting result and cost cap to git before the run, and claims about a method need independent training seeds. Refutations stay on the record (experiments).
Contracts the code enforces
One rules authority. Only managym commits a state transition. A transition
is (revision N, decision N) + Command(expected=N) → committed events + revision N+1; a Command against another revision fails closed
(SemanticError::StaleRevision). Academy, a person or a manabot selects a
Command; none patches state, invents legality or re-derives what a viewer may
see. Academy's live play still lowers its protocol-v1 Command to a
positional step through DecisionContext.action_by_offer; the semantic
DecisionFrame / Command / TransitionReceipt contract in
managym/src/decision.rs is the engine API, not yet Academy's wire path
(experience protocol v1).
Forced decisions are played by the engine. A decision reaches a player
only with at least two legal actions (skip_trivial, on everywhere). Every
decision count in this repository excludes forced choices.
Observations are viewer-safe at the source. Observation::for_player
holds everything one seat may see and nothing else; legal actions appear only
in the chooser's view; decklist disclosure lives on PlayerConfig.disclosure.
Viewer-equivalent states produce byte-identical observations. The policy
tensor, the LLM text and the learning tokens all derive from the same
observation, and a mechanic reaches all three in the change that adds it
(observations).
Identity is typed. An ObjectRef carries its incarnation and fails after
a zone change. An action index is valid only in one decision epoch. Checkpoints
bind world, deck setup and input schema and load only where the digest
matches. Every durable value has a canonical serialization and digest
(manabot.infra.identity), and locators are not identity.
Replay is exact. A game regenerates from its deal seed, configuration and Commands, and every pre- and post-state digest must match. RNG streams derive from recorded seeds, so scheduling cannot select an outcome. Evaluation scores only replay-verified terminal games (forks, replay and determinization).
Branching is a full clone. Search forks a Game by cloning it and steps
the clone; a rules-only witness checks the source is untouched. Determinized
search is named as such: separate perfect-information trees per sampled world,
aggregated at the root, with no claim to information-set consistency.
Hidden information has one domain. managym/src/possible_worlds.rs owns
the hidden-hand domain, the five-variant WorldQuery, compatible-deal weights
and materialization; manabot.belief owns probability over that domain. A
query never reveals whether the actual hidden hand satisfies it, and empty
support is an explicit result.
Training is declared data. A TrainingRegime (one module per experiment
under experiments/) names the world, decks, model and ordered stages; one
runner executes it, writes world-bound raw and EMA checkpoints, records every
attempt in VerifyStore, and ships metrics through Etude. Regimes refuse
belief inputs; the trained model sees the current observation only
(training).
Evaluation never promotes. A player is an immutable PlayerRegistration;
a rating belongs to one EvaluationKey (world, content suite, viewer
boundary, arena version, compute class) and never crosses it. Candidates play
the same deals with seats and decks swapped, uncertainty resamples whole
deals, and a seat-aware Bradley-Terry fit gives local Elo coordinates with
heuristic and frozen checkpoints as working anchors. No win rate, rating or
report promotes a checkpoint; scores never enter the loss.
Findings are preregistered. A result cited as a finding commits its question, prediction, refuting result and cost cap before the run; everything else is exploratory and says so. The training seed is the unit of evidence for a method; refutations stay on the record.
Beside the loop
These exist and run, and none of them is on the training path today.
- Search players (
manabot/sim/search).flat_mc.make_playerbuilds every kind from a spec:search(flat Monte Carlo over determinized worlds, no network),determinized_puctandagent_puct(one tree per sampled world, values as win scores, not information-set-consistent),policy_search,value_greedy,value_search, andlocal_update.LocalUpdateTeacheris the current search-improvement code: for one checkpoint it maximizesΣ p(a)Q(a) − α KL(p‖uniform) − β KL(p‖base)over rolled-out worlds, following Ataraxos supplement S3.7, and retains a replayable receipt (local-update usage). Worlds come from the compatible-deal prior, a learned sampler, or the small exact tracker. None has shown a strength gain over the policy alone. - Beliefs (
manabot/belief).managym/src/possible_worlds.rsowns the hidden-hand domain;manabot.beliefputs probability on it:BeliefStateover onePossibleWorldSpace, a tracker fed by viewer observations, and theAutoregressiveBeliefSampler, which learns opponent hand counts from a frozen policy's games. Thecollect_beliefandtrain_beliefstages fit it on an immutable dataset (uv run manabot train --regime-name belief_sampler --seed 421 --out .runs/belief-pilotis the bounded pilot), andpython -m manabot.reports.beliefscores a sampler by held-out joint NLL, Brier and calibration. Consumers are search players and a demo seam only;ActorCritichas an optional belief channel that regimes reject, and Academy's live belief tracking was removed. Detail: search-and-beliefs.md at 055dddab1. - Academy Study (
academy/study_branch.py, the replay page) forks a retained engine root, executes structured Commands on the clone, proves source and sibling isolation, and returns through a consuming receipt. Its decision evidence is fixture-served. - LLM players (evaluation) read the text observation and choose Commands through the same authority as everyone else.
Scale
Training scale per agent, measured in learner decisions: the decisions the learning policy made and trained on. Decisions with a single legal action are played automatically and not counted, and neither are a frozen opponent's; when both seats learn, both seats count. This unit does not depend on model size or batching, unlike iterations or Adam steps, and does not depend on hardware, unlike dollars or hours. We add a row when a run sets a new high.
| Agent | Date | Model | Parameters | Learner decisions | Decisions per iteration × iterations | Hardware |
|---|---|---|---|---|---|---|
| first-light PPO (report) | 2026-03 | width 64, no attention | not recorded | 262k | 512 × 512 | CPU |
| matched-cost PPO (exp-03) | 2026-07 | width 64, no attention | 50,306 | 5.8M | 2,048 × 2,850 | M4 Max |
small-26k (capacity, head-to-head) |
2026-10 | 64 wide × 2 attention layers | 188,482 | 13.3M | 512 × 26,000 | 1× L4 |
small-63k, continued |
2026-10 | 64×2 | 188,482 | 32.3M | 512 × 63,000 | 1× L4 |
small-100k, continued |
2026-10 | 64×2 | 188,482 | 51.2M | 512 × 100,000 | 1× L4 |
| scale ladder v1, one seat (ladder) | 2026-10 | 64×2 | not retained | 196.6M | 16,384 × 12,000 | 1× L4, $13.34 |
| MTG-183, ten Elemental decks, both seats (protocol) | 2026-10 | 64×2 | 196,482 | 331.2M | ≈55,700 (complete games) × 5,950 | 1× L4, four rental segments, $50 cap |
The parameter count of a 64×2 network depends on its inputs, not only its
width and depth. The card encoder's token vocabulary adds 64 parameters per
distinct learning token, card names among them, which is the 8,000 between the
two-deck and ten-deck runs. The fact encoder and the shared-effect encoder
each hold about 0.8M parameters in hash-bucket embedding tables, so
the current TLA recipe has 1,883,650 with the same 64×2 attention core.
The first two rows predate the current world and
encoding, so they record scale only. The one-seat ladder's $10 checkpoint
(151.6M decisions) scored 0.69 against the heuristic anchor and 0.70 as
Lessons against Allies; it was closed before its $50 tier once self-play
moved to learning from both seats, and MTG-183 is the two-seat run that
followed.
Learning-rate schedules currently count iterations, not decisions. The same
recipe run at a different batch size therefore decays at a different number
of decisions: about 18M for small-100k versus about 575M for the ladder recipe.
What we know
All numbers belong to the world they were measured in, and most come from one training seed, so they guide the next experiment rather than settle a method. Earlier findings are tabulated in the research program.
- One seed on ten decks kept improving for 331M decisions. MTG-183 trained
a 64×2 network from both seats on the ten-deck Elemental world (w13). Its
score against the
heuristicanchor on the full 10×10 deck grid rose from 0.065 to 0.801 over 5,950 updates, and its rating from 525 to 1,248 Elo with the heuristic at 1,000. When the heuristic score flattened after update 3,600, newer checkpoints still beat older ones: the endpoint scored 0.591 [0.569, 0.612] against update 2,000 and 0.532 [0.511, 0.554] against update 3,600, with no significant intransitive triangles among 27 rated checkpoints (protocol; rating report inexperiments/data/mtg183-rating/). - Claude Haiku played that checkpoint to a draw. Haiku 5.5 with high reasoning won 51 of 100 games against MTG-183's final policy, at $0.37 per game and a median 1.4 seconds per decision (Haiku versus MTG-183).
- The anchors are moving targets. A rewrite of the
heuristicbot took it from 18.3% to 62.0% as UR Lessons against MTG-183's update-1,750 checkpoint, and from 10.8% to 34.3% as each of the ten decks against its GW and UB seats, without slower decisions (heuristic strength). Ratings are pinned to an anchor version and a world, never compared across them. - Learning from both seats replaced one-seat training. The one-seat ladder reached 0.69 against the heuristic at $10 (scale ladder); matched per learner decision over four seeds per arm, two-seat learning was no worse and reached the same score about 1.4× sooner (seat comparison).
- Batching is the reliable speedup, and the smallest model kept up. 64×2 took 109–111 minutes at 4 streams and about 5 at 256; larger models showed no advantage at this horizon, on two seeds (longer learning). Collection is 82.5% of training time (training time).
- The trophy population is untested. The TLA pilot's initialization scored 7–25 against the heuristic before its run stopped; there is no trained checkpoint on random real decks yet (pilot evidence).
- Search and beliefs run end to end but add no strength yet (beside the loop).
Not built yet
- A trained agent on the trophy population. The pilot's first run stopped at a permanent-capacity limit after five updates; its successor raises the capacity and recovers from oversized games, but hasn't run (pilot evidence).
- The full trophy population. The pilot corpus was frozen when 134 of 1,000 sampled lists admitted; the current world admits all 1,000, and no protocol or run uses the larger population yet.
- Limited. The long-term target is sealed and draft play: building decks from a pool, then piloting them. Piloting random trophy decks is the first half; nothing in the repository drafts or builds decks yet.
Not goals: a general-purpose Magic rules library independent of the training worlds; natural-language parsing or LLM authority over legality at runtime; multiplayer, general-sum play, Commander breadth or broad format legality; a second semantic authority anywhere, even as a compatibility layer; claiming that exact beliefs solve strategy fusion, or that one rating describes every matchup.
Quickstart
You need uv and a Rust toolchain. Development uses CPython 3.13; the library also supports ordinary CPython 3.12.
git clone git@github.com:loopflowstudio/manabot.git
cd manabot
uv sync --locked --python 3.13 --extra dev
uv run --extra play maturin develop --release \
--manifest-path managym/Cargo.toml --features python
uv run manabot train # two-update local smoke, capped at two minutes
uv run python scripts/inspect_batch.py # one real batch and how credit reaches each decision
uv run manabot train trains a small agent and saves checkpoints under
.runs/. The local recipe uses CUDA, then Apple MPS, when available and CPU
otherwise. --recipe baseline requires CUDA or Apple MPS and trains on that
accelerator; its evaluation and search run on CPU. --device cpu|mps|cuda
overrides local selection; baseline accepts only CUDA or MPS. MPS training uses
float32. This makes no speed or strength claim.
Training recipes are typed regimes composed in Python, one module per
current experiment in experiments/, from reusable parts in
manabot/recipes/builders.py. The current GPU
baseline is
uv run manabot train --regime-name batched_baseline --out .runs/batched/run.
docs/training.md covers running, monitoring and recovering
runs, and manabot/README.md covers the package.
There is also a local browser table (./scripts/play, needs Node) for playing
one game against a checkpoint or stepping through a replay. It is for
inspecting what a bot does, not a way to play Magic.
For an engine-only project, start with installing managym. For training, see installation and dependency choices. The release guide also covers supported platforms and CPU/CUDA selection. The 0.2.2 release notes cover the separate engine package; the 0.2.1 notes cover CPython 3.12/3.13 support and collector API migrations. The historical 0.2.0 release requires CPython 3.12.
Experiment data
Every number above traces to a report in experiments/
and the files behind it. Reports are in git; the result files are not.
experiments/data.manifest.json records
each file's path, size and SHA-256, and the bytes live once per digest in the
team's R2 store, so a checkout is small and a report's evidence is still exact:
uv run --extra artifacts python -m manabot.data fetch experiments/data/mtg183-rating # one report's files
uv run --extra artifacts python -m manabot.data fetch # everything
fetch needs the R2_* credentials from Doppler manabot/prd (prefix the
command with doppler run -p manabot -c prd --), verifies every digest and
refuses to overwrite a file whose bytes differ. Training and evaluation runs
themselves are tracked by Etude:
uv run etude report experiments/ --source r2://manabot/jobs --serve renders
every experiment's curves and matches from the job store, and
uv run etude eval experiments/elemental.py --source r2://manabot/jobs plays
whatever matchups a report still wants. How a question becomes a report, and
what makes a result count, is in experiments.
Guides and map
Each part of the system has one guide, written the same way: what it does, one worked example, the key terms with the code that implements them, then what we know and where the code lives.
| Guide | What |
|---|---|
| engine.md | The rules engine: one decision, forced choices, who chooses, observations, forks, replay, cards as programs, decks, worlds |
| observation-and-model.md | What the policy sees, how it scores legal actions and estimates value, the policy input layout |
| learning.md | How a manabot learns: play, batch boundaries, credit assignment, filtering, the loss, reading a run, down to the code |
| evaluation.md | One deal, what counts, anchors and ratings, scenarios, frozen-policy attacks, LLM players, shared inference, card data |
| experiments.md | How a question becomes a report: the claim rules, a worked example, failures worth reading, declaring a comparison |
| training.md | Running training: regimes and stages, remote training, monitoring, numerical health, recovery, game failures |
| experiment-metrics.md | Metric definitions the experiment reports read |
| workflows.md | Wave responsibilities, Coverage loops and experiment execution boundaries |
| development.md | Environment, validation by change area, CI, releases, clean-machine play, retained evidence |
| academy.md | The browser UI: running it, the shared decision surface, presentation, trained challengers, the proof gate |
| Path | What it is |
|---|---|
managym/ |
Rust rules engine, vectorized env, and PyO3 bindings (README) |
manabot/ |
Agents: models, training, search, beliefs, evaluation, verification (README) |
experiments/ |
Experiment modules, their reports, and data |
content/ |
Deck lists and card content notes |
conformance/ |
Active rules and replay fixtures; historical corpora in S3 |
docs/ |
The guides above and their diagrams |
paper/ |
A working paper draft |
deploy/ |
Hosted service deployment |
academy/, academy/ui/, protocol/ |
Local browser UI for testing a bot by hand and reviewing replays; protocol/ holds its wire protocol and schemas |
.lf/ |
Loopflow Waves (.lf/wave/), chapters and prompts that organize agent work |
Development
Read TESTING.md before running checks. Never intentionally induce load for testing.
# Rust (CI runs cargo test in debug, so validate in debug before landing)
cd managym && cargo fmt --check && cargo clippy --all-targets --all-features -- -D warnings && cargo test && cd ..
# Python
uv run --extra dev pytest tests/
Contributor and agent conventions are in AGENTS.md. Package style guides are in each package README.
Names
- manabot: the bot and the Python library. You train a manabot.
- managym: the rules environment the bot lives in.
- Academy: the local bot-testing UI (
academy/,academy/ui/). - Etude: the separate system that launches and records experiments
(
loopflowstudio/etude). Older documents also use Etude and Fantasia for this project. - Loopflow: the agent development tool
(
loopflowstudio/loopflow).
Licence
Manabot is licensed under the MIT licence.
Manabot is an independent research project and unofficial Fan Content permitted under the Wizards of the Coast Fan Content Policy. Not approved or endorsed by Wizards. Magic: The Gathering and its card names are property of Wizards of the Coast LLC.
Metadata
Release files for manabot 0.2.2
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| manabot-0.2.2.tar.gz | 910.5 kB | With provenance | Details for manabot-0.2.2.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| manabot-0.2.2-py3-none-any.whl | Python 3 | none | any | Details for manabot-0.2.2-py3-none-any.whl |
Total release size: 2.0 MB
Release files / manabot-0.2.2.tar.gz
| Download URL | manabot-0.2.2.tar.gz |
|---|---|
| Size | 910.5 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
3e19429636233f09346255f8d8645dd6aaca7421ecefe8736e47b92d15a31a78
|
|
BLAKE2b-256 checksum How to use checksums |
c925559cdf38bb25de10a0444e94245943051f4de20869998cca80e6325a18a2
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.16
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Nov 12, 2026.
Transparency logRelease files / manabot-0.2.2-py3-none-any.whl
| Download URL | manabot-0.2.2-py3-none-any.whl |
|---|---|
| Size | 1.1 MB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
f09bc32a14a11d6e56bce4c61e446c8c337cf55c3aad478901b6fa9b6174dca8
|
|
BLAKE2b-256 checksum How to use checksums |
bd42c72bbd0b1741921484e4a77e49b718a9f84b1f14ce3e332af1713681a7ed
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.16
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Nov 12, 2026.
Transparency logSecurity for manabot 0.2.2
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
Full provenance
Both files in this release have been uploaded with provenance metadata.
Attestation for manabot-0.2.2.tar.gz
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Nov 12, 2026.
Transparency logA note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.