feat(models): presets with a ladder — a run goes to the first route with quota left #50

Closed
gabrielvidal wants to merge 0 commits from model-router into main
pull from: model-router
Owner

Summary

A preset is a named ladder of routes (a model, a harness and an effort each). A run sent on one goes to the first route with quota left for its profile's login, and a follow-up steps down when its route fills, so every run still gets done, sometimes on a lesser model. This is the core half of the design approved on 2026-11-29 (mockups A–E): the store and resolver, the send path, the run queue's quota hold, the subagent model, the API, and the UI in Settings → Models, the composer and the conversation page.

Merge together with ai-agent-plugins#44 (provider-google 1.1.0, provider-anthropic 1.1.0, harness-agy 1.2.0, hub-mcp 1.2.0, cron-jobs 1.1.0). Core works without it, but the Antigravity Claude / GPT-OSS routes read "not in the catalogue" and the Google plan's two quota groups aren't told apart until it lands.

Nothing is deployed from the EVOX2: deploy from the Homelab after review, the host sidecar before the backend (subagentModel is a new launch field; an older sidecar ignores it, so the order only matters for the subagent switch to take effect).

Key changes

  • backend/models/ladders.py (new): LadderStore (/data/model-ladders.json, seeded with Best / Everyday / Background / Free and their defaults, all editable and deletable), a route's status against the usage readings, resolve, step_for_turn, subagent_model, the API views.
  • backend/runs/service.py: preset:<id> is resolved before route_new_run in the new-run branch; a new owner run that names no model, harness or account gets its source's default preset; a continue of a routed conversation steps down on the same harness and login; every owner Claude launch (spawn, resume, fork) carries subagentModel.
  • backend/runs/queue.py: a second reason to wait, hold (a preset set to wait whose routes are all full), replayed at the earliest reset.
  • sidecar/launch.py, routes_runs.py, fork.py: subagentModel → CLAUDE_CODE_SUBAGENT_MODEL, CLAUDE_CODE_SUBAGENT_MODEL_FORCE=1, CLAUDE_CODE_WORKFLOW_SUBAGENT_MODEL.
  • backend/plugins/typed_manifest.py, providers.py: the optional provider key quotaWindows; a Claude id another vendor serves folds into the family key (Opus is one model on two harnesses); context_window no longer takes Antigravity's entry for Claude Code's model.
  • backend/models/routes.py: GET/POST /api/model-ladders, PUT/DELETE /api/model-ladders/{id}, PUT /api/model-ladders/defaults (owner; authz rows + golden matrix); ladders in /api/models and the models.read bridge; hub/runs/resolve answers where a preset lands.
  • cli/ai_agent.py: --model preset:<id>; ai-agent models lists the presets.
  • Frontend: lib/ladders.tsx, business/models/components/Presets.tsx (A and D), business/models/pages/Preset.tsx (B), ModelPicker + SpawnComposer (C), PresetBadge, RoutingCard.tsx and the step-down divider (E), two visibility switches, the mock backend, i18n keys, a telemetry event.
  • backend/conversations/cards.py: cards now carry route / routeSteps / preset, and queued, which the agent-limits badge read but the card never sent.

Key decisions

  • Fable's week is a sub-limit, not its own pool. A route is full when any window it draws on is at the line, so Fable is full while the account's week is at 100% even with its own week at 41%. This follows the brief's decision 2, not the mockup's "Fable 41% · room".
  • Missing data never blocks. No reading, or a reading whose reset has passed, counts as room. A default preset that can't be resolved leaves the run as it was; only an explicit preset:<id> can refuse a send.
  • Subagents with no Claude route left get the run's own model, as the brief says. With the Personal week at 100% today that means a Haiku-defined agent (the clarifier) is forced onto the run's model. Setting Claude Code subagents & workflows to "its own" turns the forcing off.
  • Step down only, never back up. A model switch re-reads the whole context uncached, so a conversation doesn't climb again when a higher route resets. A turn that picks one exact model ends the stepping; preset:<id> on a continue re-attaches it.
  • The step-down applies at a launch only. A follow-up delivered through a live run's inbox keeps the model that run started with.
  • The composer's pre-selection respects an existing pick. A profile that already has a sticky model keeps it; only a profile that never picked one starts on the composer's default preset. Picking a preset once makes it the sticky pick.

Deviations from the mockups

  • B: no per-preset "subagents and workflow agents" select. Per the brief it is one global default (D's Claude Code subagents & workflows row).
  • B: each route has an effort select; a route is removed with ×; changes save at once (no Save button).
  • C: the list keeps every vendor's models under the presets instead of an "All models…" row; the chip beside the model shows the profile, not a login.
  • D: an unset source reads "its own" (the hub can't know a plugin's own model, so no "its own: Sonnet").
  • E: the header keeps the app's one-line meta row: pill, model, harness, project, age.

Left / known gaps

  • For about 25 s after a hub start the lab's hosted logins (agy, opencode) aren't read yet, so those routes read unavailable and a preset sent in that window lands lower. Plain routing has the same gap (it answers 400).
  • An agy Claude run is still priced with Anthropic's price book and its cost shows under the anthropic vendor (the account is google-personal, out of totals). Not touched here.
  • Send later and the reply box don't offer presets in their own pickers (a scheduled send from the composer does carry preset:<id>).

Changelog

  • Added: presets in Settings → Models: a ladder of models per preset; a run goes to the first one with quota left
  • Added: the composer's model picker lists presets and shows each model's own quota ("week 100% · pays")
  • Added: "who uses which preset" for the composer, the CLI / MCP, child conversations, Claude Code subagents and each plugin that starts runs
  • Added: a conversation sent on a preset shows its route ("Best · 3/7"), the routes it skipped and each step down
  • Added: ai-agent new --model preset:<id>
  • Fixed: a conversation waiting in the start queue now shows its "queued" badge on cards

Test notes

  • Backend: test_model_ladders.py (43 tests: the manifest key, keys and vendors, windows, room / full / missing data, resolution and whenFull, the store and defaults by source, a new run on a preset and on a default, the quota hold and its replay, follow-up step-down, the subagent model and the sidecar env, the routes). Every backend module run one sandbox each: all pass except test_typed_plugins::test_records_carry_kind, which fails the same way on main. Sidecar suite: the same 9 failures as main (test_host_only_routes and friends); CLI suite passes.
  • Frontend: tsc clean; vitest 1165 pass. FreshContext (CacheExpiredNotice) fails as on main; reachability failed once under the full run's load and passes alone, here and on main.
  • Real hub on this box (port 8141, scratch data, the plugins branch as the seed dir, a stub sidecar, usage readings matching today's: Personal week 100%, Fable week 41%, Gemini week 96%, Claude & GPT group 0%):
    • preset:best → agy claude-opus-5-5 on google-personal; no model from a browser → the composer's default (same route); preset:background → agy gpt-oss-120b; a plain opus on Claude Code → unchanged, with subagentModel.
    • A browser script drove the editor: arrow-key and drag reorder, add and remove a route, the when full radio, rename, a source's default, delete. All saved; no page errors.
  • One tiny real run on CLI 2.1.332 with the three env vars set to haiku: the main turn ran on claude-fable-5-2, its subagent on claude-haiku-5-5 ($0.38 at list price).
  • Screenshots below are the real UI on that hub, mobile and desktop.

Screenshots

a-models-mobile.png
a-models-desktop.png
b-editor-mobile.png
b-editor-desktop.png
c-picker-mobile.png
c-picker-desktop.png
d-defaults-mobile.png
d-defaults-desktop.png
e-conversation-mobile.png
e-conversation-desktop.png
e-exact-model-desktop.png

## Summary A **preset** is a named ladder of routes (a model, a harness and an effort each). A run sent on one goes to the first route with quota left for its profile's login, and a follow-up steps down when its route fills, so every run still gets done, sometimes on a lesser model. This is the core half of the design approved on 2026-11-29 (mockups A–E): the store and resolver, the send path, the run queue's quota hold, the subagent model, the API, and the UI in Settings → Models, the composer and the conversation page. **Merge together with [ai-agent-plugins#44](https://git.gabvdl.xyz/gabrielvidal/ai-agent-plugins/pulls/44)** (provider-google 1.1.0, provider-anthropic 1.1.0, harness-agy 1.2.0, hub-mcp 1.2.0, cron-jobs 1.1.0). Core works without it, but the Antigravity Claude / GPT-OSS routes read "not in the catalogue" and the Google plan's two quota groups aren't told apart until it lands. Nothing is deployed from the EVOX2: deploy from the Homelab after review, **the host sidecar before the backend** (`subagentModel` is a new launch field; an older sidecar ignores it, so the order only matters for the subagent switch to take effect). ## Key changes - `backend/models/ladders.py` (new): `LadderStore` (`/data/model-ladders.json`, seeded with Best / Everyday / Background / Free and their defaults, all editable and deletable), a route's status against the usage readings, `resolve`, `step_for_turn`, `subagent_model`, the API views. - `backend/runs/service.py`: `preset:<id>` is resolved before `route_new_run` in the new-run branch; a new owner run that names no model, harness or account gets its source's default preset; a continue of a routed conversation steps down on the same harness and login; every owner Claude launch (spawn, resume, fork) carries `subagentModel`. - `backend/runs/queue.py`: a second reason to wait, `hold` (a preset set to *wait* whose routes are all full), replayed at the earliest reset. - `sidecar/launch.py`, `routes_runs.py`, `fork.py`: `subagentModel` → `CLAUDE_CODE_SUBAGENT_MODEL`, `CLAUDE_CODE_SUBAGENT_MODEL_FORCE=1`, `CLAUDE_CODE_WORKFLOW_SUBAGENT_MODEL`. - `backend/plugins/typed_manifest.py`, `providers.py`: the optional provider key `quotaWindows`; a Claude id another vendor serves folds into the family key (Opus is one model on two harnesses); `context_window` no longer takes Antigravity's entry for Claude Code's model. - `backend/models/routes.py`: `GET/POST /api/model-ladders`, `PUT/DELETE /api/model-ladders/{id}`, `PUT /api/model-ladders/defaults` (owner; authz rows + golden matrix); `ladders` in `/api/models` and the `models.read` bridge; `hub/runs/resolve` answers where a preset lands. - `cli/ai_agent.py`: `--model preset:<id>`; `ai-agent models` lists the presets. - Frontend: `lib/ladders.tsx`, `business/models/components/Presets.tsx` (A and D), `business/models/pages/Preset.tsx` (B), `ModelPicker` + `SpawnComposer` (C), `PresetBadge`, `RoutingCard.tsx` and the step-down divider (E), two visibility switches, the mock backend, i18n keys, a telemetry event. - `backend/conversations/cards.py`: cards now carry `route` / `routeSteps` / `preset`, and `queued`, which the agent-limits badge read but the card never sent. ## Key decisions - **Fable's week is a sub-limit, not its own pool.** A route is full when *any* window it draws on is at the line, so Fable is full while the account's week is at 100% even with its own week at 41%. This follows the brief's decision 2, not the mockup's "Fable 41% · room". - **Missing data never blocks.** No reading, or a reading whose reset has passed, counts as room. A default preset that can't be resolved leaves the run as it was; only an explicit `preset:<id>` can refuse a send. - **Subagents with no Claude route left get the run's own model**, as the brief says. With the Personal week at 100% today that means a Haiku-defined agent (the clarifier) is forced onto the run's model. Setting *Claude Code subagents & workflows* to "its own" turns the forcing off. - **Step down only, never back up.** A model switch re-reads the whole context uncached, so a conversation doesn't climb again when a higher route resets. A turn that picks one exact model ends the stepping; `preset:<id>` on a continue re-attaches it. - **The step-down applies at a launch only.** A follow-up delivered through a live run's inbox keeps the model that run started with. - **The composer's pre-selection respects an existing pick.** A profile that already has a sticky model keeps it; only a profile that never picked one starts on the composer's default preset. Picking a preset once makes it the sticky pick. ## Deviations from the mockups - B: no per-preset "subagents and workflow agents" select. Per the brief it is one global default (D's *Claude Code subagents & workflows* row). - B: each route has an effort select; a route is removed with ×; changes save at once (no Save button). - C: the list keeps every vendor's models under the presets instead of an "All models…" row; the chip beside the model shows the profile, not a login. - D: an unset source reads "its own" (the hub can't know a plugin's own model, so no "its own: Sonnet"). - E: the header keeps the app's one-line meta row: pill, model, harness, project, age. ## Left / known gaps - For about 25 s after a hub start the lab's hosted logins (agy, opencode) aren't read yet, so those routes read unavailable and a preset sent in that window lands lower. Plain routing has the same gap (it answers 400). - An agy Claude run is still priced with Anthropic's price book and its cost shows under the anthropic vendor (the account is google-personal, out of totals). Not touched here. - *Send later* and the reply box don't offer presets in their own pickers (a scheduled send from the composer does carry `preset:<id>`). ## Changelog - Added: presets in Settings → Models: a ladder of models per preset; a run goes to the first one with quota left - Added: the composer's model picker lists presets and shows each model's own quota ("week 100% · pays") - Added: "who uses which preset" for the composer, the CLI / MCP, child conversations, Claude Code subagents and each plugin that starts runs - Added: a conversation sent on a preset shows its route ("Best · 3/7"), the routes it skipped and each step down - Added: `ai-agent new --model preset:<id>` - Fixed: a conversation waiting in the start queue now shows its "queued" badge on cards ## Test notes - Backend: `test_model_ladders.py` (43 tests: the manifest key, keys and vendors, windows, room / full / missing data, resolution and `whenFull`, the store and defaults by source, a new run on a preset and on a default, the quota hold and its replay, follow-up step-down, the subagent model and the sidecar env, the routes). Every backend module run one sandbox each: all pass except `test_typed_plugins::test_records_carry_kind`, which fails the same way on main. Sidecar suite: the same 9 failures as main (`test_host_only_routes` and friends); CLI suite passes. - Frontend: `tsc` clean; vitest 1165 pass. `FreshContext` (CacheExpiredNotice) fails as on main; `reachability` failed once under the full run's load and passes alone, here and on main. - Real hub on this box (port 8141, scratch data, the plugins branch as the seed dir, a stub sidecar, usage readings matching today's: Personal week 100%, Fable week 41%, Gemini week 96%, Claude & GPT group 0%): - `preset:best` → agy `claude-opus-5-5` on google-personal; no model from a browser → the composer's default (same route); `preset:background` → agy `gpt-oss-120b`; a plain `opus` on Claude Code → unchanged, with `subagentModel`. - A browser script drove the editor: arrow-key and drag reorder, add and remove a route, the *when full* radio, rename, a source's default, delete. All saved; no page errors. - One tiny real run on CLI 2.1.332 with the three env vars set to `haiku`: the main turn ran on `claude-fable-5-2`, its subagent on `claude-haiku-5-5` ($0.38 at list price). - Screenshots below are the real UI on that hub, mobile and desktop. ## Screenshots ![a-models-mobile.png](https://git.gabvdl.xyz/attachments/b449665b-93cf-4e1b-b77d-f6c5cd7076f2) ![a-models-desktop.png](https://git.gabvdl.xyz/attachments/9a12ec56-dd88-4ac2-8e8e-c47c71c533e0) ![b-editor-mobile.png](https://git.gabvdl.xyz/attachments/7f534ea5-e967-4074-b7c5-1bf335c62c97) ![b-editor-desktop.png](https://git.gabvdl.xyz/attachments/94f114d6-212a-4b18-8737-348d9c9a9b19) ![c-picker-mobile.png](https://git.gabvdl.xyz/attachments/4409b037-ebf2-4ed7-bbae-ef9cc949287d) ![c-picker-desktop.png](https://git.gabvdl.xyz/attachments/359fc5b7-a403-40b2-969e-99480994facf) ![d-defaults-mobile.png](https://git.gabvdl.xyz/attachments/bc9a064d-c93c-460f-8d87-179346b7c39e) ![d-defaults-desktop.png](https://git.gabvdl.xyz/attachments/4a034f5a-ac0f-4a3b-a90d-3d3aa048d8b5) ![e-conversation-mobile.png](https://git.gabvdl.xyz/attachments/c059aea0-a11b-4c11-92a1-8382ff1f87cf) ![e-conversation-desktop.png](https://git.gabvdl.xyz/attachments/3fe8aa13-3f63-4b29-afbc-6513be80e758) ![e-exact-model-desktop.png](https://git.gabvdl.xyz/attachments/795e6770-99e1-49e6-819b-2f2b8c25e1be)
gabrielvidal self-assigned this 2026-11-29 19:48:15 +01:00
gabrielvidal added 2 commits 2026-11-29 19:48:15 +01:00
A preset is a named ladder of routes (model + harness + effort). A run sent on
preset:<id> — or on its source's default preset — takes the first rung with
room for its profile's login, and a follow-up steps down when its rung fills.
Provider plugins say which usage windows a model draws on (quotaWindows).
A Claude run's own subagents are held to the subagents preset's first Claude
route with room (subagentModel → CLAUDE_CODE_SUBAGENT_MODEL).

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
Settings → Models opens on the presets (where each lands right now) and on
who uses which; /settings/models/presets/<id> edits a ladder. The composer's
model picker lists presets above the models and sends preset:<id>; a
conversation sent on one shows its route (header pill, Details Routing card)
and the step-down divider. Cards carry meta.queued / route; the reply box
offers a conversation its own harness's entry of a shared model.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
Author
Owner
Merged into `main` as 7b1ad56349465bf1ea8c7f28c98a0ade48db443f by the auto-ship batch https://ai-agent.lab.gabvdl.xyz/conversation/6dc229d3-ba8d-4b73-8ef7-dcb3135fdd68.
gabrielvidal closed this pull request 2026-11-29 20:17:43 +01:00

Pull request closed

Please reopen this pull request to perform a merge.
Sign in to join this conversation.
No Reviewers
No labels
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: gabrielvidal/ai-agent#50