Manabot
Manabot is a project to train superhuman Magic: The Gathering bots.
It has two halves:
- managym (Rust): a deterministic rules engine built for learning. It handles fast batched stepping, exact clone/fork for search, replay, and per-player observations that keep hidden information hidden. Python bindings come through PyO3.
- manabot (Python): the agents. It includes self-play training, search, belief models over hidden cards, and an arena for evaluating checkpoints against fixed opponents.
We are currently focusing on a very small but fairly complicated set of decks: UR Lessons versus GW Allies, from the Avatar: The Last Airbender set.
Built with two companion projects from Loopflow Studio:
Technical approach
A rules engine built for learning. managym runs a full game of Magic: priority, the stack, combat, triggers, and state-based actions. It is deterministic given a seed, steps many games in lockstep, and can clone a game state exactly. That makes batched self-play, search over possible futures, and replay verification cheap. At every decision it gives each player an observation of only what that player can see: players, cards, and permanents as typed objects, plus the list of legal actions with the objects each one targets.
Cards as typed programs. Cards are not parsed from Oracle text and not hand-coded per card name. Each card is authored as a typed program (content/semantic/), compiled to an IR, and run by a generic interpreter that rejects anything it cannot execute. The model can embed what a card does as well as its name, and most new cards are content changes rather than engine changes. Rules behavior is pinned by conformance fixtures (conformance/).
Versioned worlds. The observation and action encoding is versioned as a world (WORLDS.md). Checkpoints only load in the world they were trained in, and a nightly learnability check catches encodings that make two different choices look identical.
One network, one action head. One network encodes every visible object, mixes them with attention, and scores each legal action together with its focus objects. A value head predicts the game outcome. Every decision, from casting and targeting to attacking, blocking, and paying costs, goes through that single action head.
Self-play from terminal reward. The agent plays both decks against current copies of itself, and many games step in lockstep so that inference is batched. The update is a clipped policy gradient, regularized toward both the collection policy and a fixed reference policy, with advantage filtering, annealed step sizes, and an EMA of the weights for evaluation. Those choices follow Ataraxos (Sokota et al., 2026), and each one is a separate switch that we test on Magic rather than adopt on the paper's authority (research program). Reward is win or loss only: our shaped rewards lost to it (exp-04).
Hidden information and search. Belief samplers learn a distribution over the opponent's hidden cards from a frozen policy's own games (belief sampler). Search samples hands from that belief, uses the frozen policy for continuations, and distills its choices back into the policy (local policy search). This runs end to end but has not yet shown a strength gain over the policy alone.
Evaluation by head-to-head play. Trained agents play each other. A
Tournament file names a roster of checkpoints and fixed opponents, and the
runner plays every pairing on the same held-out deals, with both decks and
both seats (head-to-head). The arena fits
ratings across the whole population (manabot/arena/), and a rule-based
heuristic bot gives a stable reference point across runs. Every game is
replay-verified.
Preregistered experiments. The question, numeric prediction, kill criteria, and cost cap are committed to git before a run; without that commit a result is exploratory, not evidence. Frozen contracts record the hashes of their inputs, claims about a training method need independent training seeds, and refutations stay on the record (experiments/).
Right now the main open question is the training curriculum: which matchups, opponents, and mix of self-play the agent should learn from (for example, mirror matches versus balanced cross-deck play). Evaluation is kept narrow, just enough to compare curricula, rather than testing current agents across a wide range of environments.
Versioned installs
Versioned PyPI release preparation, platform support, CPU/CUDA installation and maintainer publishing are described in the release guide. The first planned release is 0.2.0; the source workflow below remains available.
Quickstart
You need uv and a Rust toolchain.
git clone git@github.com:loopflowstudio/manabot.git
cd manabot
uv sync --python 3.12 --extra dev
uv run --extra play maturin develop --release \
--manifest-path managym/Cargo.toml --features python
uv run manabot train # small CPU training run, under a minute, no W&B
uv run manabot train trains a small agent and saves checkpoints to
.runs/local/. Training recipes are typed regimes composed in Python, one module per
current experiment in experiments/, from reusable parts in
manabot/training/builders.py. The current GPU
baseline is
uv run manabot train --regime-name batched_baseline --out .runs/batched/run.
manabot/README.md covers presets, remote GPU runs,
simulation, and evaluation.
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.
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 the opponent seat's decisions in self-play. 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 | Learner decisions | Decisions per iteration × iterations | Hardware |
|---|---|---|---|---|---|
| first-light PPO (report) | 2026-03 | width 64 | 262k | 512 × 512 | CPU |
| matched-cost PPO (exp-03) | 2026-07 | 100k params | 5.8M | 2,048 × 2,850 | M4 Max |
small-26k (capacity) |
2026-10 | 64×2, 188k params | 13.3M | 512 × 26,000 | 1× L4 |
small-63k, continued |
2026-10 | 64×2 | 32.3M | 512 × 63,000 | 1× L4 |
small-100k, continued |
2026-10 | 64×2 | 51.2M | 512 × 100,000 | 1× L4 |
| scale ladder v1, one seat (ladder) | 2026-10 | 64×2 | 196.6M | 16,384 × 12,000 | 1× L4, $13.34 |
The first two rows predate the current world and encoding, so they record
scale only. The ladder run's $10 checkpoint (151.6M decisions) scored 0.69
against the heuristic anchor across the four deck matchups, and 0.70 as
Lessons against Allies. The run was closed before its $50 tier, once
self-play moved to learning from both seats.
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.
Earlier results
Before self-play became the main loop, the project leaned on search. These results come from that period and from earlier encodings, so their numbers are not comparable with today's checkpoints:
- Search was strong and cheap. Flat determinized Monte Carlo with 256 rollouts beat random 99% of the time. Every early trained policy was weaker than 16-rollout search (exp-02).
- Distillation beat PPO at equal cost, 90.5% versus 52.7% against random (exp-03). Naive expert iteration did not compound: round 1 lost 74–26 to round 0 (exp-07).
- Reward shaping hurt. Terminal-only reward beat our shaped rewards by about 15 points (exp-04).
- Win rate hid incompetence. The search pilot could not play a control deck: it found the right line at most 39% of the time in competency scenarios, and random beat it in 3 of 5 (exp-09). Matchup tables mostly measured the pilot and card quality (exp-08b).
Not built yet
- More cards. Because cards are typed programs, most new cards can be added as content without engine changes, but the pool is still two decks.
- Limited. The long-term target is sealed and draft play: building decks from a pool, then piloting them. Nothing in the repository drafts or builds decks yet.
Map of the repository
| Path | What it is |
|---|---|
managym/ |
Rust rules engine, vectorized env, and PyO3 bindings (README) |
manabot/ |
Agents: models, training, search, beliefs, arena, verification (README) |
experiments/ |
Preregistered experiment reports, protocols, and data |
content/ |
Card and deck definitions compiled to a typed IR |
conformance/ |
Rules conformance fixtures |
docs/ |
Architecture, training operations, rules, and research notes (index) |
paper/ |
A working paper draft |
ops/, deploy/ |
Remote training hardware and deployment |
academy/, academy/ui/, protocol/ |
Local browser UI for testing a bot by hand and reviewing replays |
wave/, .lf/ |
Loopflow Waves, Flows, and skills that organize agent work |
docs/ARCHITECTURE.md has the full system design. In short, managym owns the rules and legality, manabot owns inference and decisions, and the play UI only displays what managym allows the viewer to see.
Development
# 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).
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.0
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.0.tar.gz | 1.5 MB | With provenance | Details for manabot-0.2.0.tar.gz |
Built distributions (wheels)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| manabot-0.2.0-cp312-cp312-manylinux_2_28_x86_64.whl | CPython 3.12 | CPython 3.12 | Linux glibc 2.28+ x86-64 | Details for manabot-0.2.0-cp312-cp312-manylinux_2_28_x86_64.whl |
| manabot-0.2.0-cp312-cp312-macosx_11_0_arm64.whl | CPython 3.12 | CPython 3.12 | macOS 11.0+ ARM64 | Details for manabot-0.2.0-cp312-cp312-macosx_11_0_arm64.whl |
Total release size: 7.5 MB
Release files / manabot-0.2.0.tar.gz
| Download URL | manabot-0.2.0.tar.gz |
|---|---|
| Size | 1.5 MB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
740b889c6baccafc411faadf803a0bd402721442a7698c8be6b4e4c89da677da
|
|
BLAKE2b-256 checksum How to use checksums |
8d0835fd3560a990da4daa5deb77cb49ecd83a366b1d07c07a72916f4c0967a0
|
| 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 Oct 22, 2026.
Transparency logRelease files / manabot-0.2.0-cp312-cp312-manylinux_2_28_x86_64.whl
| Download URL | manabot-0.2.0-cp312-cp312-manylinux_2_28_x86_64.whl |
|---|---|
| Size | 3.1 MB |
| Tags | CPython 3.12 Linux glibc 2.28+ x86-64 |
|
SHA-256 checksum How to use checksums |
a4f3bbbf643799d3d2e89374a3cb3676b5b174dc97471ef371f87a9e8444d0d9
|
|
BLAKE2b-256 checksum How to use checksums |
c245525ebe3fe573b7f94a3b8742c576ea34c606e35b2d9148bbbaec0314b957
|
| 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 Oct 22, 2026.
Transparency logRelease files / manabot-0.2.0-cp312-cp312-macosx_11_0_arm64.whl
| Download URL | manabot-0.2.0-cp312-cp312-macosx_11_0_arm64.whl |
|---|---|
| Size | 2.9 MB |
| Tags | CPython 3.12 macOS 11.0+ ARM64 |
|
SHA-256 checksum How to use checksums |
aa6a7741ed7fd2a15b4a12b8979900cf5cd1a57712375241cde98cc627f46adb
|
|
BLAKE2b-256 checksum How to use checksums |
49a041249739ec5ecb909a2543d7f1302413e2cc37d88b89fb90b073436d7001
|
| 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 Oct 22, 2026.
Transparency logSecurity for manabot 0.2.0
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
All 3 files in this release have been uploaded with provenance metadata.
Attestation for manabot-0.2.0.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 Oct 22, 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.