Skip to content

LucioLiu/token-saver

Repository files navigation

English | 简体中文

token-saver · autonomous subagent model routing 💰

Route each subagent to the cheapest capable model that can still do the job — don't send scanning/copying work to an expensive model, and don't hand critical judgment to an underpowered one.

Which models are actually callable varies by user, account, and agent tool — and it keeps changing. token-saver doesn't maintain a vendor leaderboard and doesn't hard-code specific model names; it teaches the dispatching agent to choose based on task intensity and what's genuinely available right now.

Honest positioning: this is a routing discipline (a routing guideline) — it teaches an agent how to choose and how to record it honestly, and it only takes effect if the agent follows it. It does not ship a candidate enumerator, a dispatcher, a host-log verifier, or an automatic metering tool. The machine-readable contracts live in schemas/; the actual runtime capability must come from an adapter/tool in the current harness. Details beyond the main text live in references/, read on demand to control injection overhead.

Core mechanics

  • Sensitivity-first gate: classify the task's data as PUBLIC / INTERNAL / CONFIDENTIAL / RESTRICTED first, filter down to the models and vendors allowed to touch that level, and only then talk about capability and cost — you can't pick the cheap option first and ask afterward whether it's allowed to see the data.
  • Task-intensity intent: light execution, routine work, deep judgment, critical review — these describe the task, not a specific model. Tiering uses a five-dimension check (uncertainty / cost of error / verifiability / context complexity / side effects), not a gut call based on the task's name.
  • Autonomous choice: from the options the current tool genuinely allows, pick the model that's just enough to reliably get the task done.
  • Three execution modes: EXPLICIT when explicit parameters are supported; PRESET when going through a pre-built worker; INHERIT_ONLY when the calling surface offers no choice.
  • Honest degradation: inheriting the default model isn't a failure, but you may never claim it was routed by tier when it wasn't.
  • Splitting mixed tasks: dispatch the execution segment and the judgment segment separately, to cut down on expensive-context occupancy.
  • Guarded cascade upgrade: for tasks whose output is machine-checkable (tests / schema / compile) and whose first run can be isolated, idempotent, or fully revertible, you may run one tier down first and re-run one tier up only if verification fails; tasks with irreversible side effects (sending messages, touching a database, deploying, bulk edits/deletes) — plus critical-review-tier and non-machine-checkable tasks — are barred from cascading, to prevent "the low tier digs a hole, the high tier has to fill it."
  • Cost feedback loop: when the host exposes usage data, feed the actual cost back as a reference for tiering choices within this session; never fabricate what isn't visible, and never let it sediment across sessions into a model ranking or price table.
  • ROUTE_DECISION dispatch record: every routing decision logs one structured record (tier / sensitivity / mode / model chosen / cascade plan / verification status), making routing auditable and serving as an input contract for a future execution layer.
  • Quality guardrail (a three-way split of verifiers): deterministic verifiers (compile / test / schema) aren't a model and have no notion of "stronger or weaker"; a semantic reviewer must not be noticeably weaker than the generator; high-risk rulings must go through the main agent or a human. Never pick a weaker option for a critical result nobody will review.
  • Post-run verification: confirm from the current platform's host logs or run metadata when needed — never trust the model's self-report, and never hard-code a log path.

Install

Option 1 · GitHub CLI (auto-updating)

gh skill install LucioLiu/token-saver token-saver --agent claude-code --scope user

Option 2 · Manual: copy SKILL.md into whatever user-level skills directory your agent tool supports. Chinese-speaking users should copy SKILL.zh-CN.md instead and rename it to SKILL.md locally.

Companion blocks

  • handoff-protocol — the discipline for dispatching and receiving work back across multiple agents.
  • dont-reinvent — look for an existing skill before building one.

Measured results (2026-07 · v1.4 evaluation)

A 30-task evaluation set (10 mechanical / 10 routine / 5 judgment / 5 mixed) × 3 dispatch strategies, run for real in a single agent-tool environment in EXPLICIT mode; the grader was frozen after an independent, bidirectional adversarial review (correctly failed all 30 injected wrong answers, zero false positives on 9 legitimate phrasing variants):

Strategy Success rate Relative cost
Always inherit the main session's strong model 96.7% 1.00×
Always pin a fixed mid-tier model 96.7% 0.34×
token-saver dynamic routing (dispatch low/mid/high tier by four-level intensity) 89.0% (mean of 3 batch runs) 0.30×

Honest reading:

  • Dynamic routing saves about 70% of cost relative to "always dispatch the main session's strong model directly" — that's the real payoff under this skill's scenario assumptions.
  • On this particular task mix, "fixed mid-tier" is the best value: the same success rate, at roughly 1/3 the cost; dynamic routing only saves an additional 12% while losing 7.7 percentage points of success. The more a task mix skews toward mechanical, bulk work, the bigger routing's payoff; the more it skews toward uniform, routine work, the more fixed-mid-tier wins.
  • Routing's losses are highly concentrated: every one traces back to a low-tier model's off-by-one on a machine-checkable counting task — exactly the scenario "cascade upgrade" (run light first, re-run one tier up if verification fails) is meant to catch; this evaluation round did not have cascading enabled. On judgment-type tasks, routing lost zero quality (15/15 at the strong tier).

Boundaries: single platform, single round (dynamic routing n=3, everything else n=1 — variance exists); routing tiers were pre-labeled per this skill's five dimensions (the discipline's ideal execution) — how accurately an agent tiers a task on its own is a separate, untested question; INHERIT_ONLY / PRESET scenarios weren't covered; cost is a relative value against API list price. See the repo's issue tracker or the source project for how the evaluation set and grader were built.

Version & updates

Current version 1.4.0 (see .claude-plugin/plugin.json).

  • 1.2.0: removed vendor names, specific model names, fixed price multipliers, and a hard-coded log path — replaced with the current agent choosing autonomously based on what's actually available.
  • 1.3.0: added guarded cascade upgrade and cost feedback loop, plus a near-match mapping onto existing semantic-tier aliases (fast/balanced/deep/critical, etc.).
  • 1.4.0 (driven by external review): added the sensitivity-first gate (filter allowed models before tiering), five-dimension tiering (replacing gut-feel tiering based on task name), hard preconditions for cascading (isolated / idempotent / revertible; irreversible side effects bar cascading), the structured ROUTE_DECISION dispatch record, and a three-way split of verifiers (deterministic / semantic / adjudication); slimmed down the main text and moved details into references/ for on-demand reading.

Part of the capability-block architecture behind the Nuwa digital-employee framework.

Contract tests

Single entry point:

python .\tests\run_tests.py --component-schema <agent-modpack-component-schema.json>

This entry point validates the component manifest, the ROUTE_DECISION/policy schema, and the deterministic contracts for SK-TS-P-001 and SK-TS-N-001 (including a provider mock and INHERIT_ONLY sensitivity blocking) — offline. It never dispatches a real agent, and never marks a case bundle's semantic behavior as PASS.

License

PolyForm Noncommercial 1.0.0 — free for personal and non-commercial use.


Both language editions are maintained in sync. If they ever diverge, the Chinese edition is authoritative — please open an issue if you spot one.

About

Route each subagent to the cheapest capable model - about 70% off execution-tier tokens in our tests (Claude Code / any multi-tier agent platform)

Topics

Resources

License

Stars

1 star

Watchers

0 watching

Forks

Releases

No releases published

Packages

 
 
 

Contributors