A budget-constrained progressive-disclosure planner for MCP tool manifests and Agent Skills.
loadout reads your MCP tools (a tools/list dump) and Agent Skills (SKILL.md
files), measures exactly how much of the context window their schemas burn, and
then solves for which tools should stay eagerly loaded versus deferred under a
token budget — emitting a ready-to-ship defer_loading plan plus projected
savings and a CI budget gate. It is offline, deterministic, and dependency-free.
Think of it as choosing your agent's loadout: the kit it carries into every turn. Everything else is a search away.
By mid-2026 the dominant complaint about the Model Context Protocol is that tool schemas devour the context window before the user says anything:
- Seven MCP servers commonly consume ~67,300 tokens (33.7% of a 200k window) of tool definitions up front; one team reported 143k of 200k (72%) burned on tool definitions alone.
- A single GitHub MCP server is ~18k tokens for 27 tools; a 50-tool server is 25k–75k tokens. A well-documented tool costs 500–1,500 tokens.
- Tool-selection accuracy has been observed to collapse from ~43% to under 14% as tool sets bloat — the model drowns in irrelevant schemas.
The fix that actually shipped (Nov 2025 – Feb 2026) is progressive disclosure:
Anthropic's Tool Search Tool (defer_loading: true, ~85% token reduction),
Cloudflare's Code Mode, and the MCP code-execution pattern. Each says the same
thing: stop loading tool definitions you are not using; discover them on demand.
But progressive disclosure leaves an unsolved decision. If you defer
everything, the agent must search before it can act on turn one, and rarely-obvious
tools get missed. If you defer nothing, you pay the full bloat tax. So: which
tools stay eager, and which get deferred? Existing tools (token counters,
mcp-checkup, tool-card linters) measure and grade the bloat. None of them
solve the partition and hand you a deployable plan. That is the gap loadout
fills.
Choosing the eager tool set that maximizes usefulness under a fixed token budget
is exactly the 0/1 knapsack problem: each tool has a token weight and a
keep-eager value. loadout derives that value from purely static, deterministic
signals — links to installed Agent Skills, capability uniqueness, optional usage
frequency, and redundancy — then solves the knapsack, guards it with a
coverage-safety policy so no skill-critical capability is silently deferred, and
emits the defer_loading assignment you deploy. It turns "measure the bloat"
into "deploy the fix, deterministically." This prototype is the smallest thing
that proves that step is decidable offline.
No dependencies required (Python 3.11+). From this directory:
# Token-accounting report: where are your tokens going?
python main.py analyze examples
# Solve an eager/deferred plan under an 1800-token budget, folding in a usage log
python main.py plan examples --budget 1800 --usage examples/usage.jsonl
# Emit a deployable config and gate CI (exit 2 if over budget)
python main.py plan examples --budget 1800 --out plan.config.json --gateWith make: make analyze, make run, make test.
If tiktoken is installed (pip install ".[exact]"), loadout uses it
automatically for exact counts; otherwise it falls back to a calibrated
offline estimator. The active backend is always printed in the report header.
plan --out writes a config whose tools array is directly applicable to an
API tool list — deferred tools carry defer_loading: true:
{
"tools": [
{
"name": "github_create_issue",
"defer_loading": false
},
{
"name": "slack_post_message",
"defer_loading": true
}
],
"summary": {
"eager_count": 7,
"deferred_count": 9,
"baseline_tokens": 2942,
"upfront_tokens": 1778,
"savings_tokens": 1164,
"savings_pct": 39.6,
"within_budget": true
}
}--json prints the full machine payload (per-tool tokens, value, decision,
reason, redundancy clusters) for dashboards.
Exit codes (stable for scripting): 0 success; 1 bad input (clean message,
never a traceback); 2 gate failure — plan over budget or infeasible (with
--gate).
A single deterministic pipeline, one module per stage, so each is independently testable and swappable:
manifest ─▶ analyze ─▶ value ─▶ engine (pins) ─▶ pack (knapsack) ─▶ plan ─▶ report
| Module | Responsibility |
|---|---|
tokenizer.py |
Token counts. Exact via tiktoken if present; else an offline estimator that reproduces GPT-style pretokenization exactly and models sub-tokens per chunk. |
manifest.py |
Parse tools/list JSON (array / tools object / JSON-RPC envelope) and SKILL.md front matter (incl. folded/literal YAML block scalars) into a common model. |
analyze.py |
Per-tool token accounting (description vs schema), redundancy clustering by keyword overlap coefficient, and a capability keyword → tools index. |
value.py |
Per-tool keep-eager value from static signals: skill linkage, capability uniqueness, optional usage frequency, redundancy discount. Weights are explicit and tunable. |
pack.py |
The optimizer: 0/1 knapsack (bucketed-weight DP) maximizing value under the token budget, with pinned tools pre-allocated. |
engine.py |
Orchestration + the coverage-safety policy that decides which tools are pinned. |
plan.py |
Renders the packing into a defer_loading assignment with upfront/residual token projections and savings. |
report.py |
Human text and machine JSON — both pure functions of one result object, so they can never disagree. |
cli.py / main.py |
Argument parsing, usage-log loading, exit codes, the CI gate. |
- Load tools + skills into
Tool/Skillrecords. - Analyze: measure each tool's tokens; extract capability keywords; cluster near-duplicates; index which tools provide each capability.
- Value: score each tool's worth as an eager tool from static signals.
- Pin: under the coverage-safety policy, force-eager any tool that is the sole provider of a capability an installed Skill references.
- Pack: solve the knapsack — pinned tokens are pre-allocated, the remaining budget is filled to maximize total value; the rest are deferred.
- Plan + report: assign
defer_loading, project upfront cost (eager tokens + a one-time Tool Search overhead), and compute savings versus all-eager.
(A) Greedy value-density ranking (rejected as the core). Sort tools by value-per-token and keep eager until the budget fills. Simple and O(n log n), but greedy is not optimal for 0/1 knapsack — it can leave obvious value on the table when a cheap-but-critical tool is edged out by a slightly denser one. For a decision users will deploy, sub-optimality is hard to justify.
(B) Exact 0/1 knapsack via DP (chosen). Optimal for the stated objective.
The only cost is the DP's budget axis, which is large in raw tokens. We bucket
weights by a granularity g — rounding each tool's weight up and the budget
down — which shrinks the axis by ~g× and is provably non-overshooting: the
selected set's real token total never exceeds the budget (it can only leave a
little slack unused). For realistic manifests (tens to low hundreds of tools) the
DP runs in milliseconds.
| Greedy (A) | Bucketed DP (B, chosen) | |
|---|---|---|
| Optimality | approximate | optimal for the objective |
| Budget safety | exact | never overshoots (bucketing is conservative) |
| CPU | O(n log n) | O(n · budget/g) — ms in practice |
| Memory | O(n) | O(n · budget/g) for reconstruction |
| Determinism | yes | yes |
The value function itself is deliberately a transparent linear model, not a learned one: every number in a report can be traced to a signal, which matters when a human is deciding whether to trust the plan.
The default estimator is offline and dependency-free. It reproduces the public GPT-style pretokenization regex exactly (so it splits text into the same chunks a real BPE tokenizer sees) and then models the number of BPE sub-tokens per chunk with a small, documented formula calibrated against published anchor points for real MCP schemas (e.g. GitHub MCP ≈ 670 tokens/tool; typical tools 200–800). Expect ±15% on a single tool and ±8% in aggregate (errors are largely independent and partially cancel).
For exact numbers, install tiktoken and loadout uses it automatically. Reports
name the active backend (heuristic-v1 vs tiktoken:o200k_base) so you always
know whether a count is estimated or exact. Nothing is silently faked.
Deferral has a behavioral cost, not just a token cost: the agent must search for
a deferred tool. loadout's --safe mode (default on) pins every tool that is
the sole provider of a capability keyword an installed Agent Skill actually
references, so a declared workflow never depends on a lucky search hop. Tools that
are unique but that no skill needs are not pinned — their uniqueness is already
rewarded by the value function, and the budget is free to defer them. With no
skills installed, nothing is pinned and the budget rules everything. Disable with
--no-safe.
If the pinned set alone exceeds the budget, loadout reports the plan as
infeasible with an actionable message — it never emits a plan that quietly
violates the budget.
- Token counts are estimates by default. See "Honesty about token counts."
Install
tiktokenfor exact counts. The heuristic targets GPT-family BPE; other tokenizers will differ. - The Tool Search overhead is a single documented constant (
--overhead, default 500 tokens), applied once when any tool is deferred. Measure your provider's real overhead and pass it for a tighter projection. - Value signals are static. Skill linkage and capability uniqueness are
keyword-based (deterministic, offline). A usage log (
--usage) adds real frequency signal when you have one, butloadoutnever calls a model. - Redundancy is keyword-overlap based, not semantic embedding — it reliably catches near-duplicate/aliased tools but won't spot two tools that do the same thing with entirely different vocabulary.
- Deferral changes agent behavior.
loadoutoptimizes the token trade-off and guards known-critical capabilities; it cannot predict every task. Treat the plan as a strong, transparent default, and keep the CI gate to catch regressions. - Scope is a prototype: one budget, one manifest, one plan. Multi-profile planning and provider-specific overhead auto-measurement are future work.
python main.py plan examples --budget 1800 --usage examples/usage.jsonl
(16 tools across four mock MCP servers + two Agent Skills, offline estimator):
loadout plan (tokenizer: heuristic-v1)
============================================================
budget: 1800 tokens status: OK
baseline (all eager): 2942 tokens
planned upfront: 1778 tokens (eager 1278 + tool-search 500)
savings: 1164 tokens (39.6% off baseline)
eager tools: 7 deferred tools: 9
decisions:
EAGER * 305 github_create_issue
pinned eager (sole provider of 11 capability keyword(s); linked to skill(s): db-reporting, issue-triage)
EAGER * 153 postgres_run_query
pinned eager (sole provider of 12 capability keyword(s); linked to skill(s): db-reporting, issue-triage)
EAGER 103 postgres_list_tables
kept eager (value=2.11)
DEFER 242 github_list_issues
deferred (value=2.05, reclaims tokens upfront)
DEFER 184 slack_send_message
deferred (value=2.48, reclaims tokens upfront)
DEFER 141 slack_post_message
deferred (value=1.58, reclaims tokens upfront)
... (7 eager, 9 deferred in total)
(* = pinned by coverage-safety policy)
The five sole-providers of skill-referenced capabilities are pinned eager; the budget then keeps the two next-most-valuable tools and defers the remaining nine, cutting the up-front tool-definition cost by ~40% while keeping every declared workflow's critical tools one token away, not one search away.
python -m pytest # 48 tests, ~0.3s, no networkThe knapsack core is verified against a brute-force optimum over hundreds of random instances, plus invariants: never exceeds budget (any granularity), pinned tools always eager, infeasibility when pins bust the budget, determinism, and free zero-token items. Parsing, valuation, plan projection, the coverage-safety policy, and every CLI exit code are covered too.
MIT — see LICENSE.