{"slug": "state-machines-skills", "title": "State Machines > Skills", "summary": "Developer Adam Grant rebuilt his open-source Flux Player tool as Flux v3, replacing large SKILL.md instruction files for coding agents such as Claude Code, Cursor and Antigravity with a deterministic state machine defined in a cartridge.yaml or cartridge.py file. Flux v3 persists sessions in .flux/state.json, emits just-in-time prompts for only the active state, pins a persona and model tier (opus, sonnet or haiku) per state, and gates transitions on shell commands like pytest, file and regex assertions, and JSON/YAML schema checks, with failures routed to .SELF, .BACK or an upstream recovery state after max_retries. Grant says the approach addresses attention decay, state spoofing and improvised recovery that he observed when 300-line skills degraded by Turn 12 of a multi-step workflow.", "body_md": "If you build complex multi-step workflows for coding agents (Claude Code, Cursor, Antigravity), you have probably run into the same wall I kept hitting: **giant `SKILL.md` files decay.**\n\nWhen you front-load 300 lines of instructions, edge cases, and formatting rules into a skill at Turn 1, it looks great on paper. By Turn 12, after tool outputs, file reads, and subagent handoffs have filled the context window, the LLM starts skimming. It rushes past the setup, forgets the pacing rules, skips a validation step, or invents its own shortcut.\n\nThe fix isn’t a longer skill. **It’s replacing the giant skill with a thin wrapper, or no skill at all, and putting a deterministic state machine in charge.**\n\nThat is what I rebuilt [Flux Player](https://github.com/adamjgrant/fluxplayer) ([original write-up](https://adamgrant.micro.blog/2026/11/25/flux-player-v-the-missing.html)) to do.\n\n## The Problem With Giant Skills\n\nA traditional skill is a **static wall of text**. It dumps every phase of a workflow (research, planning, implementation, review, QA, packaging) into the model’s lap at once and hopes the model stays disciplined across 20+ turns.\n\nThree things break reliably:\n\n1. **Attention Decay:** Rules for Step 6 get drowned out by noise from Steps 1 to 4.\n2. **State Spoofing and Skipping:** Nothing mechanically stops an agent from jumping straight to “done” when a check hasn’t actually passed.\n3. **No Deterministic Recovery:** When an output fails to pass muster, you don’t get a predetermined rollback and remediation prompt. You get whatever improvisation the LLM feels like trying next.\n\n## Thin Skill + Flux Cartridge\n\nIn Flux v3, your skill shrinks to a few lines:\n\n*Run `flux start`. Follow ONLY the active state’s instructions. Advance via `flux step <TARGET>`.*\n\nEverything else lives in a **cartridge** (`cartridge.yaml` or `cartridge.py`) that defines the state machine. Instead of trusting the LLM to remember the whole playbook, Flux persists the session in `.flux/state.json`, tracks history on a stack, and acts as a strict runtime referee:\n\n- **Just-In-Time Craft Prompts:** Flux only outputs the instructions, tone rules, and`BAD` vs.`GOOD` examples needed for the*current* state, right when the agent enters it.\n- **Persona and Model Pinning:** Each state specifies the exact virtual persona, role boundary, and model tier (`opus` ,`sonnet` ,`haiku` ) required for that step.\n- **Mechanical “Pass Muster” Guardrails:** Transitions are gated by real checks: shell commands (`pytest` , linters), file/regex assertions, JSON/YAML schema checks,`expected_outputs` , or Python validator functions.\n- **Predetermined Failure Routing:** If a guardrail fails, Flux blocks the transition, emits a predetermined`fail_prompt` populated with`{errors}` and`{attempt}` , and routes to`.SELF` (retry),`.BACK` (pop the history stack), or an upstream recovery state after`max_retries` .\n\nHere is what a minimal YAML guardrail looks like:\n\n```\nstates:\n  IMPLEMENT:\n    persona: Staff Engineer\n    model: sonnet\n    expected_outputs: [src/app.py]\n    prompt: |\n            Implement the plan in PLAN.md with tests. Leave zero TODOs in src/.\n    transitions:\n      - target: REVIEW\n        when: Implementation and tests pass\n        guards:\n          - command: uv run pytest -q\n          - type: file_not_contains\n            path: src\n            pattern: \"TODO|FIXME\"\n            regex: true\n        on_fail: .SELF\n        max_retries: 3\n        on_max_retries: .BACK\n        fail_prompt: |\n          Checks failed (attempt {attempt}/{max_retries}):\n          {errors}          \n        max_retries_prompt: |\n                    Failed {attempt} times. Rolling back to revise PLAN.md first.\n```\n\n## Real-World Example: Moving a Graphic Novel Studio Onto Flux\n\nI recently stress-tested this on my multi-volume educational **Graphic Novel** skill: a pipeline with a Showrunner, Curriculum Architect, Dialogue Screenwriter, Panel Formatter, OCR Pre-Screener, two tiers of Vision QA, and an EPUB packager.\n\nBefore Flux, even with a detailed `SKILL.md`, the generated Volume 1 script rushed straight into system acronyms on Page 1, teleported characters into a whiteboard lecture on Page 2 without establishing their relationship, and rattled off definitions instead of letting the student character ask *“Wait, I don’t get it.\"*\n\nMoving the pipeline into an **18-state Flux cartridge** (`cartridge.py`) solved this cleanly:\n\n1. **Dynamic Just-In-Time Prompts:**`STAGE_5A_SCREENWRITER` swaps its prompt dynamically between Volume 1 (enforcing a 3-page Hollywood opening crescendo before any diagrams appear) and Volumes 2+ (continuity re-entry).\n2. **A Dedicated `STAGE_5A_READER_PROXY` Gate:** Before panel formatting even begins, a Script Doctor state checks the screenplay for gentle*“you can think of it like…\"* explanations, at least three*“Wait, what does that mean?\"* student pushbacks, and zero leaked CamelCase keys or insider jargon.\n3. **Token-Tier and QA Control:**`OPUS 5.5` runs once for the Master Showrunner (`STAGE_3_SHOWRUNNER` ),`SONNET 5.5` handles curriculum, dialogue, and likeness QA, and`HAIKU 5.5` runs zero-image bash orchestration, layout pagination, and EPUB packaging, with automatic`on_fail` rollbacks to`STAGE_8_RENDER_OCR` whenever Vision QA flags a page.\n\nSkills are great for telling an agent *that* a workflow exists. **State machines are how you make the workflow actually hold together.**\n\nWhen you move the rules out of a giant static prompt and into a Flux cartridge, the LLM stops juggling 18 steps in its head. It just does the one job in front of it, passes the gate, and moves to the next state.\n\nYou can check out the updated Flux v3 repo here: [github.com/adamjgrant/fluxplayer](https://github.com/adamjgrant/fluxplayer).", "url": "https://wpnews.pro/news/state-machines-skills", "canonical_source": "https://adamgrant.micro.blog/2026/11/25/state-machines-are-better-than.html", "published_at": "2026-11-25 20:01:12+00:00", "updated_at": "2026-11-25 20:12:25.392372+00:00", "lang": "en", "topics": ["ai-agents", "ai-tools", "developer-tools", "large-language-models"], "entities": ["Adam Grant", "Flux Player", "Flux v3", "Claude Code", "Cursor", "Antigravity", "GitHub"], "also_reported_by": [], "takeaway": "Gate each agent state transition on mechanical checks (pytest, file/regex assertions, schema validation) with on_fail routing to .SELF, .BACK or an upstream state after max_retries, instead of front-loading a 300-line SKILL.md that decays by Turn 12.", "recommendation": null, "alternates": {"html": "https://wpnews.pro/news/state-machines-skills", "markdown": "https://wpnews.pro/news/state-machines-skills.md", "text": "https://wpnews.pro/news/state-machines-skills.txt", "jsonld": "https://wpnews.pro/news/state-machines-skills.jsonld"}}