Context Engineering and Prompt Management

Context Engineering and Prompt Management

Context Window Management — Stack

Context window management › Stack

21 of 57 in this book · 3 min read

Technology landscape as of 2026-10-10. Knowledge cutoff May 2026.

Selection criteria

Three separate things have to be sourced: an accurate count, an accurate limit, and a mechanism for continuing past it.

  • Counting fidelity. Whether the counter is the target model's actual tokenizer or an approximation, and whether it accounts for message framing, tool declarations, and image or audio content that is priced in tokens but is not text.
  • Limit freshness. Where the context limit for a given model comes from, how quickly that source updates when a provider ships a new build, and what happens when the model is not in the source at all.
  • Counting cost. Whether a count requires a network round-trip. A per-call remote count adds latency to the hot path and makes assembly depend on a second service.
  • Rollover support. Whether the runtime offers a defined way to continue a session past the wall, and whether the hand-off artefact is inspectable or buried inside the framework.
  • Prefix-cache interaction. Whether the mechanism preserves an exact leading byte sequence across turns, since any trimming that rewrites the front defeats caching entirely.
  • Occupancy telemetry. Whether used tokens, the high-water mark per session, and boundary events are emitted as metrics rather than inferred from billing.
  • Effective-length evidence. Whether there is a way to establish how much of the window the model actually uses well, as opposed to how much it accepts.

Options

Option Best for Watch out for
Local tokenizer libraries (tiktoken, Hugging Face tokenizers, SentencePiece) Exact counting with no network call, where the model's tokenizer is published Only correct if the vocabulary matches the deployed build; message framing and tool declarations are counted by the provider and not by you
Provider token-counting endpoints Models whose tokenizer is not published, and for authoritative counts including framing A network call on the assembly path; rate limits apply; some providers price the call
Model metadata registries (community-maintained context and price maps, provider model-list APIs) Keeping limits current across many models without editing code Community data lags new releases and occasionally carries wrong values; a missing entry has to fail loudly rather than default
Character or word heuristics Rough guards far from the boundary, and languages where the ratio is stable Underestimates badly on code, identifier-heavy JSON, and non-Latin scripts — precisely the inputs that approach the limit
Framework trimming utilities (message trimmers, windowed buffers, summarising buffers) Getting a defensible behaviour at the boundary without writing it Default strategies drop from the front, which discards the task definition; most rewrite the leading bytes and break prefix caching
Session rollover with a hand-off artefact (agent frameworks with summary-and-continue, OS-style paging designs) Long-running assistants that must survive far past one window The hand-off becomes the session's memory, so its quality is the product's quality; references to earlier turns stop resolving
Serving-side prefix caching (vLLM and SGLang automatic prefix caching, provider cache features) Reducing the cost of a large stable leading region that genuinely repeats Cache hit depends on exact prefix equality; eviction is invisible to the caller, so savings vary by load
Long-context model variants and context-extension techniques Workloads that genuinely need more room and can pay for attention over it Accepting more tokens is not using them well; verify retrieval from depth before planning capacity around the headline number