# Model tiers

Yokai does not pin one model for the whole run. Each phase gets a capability tier, each tier lists agent and model candidates in order, and each turn takes the first candidate that opens.

## Why tiers

Renaming a field and redesigning a state machine do not need the same model. A tier describes how much capability a phase needs. Your settings map each tier to concrete agents and models. When a provider changes its lineup, you edit one list in `.koi/yokai.yml` instead of every phase.

Junji alone does not use tiers. When you run `/junji next`, the phase runs with whatever agent and model you have open.

## The pieces

- Tier: one of four bands, `low`, `medium`, `high` or `ultra`. `medium` is the default.
- Phase assessment: the tier chosen for one phase, with a one-line reason, approved by a human. On a JSON board it sits on the card as `"yokai": {"model-tier": "high", "reason": "..."}`.
- Candidate: one agent with an optional model, effort and speed, such as `{agent: claude, model: opus}`. A tier holds an ordered list of candidates; the first is preferred.
- Role: the kind of turn. Plan, coder, judge and seal use the phase tier unless you lift them. Repair, fix and triage (Diagnose) use `ultra` unless you set otherwise.

A tier is a band, not a model. Yokai treats model IDs as opaque strings that the agent supplies; it never interprets them.

## How a turn picks its candidate

<figure class="diagram" aria-labelledby="dg-tiers-caption">
<figcaption id="dg-tiers-caption">From phase tier to the agent that answers</figcaption>
<div class="diagram-frame" tabindex="0" role="region" aria-labelledby="dg-tiers-caption">
<svg viewBox="0 0 560 272" width="560" height="272" role="img" aria-labelledby="dg-tiers-title dg-tiers-desc">
<title id="dg-tiers-title">Tier resolution and the candidate walk</title>
<desc id="dg-tiers-desc">The phase tier from the board card selects a tier band. A role override in yokai.yml can lift the band for one kind of turn. The band lists candidates in order. The turn opens with the first candidate; if that candidate is unreachable, limited or unstable, Yokai records a skip and tries the second.</desc>
<defs><marker id="dg-tiers-head" viewBox="0 0 8 8" refX="7" refY="4" markerWidth="8" markerHeight="8" markerUnits="userSpaceOnUse" orient="auto-start-reverse"><path class="dg-head" d="M0 0 8 4 0 8z"/></marker></defs>
<rect class="dg-box" x="184" y="24" width="176" height="48" rx="4"/>
<text class="dg-label" x="272" y="48">Role override</text>
<path class="dg-line" d="M272 76V116" marker-end="url(#dg-tiers-head)"/>
<text class="dg-note is-start" x="288" y="96">roles.&lt;role&gt;.tier</text>
<rect class="dg-box" x="0" y="120" width="144" height="48" rx="4"/>
<text class="dg-label" x="72" y="144">Phase tier</text>
<path class="dg-line" d="M148 144H180" marker-end="url(#dg-tiers-head)"/>
<rect class="dg-box" x="184" y="120" width="176" height="48" rx="4"/>
<text class="dg-label" x="272" y="144">Tier band: high</text>
<path class="dg-line" d="M364 144H396" marker-end="url(#dg-tiers-head)"/>
<rect class="dg-box is-solid" x="400" y="120" width="160" height="48" rx="4"/>
<text class="dg-label is-reverse" x="480" y="144">1st candidate</text>
<path class="dg-line is-dashed" d="M480 172V212" marker-end="url(#dg-tiers-head)"/>
<text class="dg-note is-end" x="464" y="192">on skip</text>
<rect class="dg-box" x="400" y="216" width="160" height="48" rx="4"/>
<text class="dg-label" x="480" y="240">2nd candidate</text>
</svg>
</div>
</figure>

1. If you launched with `--agent`, `--model` or `--effort`, Yokai builds one candidate from those flags and skips the rest of this list.
2. Otherwise it finds the role's tier: `roles.<role>.tier` if set, else the phase tier for plan, coder, judge and seal, else `ultra` for repair, fix and triage.
3. It walks that tier's candidate list when the turn opens. If a candidate cannot open a session because it is unreachable, rate limited or unstable, Yokai writes a skip row to `ledger.jsonl` and tries the next one for the same turn.
4. A skipped candidate is not tried again until `tiers.retry_after_secs` passes (3600 seconds by default). If every candidate is skipped, the run halts.

A red test or a Build that does not converge is the work failing, not a reason to switch candidates. A missing effort or speed option is a notice, not a skip. An agent that dies mid-turn is an interrupt; the turn can reattach.

## Example settings

```yaml
# .koi/yokai.yml
model_mode: tiers
tiers:
  low:
    - agent: claude
      model: haiku
  medium:
    - agent: claude
      model: sonnet
    - agent: codex          # fallback if Claude is unavailable
  high:
    - agent: claude
      model: opus
  ultra:
    - agent: claude
      model: opus
      effort: max
roles:
  judge:
    tier: high
```

With this file, a `medium` phase codes with Sonnet and is reviewed by Opus. If the Claude adapter cannot open a session, the coder turn falls back to Codex with its default model.

`model_mode: single` means you chose One model in setup: the same agent and model fill all four bands.

## Who chooses the tier

Yokai proposes a tier and a reason for each unfinished phase during setup, or the optional `/yokai assess` helper does it from chat. You approve with Approve and continue. A saved, complete choice is authoritative: Yokai does not ask again at the next launch or check it against a hash. Reconsider it yourself when a phase's scope changes. Headless startup stops if a phase has no tier or no reason.

A rough guide: `low` for mechanical edits with clear checks, `medium` for bounded work with good tests, `high` for cross-module changes and migrations, `ultra` for tightly coupled work where another failed attempt is expensive. [Agents and models](/en/docs/yokai/models) suggests concrete models.

## What can go wrong

- `missing or incomplete phase assessment`. A phase has no `model-tier` or no `reason`. Open `yokai setup` and approve the proposals.
- `tiers.medium must list at least one candidate`. A band is an empty list. Add a candidate or rerun setup.
- Every candidate skipped. The agent is logged out or out of quota. Fix the login, or wait for `retry_after_secs`.
- A notice like `effort ... exposes no ... selection`. The turn still runs, but the candidate sets `effort` on an agent that has no reasoning selector, often Cursor. Remove `effort` from that candidate.
