agentsclimarketplace

Context window management

Skill Amey-Thakur/AI-SKILLS/skills/llm-engineering/context-window-management

Plug-and-play skills and prompts for every AI coding agent

Install
npx -y skills add Amey-Thakur/AI-SKILLS --skill context-window-management

Assembled from the repository path, not quoted from the project. Check it against their README if it does not work.

2 things to look at

  • 19 days oldThe repository was created 19 days ago. New is not bad, but a brand new repository carrying a familiar-sounding name is the shape a typosquat arrives in, and there has been no time for anyone else to find a problem with it.
  • 4 stars4 stars. Stars are a popularity signal and not a quality one, but at this level it is likely that nobody has read this closely except its author, and you would be relying on your own review.

What its author says it does

Copied from the file, not written here

Budget tokens across system prompt, history, and retrieval, with compaction that keeps what matters. Use when building long-running LLM applications or debugging context overflow and mid-conversation amnesia.

SKILL.md

3.7 KB, as published. Nobody here has run it

Context window management

Context is a budget, and everything competes for it: instructions, history, retrieved documents, tool results. Manage it like memory in an embedded system: allocated by purpose, compacted under pressure, with the invariant that the most decision-relevant tokens survive.

Method

  1. Partition the budget explicitly. Fixed allocation for the system prompt (keep it lean: every instruction competes with data for attention), a reserve for the response, and the remainder split between history and retrieval by the application's shape (chat leans history; Q&A leans retrieval: see rag-pipeline). Know your model's real window and your p95 usage against it: overflow failures are a capacity-planning problem (see capacity-planning).
  2. Compact history hierarchically, not by truncation. Rolling summarization: old turns compress into a summary block (decisions made, facts established, current goal), recent turns stay verbatim: the summary is regenerated as turns age past a threshold. Naive head-truncation deletes the instructions and early decisions that the conversation still depends on (the mid-conversation amnesia bug).
  3. Preserve the load-bearing tokens. Some content must never compact away: the task definition, hard constraints, user identity/preferences, schema definitions for structured output (see structured-output), and safety instructions. Pin them (re-inject after compaction) rather than trusting the summarizer to keep them (see agent-memory for durable cross-session state; this skill is within-session).
  4. Trim retrieval to relevance, not availability. Rank retrieved chunks, take top-k under the retrieval budget, and prefer many small relevant chunks over few large loose ones (see embeddings-selection's chunking interplay); deduplicate near-identical chunks (retrieval loves returning five copies of the same paragraph); summarize tool results that are data dumps before they enter context (a 50KB JSON response is usually 500 tokens of decision-relevant content wearing a payload).
  5. Watch position effects. Models attend best to the start and end of context: instructions up front, the immediate question and freshest data near the end, the middle for reference material: and verify with needle tests on your actual layout when correctness depends on mid-context content (long-context claims degrade under load; measure, do not trust the spec sheet: see llm-eval-design).
  6. Instrument token flows in production. Per-request token counts by section (system/history/retrieval/ response), compaction frequency, and overflow events (see llm-observability): rising history share means the compaction threshold needs tuning; cost tracks tokens linearly, so this dashboard is also the bill (see llm-cost-latency).

Boundaries

  • Bigger windows are not a strategy: cost scales with tokens, latency grows, and attention quality drops before the hard limit; compaction discipline pays at every window size.
  • Summaries are lossy by design; applications where exact history matters (legal, medical, audit) need verbatim logs outside the context (see audit-logging) with retrieval back in, not longer summaries.
  • Prompt caching changes the economics of stable prefixes (see llm-cost-latency) and rewards a fixed system-prompt layout; design the partition with caching in mind from the start.

Keep looking

Skills are one crate of 328,083. Ordering is by how many stacks a row turns up in, so the top of any crate is what has actually been picked rather than what has the most stars.