Question-led guide · how-to

How do I allocate a context-window budget?

A context-frame budget for instructions, authority, state, evidence, tools, history, uncertainty, and output reserve in production agents.

Direct answer

Allocate a context window as a frame with protected reserves, not a bucket filled until the model limit. Reserve space first for output and tool results, then protect current instructions, authority, task state, and required evidence. Give optional history and candidate retrieval bounded pools with eviction rules. Measure task success, evidence use, and truncation failures by slice before changing any allocation.

Scope

Use this guide to design prompt assembly for an agent that combines instructions, identity and authority, workflow state, retrieved evidence, tool contracts, conversation history, and generated output. It is an allocation method for a new or redesigned frame. If the problem is reducing an existing oversized prompt, use the context-shortening guide.

Why it happens

Most context windows are assembled by append order. System instructions arrive first, conversation grows, retrieval adds the top K chunks, tools append verbose results, and output gets whatever space remains. Under pressure, a library truncates old messages or the API rejects the request. Neither behavior knows which information is binding.

An agent needs asymmetric protection. Losing conversational courtesy is cheap. Losing the target tenant, a policy exception, an unresolved approval, or the source of a critical claim can be severe. A budget makes those priorities explicit before the system reaches its limit.

Diagnosis

Instrument the compiled frame, not only the user prompt. For a representative task set, record tokens by context class, material omitted, compression performed, retrieval candidates rejected, reserved output, and actual output. Identify where each failure came from:

  • required evidence never retrieved;
  • retrieved evidence displaced instructions or state;
  • a tool schema or result consumed unexpected space;
  • history was retained after its decisions were already normalized;
  • output or structured fields were truncated;
  • two sources conflicted but only one survived allocation.

The diagnostic question is not “Which message is longest?” It is “Which retained or evicted object changed the task decision or its verifiability?”

Solution

Compile context in classes. Protect a fixed-order core: current policy and instructions, actor and authority, task objective, committed state, invariants, open decisions, and required evidence. Allocate bounded pools to candidate retrieval, examples, and recent interaction. Reserve output and at least one tool-error/result envelope before filling optional pools.

Each object needs a priority, maximum size, expiry, provenance reference, and eviction behavior. When the core itself exceeds the frame, fail compilation with a typed error; silent truncation is unsafe. When optional evidence is evicted, record what was lost so the agent can request it later.

Test several allocations with the same model and tasks. Report outcome, serious failures, evidence support, latency, total calls, and outcome cost.

Artifact

Start with a template rather than universal percentages:

Frame class Minimum reserve Maximum Eviction/compression rule Failure signal
Instructions and policy Versioned; never silently truncate policy_overflow
Identity and authority Typed fields; revalidate at action authority_missing
Current task state Snapshot plus event references state_incomplete
Required evidence Keep claim/source/limit units evidence_missing
Candidate retrieval Rank, diversify, and fetch on demand candidate_evicted
Tool schemas/results Narrow schemas; normalize outputs tool_frame_overflow
Interaction history Extract decisions, then age out prose history_compacted
Output and recovery reserve Protected before optional fill output_at_risk

Version the completed frame policy and save the compiled-frame manifest for every evaluated run.

Common mistakes

  • Setting top_k without a token or diversity budget.
  • Counting only document text and omitting message, schema, and serialization overhead.
  • Letting optional retrieval displace authority or current state.
  • Silently truncating the core when it exceeds the model limit.
  • Optimizing one call while compaction and recovery create more total work.

Evidence

  1. Context engineering involves selecting and maintaining the useful information available to an agent under a finite attention budget.

    Anthropic's engineering article discusses context selection, compaction, structured notes, tool results, retrieval, and long-running agents.

    Primary source · official-doc · checked Aug 26, 2026

    Limit: The article is first-party guidance and does not supply a universal percentage allocation or prove its patterns for every model.

  2. Nominal context length and reliable task performance over long inputs are different properties.

    RULER evaluates long-context models with multiple task types and reports model-specific effective-context behavior in the studied settings.

    Primary source · paper · checked Aug 26, 2026

    Limit: Benchmark results depend on tasks and model versions; they do not determine a production agent's safe budget.

  3. A context allocator should protect decision-critical fields and expose pressure, eviction, and missing-evidence events.

    The context-frame template below turns prompt assembly into a versioned engineering policy that can be evaluated.

    Signal Studio author framework · reviewed Aug 26, 2026

    Limit: The initial numbers must be learned from representative tasks and revalidated when models, tools, or policies change.

Limitations

Tokenizers, provider message accounting, tool schemas, reasoning behavior, and model context limits differ and can change. A budget prevents uncontrolled assembly but cannot guarantee that a model will attend to every retained fact or that retrieval found the needed evidence.

FAQ

What percentage should I reserve for output?
There is no universal percentage. Set a maximum output contract by task class, include tool-call and structured-output overhead, then validate truncation and latency behavior with the exact model and API.
Should unused output reserve be filled with more documents?
Only when those documents pass relevance, authority, and provenance checks. Keeping headroom is often safer than adding low-value evidence that increases distraction or forces late truncation.

Continue within Context engineering, memory, and state, or use one of these adjacent diagnostics:

Editorial QA: automated native-English, structure, source-presence, and link checks completed . This record is not an independent expert endorsement. Review boundary.