cd /news/ai-agents/state-machines-skills · home › topics › ai-agents › article
[ARTICLE · art-176348] src=adamgrant.micro.blog ↗ pub= topic=ai-agents verified=true sentiment=↑ positive

State Machines > Skills

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.

key 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.

read4 min views2 publishedNov 25, 2026

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.

When 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.

The 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.

That is what I rebuilt Flux Player (original write-up) to do.

The Problem With Giant Skills #

A 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.

Three things break reliably:

  1. Attention Decay: Rules for Step 6 get drowned out by noise from Steps 1 to 4.
  2. State Spoofing and Skipping: Nothing mechanically stops an agent from jumping straight to “done” when a check hasn’t actually passed.
  3. 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.

Thin Skill + Flux Cartridge #

In Flux v3, your skill shrinks to a few lines:

Run flux start. Follow ONLY the active state’s instructions. Advance via flux step <TARGET>.

Everything 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:

  • Just-In-Time Craft Prompts: Flux only outputs the instructions, tone rules, andBAD vs.GOOD examples needed for thecurrent state, right when the agent enters it.
  • Persona and Model Pinning: Each state specifies the exact virtual persona, role boundary, and model tier (opus ,sonnet ,haiku ) required for that step.
  • 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.
  • Predetermined Failure Routing: If a guardrail fails, Flux blocks the transition, emits a predeterminedfail_prompt populated with{errors} and{attempt} , and routes to.SELF (retry),.BACK (pop the history stack), or an upstream recovery state aftermax_retries .

Here is what a minimal YAML guardrail looks like:

states:
  IMPLEMENT:
    persona: Staff Engineer
    model: sonnet
    expected_outputs: [src/app.py]
    prompt: |
            Implement the plan in PLAN.md with tests. Leave zero TODOs in src/.
    transitions:
      - target: REVIEW
        when: Implementation and tests pass
        guards:
          - command: uv run pytest -q
          - type: file_not_contains
            path: src
            pattern: "TODO|FIXME"
            regex: true
        on_fail: .SELF
        max_retries: 3
        on_max_retries: .BACK
        fail_prompt: |
          Checks failed (attempt {attempt}/{max_retries}):
          {errors}          
        max_retries_prompt: |
                    Failed {attempt} times. Rolling back to revise PLAN.md first.

Real-World Example: Moving a Graphic Novel Studio Onto Flux #

I 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.

Before 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."

Moving the pipeline into an 18-state Flux cartridge (cartridge.py) solved this cleanly:

  1. 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).
  2. 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.
  3. 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, andHAIKU 5.5 runs zero-image bash orchestration, layout pagination, and EPUB packaging, with automaticon_fail rollbacks toSTAGE_8_RENDER_OCR whenever Vision QA flags a page.

Skills are great for telling an agent that a workflow exists. State machines are how you make the workflow actually hold together.

When 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.

You can check out the updated Flux v3 repo here: github.com/adamjgrant/fluxplayer.

── more in #ai-agents 4 stories · sorted by recency
── more on @adam grant 3 stories trending now
sponsored brought to you by zahid.host 4,200+ EU-deployed projects
reading about agents? ship yours in a single git push.

Run your AI side-project on zahid.host

EU-based hosting, git-push deploys, automatic HTTPS, no cold starts. Free tier with a custom domain — perfect for shipping the agent you just read about.

$git push zahid main
→ Live at https://your-agent.zahid.host ✓
Get free account → Pricing
from €0/mo · no card required
LIVE [news/state-machines-skill…] indexed:0 read:4min 2026-11-25 · —