Brain and worker context budgets
Status: Ready
Truth label: Current
Audience: Fleet operator
Reader outcome: Use brain and worker context budgets in Cortex, with every control, its verification, and its limits stated.
Last verified: 2026-09-13
Open Settings > Context budgets. Manage Cortex also opens the same editor. See Cortex management for search and keyboard access.
The same editor is available from New task > Edit context budgets for all agents. It stays available when the task inherits execution defaults and preserves the task form while you edit budgets.
Open Chat > Context budgets to manage application input budgets for Brain and workers. A profile can cover every provider/model, one provider, or an exact model. Exact model matches take precedence, then provider-specific matches. Inspect the saved effective budget for the selected chat model before using it. Save, reload, history restore, and native JSON import/export are available in the editor. Stale saves preserve unsaved values.
To raise limits across every engine and model, enter the total context estimate and reserves, select Apply limits to all agents and models, then Save all budget profiles. This copies the limits to every existing profile, including exact model overrides, and adds a wildcard profile if missing. The available-input display updates as you edit. New profiles copy the wildcard profile's limits. Profiles remain individually editable for later exceptions. Edits and the bulk action take effect only after saving.
What the budget controls
Brain's graph applies one allocation before every provider reasoning call, including later tool rounds. It counts the protected system instructions, active voice/lens guidance, current request and applicable authored context, optional style examples, automatic source passages, attachments, prior dialogue, tool schemas, and the current tool exchange.
The current request and authored context are preserved. A protected prompt that cannot fit returns an actionable error before that generation call. It does not silently cut the user's facts or constraints. System voice guidance remains protected even when optional examples cannot fit.
Recent dialogue receives up to one third of the remaining input allocation. Prior user exchanges stay whole and form a contiguous recent suffix. Remaining space goes to static examples, learned examples, and eligible reference blocks. A section too large to fit is omitted as a whole, allowing later smaller sections to fit. An attached file is currently one block after its attachment-specific extraction limits. Automatic passages are separate blocks when all automatic context has passage metadata; legacy mixed memory output remains one block.
Tool call arguments and call/result IDs remain intact. Large tool results share available space and are capped at an 8,000-byte estimate per result. A shortened result contains a visible notice asking the model to obtain narrower evidence. Reports retain original/provided hashes and sizes. If required tool protocol still cannot fit, that provider call is stopped. The model also receives a notice when optional references or dialogue were omitted.
Estimates and reserves
These are application budgets, not an advertised model capacity. The estimator counts UTF-8 bytes plus explicit message framing and tool schema serialization. It is conservative for typical text but is not an exact tokenizer or protocol measurement. The overhead reserve allows additional provider framing; unsupported multimodal payloads and provider internals do not have a proven token bound here.
The default application limit is 262,144 estimated tokens, with 2,048 reserved for the answer and 1,024 for protocol overhead, leaving 259,072 for input. This default applies to Brain and every worker engine when no saved profile matches. Existing saved limits remain authoritative until edited. Brain's Ollama calls also clamp the configured application context to ollama_num_ctx. Hosted model profiles use the operator's configured application limit; the application does not infer undocumented model capacities. The editor accepts total limits up to 1,048,576. The answer reserve leaves input space and does not change the provider's output-generation limit.
Budgets are frozen at the first graph allocation in a Brain request. Changing them while tools run affects subsequent requests. Older history can be omitted before newer exchanges. This deterministic order is not measured relevance ranking; relevance experiments remain separate work.
Inspect what reached the model
Open the response's generation settings in Cortex. Each reasoning round reports the chosen provider/model profile and revision, input estimate, tool schema estimate, reserves, and included/omitted sections. Source passages omitted during allocation are excluded from supplied-source counts. Attached-file records distinguish extraction from later prompt inclusion. A shortened retrieval tool result leaves per-passage inclusion unconfirmed, so its passages are not asserted as supplied evidence.
The generation summary's example/source counts represent material supplied in at least one recorded reasoning round. Inspect individual rounds for the final prompt. No causal influence percentage or writing-quality improvement is inferred from these counts.
Writing comparisons freeze the budget in their manifest and check the complete frozen candidate prompt before generation. They do not silently remove examples to make a comparison fit. Budget changes separate aggregate comparison groups. The optional local polish pass checks its complete fact-preserving prompt with the revision model's budget; failure retains the original draft and records the reason.
Storage and remaining scope
prompt-budgets.json in the Brain data root owns versioned profiles and configuration history. Atomic file replacement and the writing-store lock protect saves. Per-round allocation evidence travels with generation metadata; comparison evidence and revision reports retain their own checks. Back up runtime settings and those records together.
Combined Brain and worker-owned prompt allocation now ships. It does not control private prompts or tool schemas inside external CLI worker engines, transport attachments between hosts, expand long documents around relevant passages, or replace provider tokenization with an exact count. Those remain tracked work. Existing section-specific extraction/retrieval limits still apply before the shared allocation.
Tests: tests/test_prompt_budget.py, comparison/revision tests, and tests/browser/prompt-budgets.mjs. They cover protected-request failure, whole section/history selection, tool protocol retention, provider resolution, frozen settings, generation evidence in regular/streamed chat, stale edits, history, and import/export. No paid or live model is used by these fixtures.
Completed Brain turns now retain each allocated application model input. Use Inspect writing turn in Cortex to inspect or export it. Budget omission metadata and captured messages describe the same allocation; provider SDK wire serialization is outside this capture.
Worker prompts and attempts
The same Cortex profiles now cover worker-owned inputs. The worker reads the active profiles once when an attempt starts. It selects the profile using the engine that actually runs and the model that engine accepts. Claude Code maps to Anthropic, Codex to OpenAI and Codex OSS to Ollama. Antigravity uses the explicit model family: Gemini maps to Google, Claude to Anthropic and AGY-hosted GPT-OSS to OpenAI. Unknown explicit AGY families use provider-wildcard profiles. These are budget namespaces, not authentication or billing routes; configure verified limits for each exact AGY model. An unspecified AGY model retains Google wildcard-model selection. A CLI default model is unknown to the application, so only wildcard model profiles apply. Inspect saved worker budget previews this normalization without launching a task. Direct executors use their configured provider/model. Direct Ollama requests set num_ctx to the chosen profile's context estimate; Brain's own host setting still clamps Brain calls separately.
If Brain cannot supply valid profiles, the attempt records an application fallback with the default limits. Saved profile changes affect subsequent attempts. An ongoing attempt keeps its original version. New and retried recurring stages follow the same rule.
CLI dispatch combines the persona, task, brief, handoff, approved context, voice/lens instructions, method, repository constraints, verification instructions and optional references. Single-response workers bound execution and automatic skill selection. Tool-loop workers bound planning, each reasoning call and reflection. A required prompt that exceeds the allocation stops before that provider or CLI call. Core task facts and required guidance are never silently shortened to fit. Some multi-skill methods exceed the default allocation even without optional references. Configure a larger appropriate profile in Cortex before dispatching them.
Whole voice examples receive priority over automatic references. A tool loop then allocates up to one third of its remaining space to complete recent exchanges. Source evidence, past outcomes, project memory, session context and generated plans fill remaining space in deterministic order when that phase uses them. A block that does not fit is omitted whole. Existing extraction and skill-loader limits still apply before this allocation. This is an input allocation policy, not a measured ranking improvement.
The original task remains present in every tool-loop call. The current assistant action and repair instructions remain intact. Only identified tool observations can be shortened, to a shared available allocation capped at an 8,000-byte estimate each. Shortened observations contain a notice requesting narrower evidence. Older exchanges can be omitted together; the in-memory conversation remains unchanged. Persisted step excerpts retain their existing capture limits.
Open a task's Context allocation for this attempt details in Cortex. Each record includes the phase, profile version, estimate, required-input size, section hashes and inclusion decisions. Retrieved evidence and supplied inputs have distinct meanings: a retrieved block can be omitted later. CLI traces also keep the exact dispatched prompt alongside the allocation record. Native CLI private prompts, resumed history, tool schemas and later conversation remain outside application control. Cross-host raw-artifact transport and document expansion remain separate work.
Verification includes tests/test_worker_prompt_budget.py and the worker preview in tests/browser/prompt-budgets.mjs, plus the existing executor and Brain-budget regressions. Fixtures invoke no paid model or actual coding CLI.
Recover a task blocked by required context
The error Protected worker input and current action need ... means the application stopped dispatch before launching that model call. The reported estimate counts UTF-8 bytes and framing. It is not a tokenizer measurement. Selected workflow skills and repository rules are protected, so even a short task description could exceed the former 29,696 input allocation. An error still showing that limit identifies an older saved profile, a frozen attempt, or an older worker using its fallback.
Open New task > Edit context budgets for all agents or Manage Cortex > Context budgets. Set Total context estimate to leave enough input after both reserves. For example, 262,144 total leaves 259,072 for input with the default reserves, covering the reported 47,606 and 50,087 required-input estimates. Select Apply limits to all agents and models to update older exact-model limits along with the wildcard. This is an application setting, not a claim about the model's capacity.
Save all profiles, then use Inspect saved worker budget with the task's engine and model to verify the effective input allocation. Retry the failed task to load the new version. Saved-profile updates need no service restart. The failed attempt retains its old allocation record. Worker code updates are needed to change an older worker's offline fallback. Keep the wildcard profile when adding an exact model profile so other models retain shared coverage.