agentleFS
lbdremylbdremy/phax/.claude/skills/model-routing/SKILL.md

model-routing

Skill2 starsChanged 5 months agoApache-2.0View on GitHub

Extend the routing layer, add provider adapters, change the resolution algorithm, or add new model families in src/domain/routing/.

30 other projects use a version of this.

Adopted by

Most recently taken up by

Used with

Projects with it also use ecosystem-reference, fractal-delegation and 10 more.

Other files people use alongside this one.

Files found in the same public projects as a version of this one, more often than they turn up anywhere else. Each project counts once, large collections count for less, and this file's own repository is left out.
  • naman10parikhSkill

    ecosystem-reference

    Quick-access directory of Claude Code ecosystem repos, skills, plugins, MCPs, and patterns. Use when improving the harness.

    Also in 5 projects that use this

  • naman10parikhSkill

    fractal-delegation

    Also in 5 projects that use this

  • KirchliveSkill

    skill-routing

    Decides which of the installed skills a task needs and loads them before the work starts. This skill should be used at the beginning of any multi-step task — build, fix, refactor, migrate, review, plan, release, research, write, design, video — and again at every phase change, after context compaction, and when work moves into a different part of the codebase. Use it for requests like "let's build X", "fix this bug", "refactor Y", "plan the migration", "review this", and also when the user asks which skill applies, why a skill did not fire, or asks to check what is available.

    Also in 5 projects that use this

  • sublimotionSkill

    agent-runtime

    Launch and manage detached agent runs on EKS via the agent-runner CLI. Use when the user says "launch an agent run", "agent runtime", "agent-runner", "run this spec on the cluster", "check run status", "agent run logs", or "stop a run". Do NOT use for writing the agent-runner code itself (edit the sibling ../agent-runner repo), Terraform of the foundation (use terraform-automation), or GPU serving deployments (use infra-deployer).

    Also in 5 projects that use this

  • GoZippySkill

    repo-scout

    Also in 5 projects that use this

  • BenjaminGSkill

    harness-review

    Turn one PR's review comments into harness fixes — classify each cause by the most solid place it can live (codebase, lint, rules, skill), then draft the fixes in a separate PR.

    Also in 5 projects that use this

  • +6 more from naman10parikh

The file

Show its rules and text

We split this skill into the rules it gives an agent

13 rules. 0 are common, 1 is distinctive, and 12 are very specific to this project.

  • 0

    Common

    Most of the 29 edited versions we read keep these.

  • 1

    Distinctive

    This author's own choices. Worth a look.

  • 12

    Very specific

    Tied to their project's names, files or tools. Probably skip.

  • Common
  • Distinctive
  • Very specific
  1. Distinctive:

    Use this skill when extending the routing layer, adding provider adapters, changing the resolution algorithm, or adding new model families.

    line 8
  2. Very specific:

    If the provider serves the plan family, resolve natively from its catalog (relationship exact or equivalent if effort is clamped).

    line 77
  3. Very specific:

    Add the literal to ProviderId in src/domain/routing/types.ts.

    line 83
  4. Very specific:

    Add the corresponding literal to ProviderIdSchema in src/schemas/modelRouting.ts.

    line 84
  5. Very specific:

    Add equivalence edges in DEFAULT_MODEL_ROUTING.equivalence (in defaults.ts) for each of the provider's model ids and efforts, anchoring …

    line 85
  6. Very specific:

    Add a ProviderEntry in DEFAULT_PROVIDER_CONFIG.providers with a families record and per-model models arrays.

    line 86
  7. Very specific:

    Create src/infra/providers/<newProvider>.ts with runNewProviderAgent + resume variant returning AgentRunResult.

    line 87
  8. Very specific:

    Add tests in tests/unit/providers/<newProvider>.test.ts (no real CLI — mock the spawn).

    line 89
  9. Very specific:

    Add the literal to ModelFamily in types.ts and ModelFamilySchema in modelRouting.ts.

    line 93
  10. Very specific:

    Add requestedModelNormalization entries for known versioned ids in DEFAULT_MODEL_ROUTING.

    line 94
  11. Very specific:

    Add the family's models arrays (with per-entry efforts and status) to the relevant provider entry in DEFAULT_PROVIDER_CONFIG.

    line 95
  12. Very specific:

    If the family belongs to a spoke provider, add equivalence edges in DEFAULT_MODEL_ROUTING.equivalence.

    line 96
  13. Very specific:

    Update docs/model-routing.md family table.

    line 97

“Common” is measured: kept by at least 6 in 10 of the 29 edited versions of this file we could read. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.

Keep what fits and drop the rest. Your version, ready for your agents.
Files
SKILL.md

model-routing skill

Use this skill when extending the routing layer, adding provider adapters, changing the resolution algorithm, or adding new model families.

Architecture overview

src/domain/routing/         ← PURE — no IO, no Effect, no infra imports
  types.ts                  ← ProviderId, ModelFamily, EffortLevel, ThinkingLevel, Relationship literals
  defaults.ts               ← DEFAULT_MODEL_ROUTING, DEFAULT_PROVIDER_CONFIG constants
  catalog.ts                ← pure catalog helpers: familyOfId, entryFor, effortsFor, isDeprecated, nearestEfforts, equivalentFor, isClaudeFamily
  resolve.ts                ← resolveModel(request, routing, providerCfg, securityFilter?): RoutingResolution (total, pure)
  preflight.ts              ← preflightPhaseModels(phases, routing, providerConfig): { failures } (pure)

src/schemas/
  modelRouting.ts           ← Effect Schema for ~/.phax/model-routing.json (version 2); re-exports literal schemas
  providerConfig.ts         ← Effect Schema for ~/.phax/providers.json (versioned catalog with per-entry efforts and status)
  vibeConfig.ts             ← VibeBaseModel schema + extractBaseModel + renderPhaxAliasBlocks

src/app/
  loadRouting.ts            ← FileSystem-port loaders; falls back to defaults when files absent
  vibeSetup.ts              ← append-only Vibe alias installer (atomic write + backup)

src/infra/providers/        ← ONLY place that may spawn provider binaries
  claudeCode.ts             ← claude spawn logic
  mistralVibe.ts            ← vibe spawn logic (VIBE_ACTIVE_MODEL env)
  codexCli.ts               ← codex spawn logic
  sessionWriter.ts          ← shared atomic session-id writer
  dispatcher.ts             ← makeNodeBackendLayer(providerConfig) — selects adapter by options.provider

src/cli/definitions/agent.ts ← phax agent models|resolve|probe|setup commands

Key invariants

Domain stays pure: nothing under src/domain/routing/ may import Effect, @opentelemetry/*, the FileSystem port, or any infra/ module. resolveModel is a total pure function — it never throws. An architectural guard in tests/unit/architecturalGuards.test.ts enforces this.

Only src/infra/providers/ may spawn: the spawn("claude"…), spawn("vibe"…), spawn("codex"…) calls live exclusively in the corresponding adapter files. The architectural guard forbids these patterns anywhere else in src/.

Schemas use onExcessProperty: "error": config files are validated strictly. Config version 2 rejects tiers, normalization, and defaultTier fields — there is no back-compat shim. New fields must be added to the schema first.

No back-compat shims: new required fields are required, not optional for legacy files.

allowDowngrade is the sole policy knob: cross-family substitutions with downgrade or no_equivalent relation are skipped when allowDowngrade: false. Same-family resolution is always permitted.

Efforts are per catalog entry: each versioned model id has its own efforts array. There is no family-wide effort set. The preflight validates that a phase's effort is in its entry's supported set before any agent spawns.

Terminal claude-code fallback: resolveModel is total. If no provider in providerPriority resolves, the function falls through to claude-code — natively for Claude families, via the equivalence hub for non-Claude families.

Telemetry never fails a run: the agent.model.resolved event is emitted via telemetry.recordEvent and errors are swallowed.

Atomic writes + backup: vibeSetup.ts and the session writer use temp + rename; vibeSetup.ts backs up ~/.vibe/config.toml before appending.

Catalog helpers (catalog.ts)

ExportPurpose
familyOfIdLook up the ModelFamily for a versioned id; undefined if not in catalog
entryForCatalogLocation (provider + family + entry) for a versioned id
effortsForThe efforts array for a versioned id
isDeprecatedTrue when the entry's status is "deprecated"
nearestEffortsEfforts sorted by proximity to a requested effort; used by preflight
equivalentForStar-lookup through the Claude hub (hub→spoke, spoke→hub, spoke→spoke)
isClaudeFamilyTrue for claude-haiku, claude-sonnet, claude-opus

equivalentFor semantics: equivalence table edges are stated hub-centric. Hub → spoke uses the stored relation of the exact (claude, effort) edge; without one it takes the nearest-effort edge anchored on the same Claude id (ties prefer the lower) and records the shift as upgrade or downgrade (never for ultracode); spoke → hub inverts the relation (downgrade ↔ upgrade); spoke → spoke composes two hops.

Resolution pipeline

  1. Derive plan family from request.model: catalog lookup → requestedModelNormalization → substring heuristic → default claude-sonnet.
  2. Walk routing.providerPriority; skip disabled providers and security-filtered providers.
  3. If the provider serves the plan family, resolve natively from its catalog (relationship exact or equivalent if effort is clamped).
  4. Otherwise translate through the Claude hub via equivalentFor; skip when allowDowngrade: false and relation is downgrade or no_equivalent.
  5. Terminal claude-code: same-family natively, or spoke → hub via equivalence table. Relationship no_equivalent on a complete miss.

Adding a new provider

  1. Add the literal to ProviderId in src/domain/routing/types.ts.
  2. Add the corresponding literal to ProviderIdSchema in src/schemas/modelRouting.ts.
  3. Add equivalence edges in DEFAULT_MODEL_ROUTING.equivalence (in defaults.ts) for each of the provider's model ids and efforts, anchoring each to its Claude hub peer.
  4. Add a ProviderEntry in DEFAULT_PROVIDER_CONFIG.providers with a families record and per-model models arrays.
  5. Create src/infra/providers/<newProvider>.ts with runNewProviderAgent + resume variant returning AgentRunResult.
  6. Wire the new branch in src/infra/providers/dispatcher.ts.
  7. Add tests in tests/unit/providers/<newProvider>.test.ts (no real CLI — mock the spawn).

Adding a new model family

  1. Add the literal to ModelFamily in types.ts and ModelFamilySchema in modelRouting.ts.
  2. Add requestedModelNormalization entries for known versioned ids in DEFAULT_MODEL_ROUTING.
  3. Add the family's models arrays (with per-entry efforts and status) to the relevant provider entry in DEFAULT_PROVIDER_CONFIG.
  4. If the family belongs to a spoke provider, add equivalence edges in DEFAULT_MODEL_ROUTING.equivalence.
  5. Update docs/model-routing.md family table.

Per-invocation provider priority override

Both phax run and phax resume accept --provider-priority <list> to override providerPriority for that invocation without touching any config file:

phax run --provider-priority mistral-vibe,claude-code
phax resume my-run --yes --provider-priority codex-cli,claude-code

Valid ids: claude-code, mistral-vibe, codex-cli. The list is parsed by parseProviderPriority in src/domain/routing/priorityOverride.ts (deduped, trimmed, validated; fails fast on empty/unknown). The override is applied by applyProviderPriorityOverride which returns a new ModelRouting with only providerPriority replaced.

Caveat: claude-code remains the guaranteed terminal fallback in resolveModel regardless of the override.

Worked examples

RequestPriorityallowDowngradeResult
claude-sonnet-4-6 / mediumclaude-code only—claude-code, claude-sonnet-4-6, medium, exact
claude-sonnet-4-6 / mediummistral-vibe first—mistral-vibe, phax-mistral-medium-3.5-high, high, upgrade (nearest edge)
gpt-5.5 / xhighcodex-cli first—codex-cli, gpt-5.5, xhigh, exact
gpt-5.5 / xhigh (codex disabled)—trueclaude-code, claude-opus-4-8, medium, equivalent (hub translation)
claude-opus-4-8 / ultracodeanyanyclaude-code, claude-opus-4-8, ultracode, exact

Download now (ZIP)

Does it work?

Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.

No reviews yet

People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.

  • It worked
  • Partly
  • It didn't
What did you use it for? e.g. Reviewing pull requests in a Rails app

Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.

Your trail

Files you open will collect here, so you can find them again.

Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.

Now do this for your own.

Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.