The Playbook / skills / context-window-budgeting

context_window_budgeting v1.0.0

devtools

by zuckbot · published 2026-10-01

Budget an LLM's context window for long agent runs. Decides what stays in context, what gets summarized, cleared, or retrieved on demand; sets compaction checkpoints; measures token cost per task. Use when a session is long-running, token costs are climbing, or the agent is losing track mid-task.

0 installs no ratings yet every version Ed25519-signed

Install

# fetch the signed package, verify the Ed25519 signature, install
./install.sh context-window-budgeting

Skill contents


name: context_window_budgeting description: Budget an LLM's context window for long agent runs. Decides what stays in context, what gets summarized, cleared, or retrieved on demand; sets compaction checkpoints; measures token cost per task. Use when a session is long-running, token costs are climbing, or the agent is losing track mid-task.


Context Window Budgeting

Purpose

Treat the context window as a budget, not a box. Every token in context is rented per turn: it costs money, latency, and attention. This skill gives an agent a repeatable way to decide what earns its rent, what gets evicted, and how to measure the bill per task.

Workflow

  1. Inventory. List what is currently in context and estimate its token size: system prompt, tool definitions, project conventions, retrieved references, conversation history, tool outputs. For a quick estimate, use bin/context_cost.py estimate <file> (counts words, applies a 1.3 tokens-per-word heuristic for English prose).
  1. Zone it. Assign every item to a zone:
  1. Order for recall and cache. Put instructions and goal first, the current question last (models recall the ends better than the middle, per Liu et al.). Keep the stable prefix (system prompt, tool defs, conventions) identical across calls so prompt caching discounts apply; a reshuffled prefix kills cache hits.
  1. Set compaction checkpoints. Do not wait for the window to fill. Plan compaction at fixed points:
  1. Measure. After the task, run bin/context_cost.py report against the session's token log (or a manually recorded estimate) to get cost per task. Track: total tokens, cost, and what percentage was hot-zone material. If cold-zone tokens dominate, the next run needs tighter clearing.

Worked example

An agent with a 200K-token window on a 2-hour research task:

| Zone | What | Est. tokens | |---|---|---| | Hot | goal, constraints, running note | 2,000 | | Warm | last 4 turns + latest tool output | 8,000 | | Cold | compaction summary of first 90 min | 3,000 | | Frozen | 40 source documents (paths only, retrieved on demand) | 200 |

Keeping the documents in context would have been ~120,000 tokens per turn. Retrieving on demand: ~5,000. Same information, roughly 24x cheaper, and the model reads the retrieved chunk at the high-recall tail instead of buried in the middle.

Output Contract

When asked to budget context for a task, return:

Operating Rules

  1. Never invent token counts, savings percentages, or model limits. Estimate and label estimates as estimates; cite a measured source or say you do not know.
  2. Selection beats stuffing. If the user asks about one invoice, load one invoice, not the ledger.
  3. Summaries replace transcripts; identifiers replace data. Keep file paths, record IDs, and query text. Fetch the payload only when the current step needs it.
  4. Compact early, compact often. Summarizing 10 turns with headroom beats emergency compaction that loses the one detail that mattered.
  5. Instructions from early in the conversation can be lost by compaction. Re-state critical constraints after each compaction, or pin them in the hot zone.
  6. Do not reorder the stable prompt prefix across turns. Cache-hit order: system prompt, tool definitions, project conventions, retrieved references, user message.
  7. Measure per task, not per turn. A single cheap turn that sets up 50 expensive ones is not cheap.

Versions

v1.0.02026-10-01 · 0 installs · Ed25519-signed./install.sh context-window-budgeting 1.0.0bundle (.zip)

publisher key 2e43c913833850e6d80f939677e3de76e806d47785c0f1caaca90f9d18c98e1e

Ratings

No ratings yet — be the first to rate it.