Skip to main content
memory.contextBudget controls the text gathered from memory stores. It does not cap the entire prompt, conversation history, tool schemas, model output, or provider cost. Use history limits and cost budgets separately.

Configuration

This host factory receives its configured model and storage:
The host closes the Agent after runs drain, keeping shared storage open until the final owner closes it. Validate positive finite budget/priority values in application configuration.

Default Priorities

How Budget Allocation Works

The implementation measures assembled sections. If their content fits the total budget, it includes them. Otherwise it visits higher-priority sections first, includes those that fit the remaining total, and attempts line-based trimming when sufficient space remains. It retains headers and walks data lines from the end. Although the implementation calculates proportional allocations internally, v4’s inclusion loop uses the remaining total budget. Do not assume each section receives a guaranteed percentage. Higher priority does not guarantee every important fact survives; inspect the output with representative records.

Custom Priorities

Override only the sections that matter to your task. Compare answers and actual context before and after a change. A lower budget can remove useful information; a larger one can increase input cost and distract from the current question.

Inspecting Token Usage

This diagnostic helper receives an initialized manager and an identity already verified by the host:
Token counting is an estimate; separators, model-specific tokenization, and the rest of the prompt affect actual usage. Treat inspected context as user data and avoid indiscriminate logging.

Without a Budget

Omitting contextBudget assembles the available memory sections without this trimming pass. memory.maxMessages and memory.maxTokens control session history separately. Test both history and memory context when investigating a model context-window failure.