# Context Budget

> Pick the optimal set of skills/docs to load for a task under a token budget — an exact 0/1 knapsack (maximize relevance while summed token cost stays under budget), not an LLM "decide what's relevant" call. Deterministic, stdlib, 0 cloud tokens. Cuts the always-on context cost (loading the whole skill catalog every turn). Use when you want to load only the most relevant context within a budget, o…

- **Type:** Skill
- **Install:** `agentstack add skill-zedarvates-botte-secrete-context-budget`
- **Verified:** Yes — security-reviewed for prompt injection and unsafe behavior
- **Seller:** [zedarvates](https://agentstack.voostack.com/s/zedarvates)
- **Installs:** 0
- **Category:** [AI & ML](https://agentstack.voostack.com/c/ai-and-ml)
- **Latest version:** 0.1.0
- **License:** MIT
- **Upstream author:** [zedarvates](https://github.com/zedarvates)
- **Source:** https://github.com/zedarvates/botte-secrete/tree/main/skills/context_budget
- **Website:** https://github.com/zedarvates/botte-secrete

## Install

```sh
agentstack add skill-zedarvates-botte-secrete-context-budget
```

Requires the [AgentStack CLI](https://agentstack.voostack.com/docs/cli). Works with Claude Code, Cursor, and any MCP-compatible agent.

## About

# context_budget — optimal context under a token budget

The OR-Tools principle applied to the agent's always-on cost: choosing *which*
skills/docs to load is a **0/1 knapsack** — maximize total relevance while the
summed token cost stays under a budget. That's an exact deterministic solver
(stdlib DP), so it costs **0 tokens** and beats the greedy "take the top matches
until full" heuristic.

```bash
python -m skills.context_budget.cli "optimize slow postgres queries and add tests" --budget 3000
python -m skills.context_budget.cli "" --budget 4000 --json
```

## How it selects

1. **Rank** — score every skill against the task lexically ([[skill_finder]],
   0 tokens), with each skill's token cost.
2. **Knapsack** — `knapsack(items, budget)` finds the subset that maximizes
   summed relevance subject to `Σ tokens ≤ budget` (exact DP, token costs scaled
   to bound the table). Optimal, not greedy.
3. **Frame** — report the chosen set, tokens used, relevance captured, and the
   saving vs loading the whole catalog.

On this repo a typical task loads ~4 skills (~2k tok) instead of the whole
~36-skill catalog (~15k tok) — an ~85% cut in always-on context for that task.

The `knapsack(items, budget)` engine is generic (takes `Item(name, kind, tokens,
relevance)`), so docs ([[docs_steward]]) or any context source plug in the same
way. Exposed via [[llm_mcp]] as `context_budget`. Related: [[skill_finder]]
(ranking), [[metrics]] (measures the always-on cost this cuts).

First of the deterministic "solver" hybridizations (OR-Tools-inspired): exact
combinatorial optimization replacing LLM reasoning for structured decisions.

## Source & license

This open-source skill is cataloged on AgentStack and links to its original source — we do not rehost the code.

- **Author:** [zedarvates](https://github.com/zedarvates)
- **Source:** [zedarvates/botte-secrete](https://github.com/zedarvates/botte-secrete)
- **License:** MIT
- **Homepage:** https://github.com/zedarvates/botte-secrete

Install and usage instructions live in the source repository linked above.

## Pricing

- **Free** — Free

## Security capabilities

Automated source analysis of v0.1.0 — what this tool can access:

- **Network access:** no
- **Filesystem access:** no
- **Shell / process execution:** no
- **Environment & secrets:** no
- **Dynamic code execution:** no

*"Yes" means the capability is present in the source — more access means more to trust, not that it is unsafe.*


## Versions

- **0.1.0** — security scan: passed — Imported from the upstream source.

## Links

- Listing page: https://agentstack.voostack.com/l/skill-zedarvates-botte-secrete-context-budget
- Seller: https://agentstack.voostack.com/s/zedarvates
- Browse the marketplace: https://agentstack.voostack.com/browse

---
Listed on AgentStack — the marketplace for AI agent skills and MCP servers. Every listing is security-reviewed. Creators keep 70%.
