# Where must an instance arbitrate a context budget when tool schemas and recalled memory compete for the same token reserve **Date of Record:** 2026 November 26 **Scope:** Applies to any agent loop with a pre-inference context assembler that partitions a fixed token window among (a) system/instruction slots, (b) tool schema definitions, and (c) retrieved memory or history. Does not apply to stateless single-shot calls with no tool registry or to systems where schema and memory share an unbounded window. ## Core Distinction The failure is not "running out of context." It is a *scheduler ordering inversion*: the budget allocator reserves tool-schema space **after** memory recall has already been admitted, but **before** instruction slots are validated. Under pressure, the allocator trims the lowest-priority bucket first—typically memory—yet the tool schemas it protects are *static per turn* while memory is *load-bearing for the current step*. The instance therefore evicts the fact it needs to call the tool correctly and preserves a schema it may never invoke. The invariant that breaks: *the token reserve allocated to a bucket must be a function of that bucket's probability of use in the imminent step, not its declaration order in the assembler.* ## What Was Observed A retrieval-augmented agent with 12 registered tools and a 32k window. Assembler priority order (hardcoded): `instructions > tool_schemas > memory > scratchpad`. At turn N the memory store returned 9 chunks averaging 380 tokens (≈3.4k). Tool schemas totaled 6.1k tokens. Instructions 1.2k. Scratchpad carried 14k of prior reasoning. Total ≈24.7k — under budget, no trimming, correct behavior. At turn N+3 the scratchpad had grown to 19.8k. The assembler computed headroom and entered trim mode. It evicted memory down to 2 chunks (760 tokens) to fit. The evicted chunks included the single record mapping the customer's account alias to the internal `cust_id` required by `lookup_account`. The instance still held the `lookup_account` schema (protected bucket) and proceeded to call it with a hallucinated `cust_id` derived from the alias string. Tool returned `NOT_FOUND`. The agent retried three times with mutated IDs, then declared the account nonexistent. No error was raised anywhere—the budget was respected, the schema was intact, the call was well-formed, and the answer was wrong. The trace signature is specific: **schema present, argument fabricated, retrieval count at floor, no budget exception.** A post-hoc auditor sees a valid tool call with an invalid argument and cannot distinguish this from a model reasoning error. ## Condition of Validity The inversion only produces a wrong answer when all of the following hold: 1. A tool's *correct invocation* depends on a memory-resident binding (an ID, a unit, a schema version, a policy constant) rather than on the user's literal text. 2. The tool schema is in a higher-priority bucket than the memory that binds its arguments. 3. Trim mode is triggered by scratchpad or history growth, not by schema growth—so schema protection is never itself contested. 4. The instance has no mechanism to detect that a required binding was evicted (no "argument provenance" check). Remove any one and the failure does not occur: if the binding arrives in the user turn it survives; if schemas and memory share a bucket they compete honestly; if the model can flag "I lack the binding" the wrong call becomes a clarifying question. ## Decision Boundary The correct arbitration is not "raise the memory floor"—that just moves the cliff. The boundary is: **a bucket may only be trimmed below the level needed to satisfy a currently-admitted tool's argument contract if that tool is simultaneously demoted out of the active schema set.** In other words, memory eviction and schema eviction must be *coupled*: you cannot keep a tool callable while evicting the state that makes its arguments valid. Concretely, the assembler must, before finalizing the budget: - For each tool in the active schema set, compute the set of memory keys its parameters require (declared as `requires_binding` in the tool manifest). - If trimming would remove any such key, either (a) preserve the key and trim elsewhere, or (b) drop the tool from the active schema set so the model cannot emit the call. - Never emit a schema whose argument bindings are not resident. This converts a silent wrong-answer into either a correct call or an explicit "tool unavailable this turn" signal—both auditable. ## Operational Effect With coupling enforced, the turn-N+3 case resolves differently: the assembler sees that trimming memory would orphan `lookup_account`'s `cust_id` binding, so it either keeps the binding (evicting scratchpad summary instead) or removes `lookup_account` from the schema set. The model then either calls correctly or reports the tool as unavailable and asks for the account number. The failure mode becomes a visible capability degradation rather than a fabricated argument. The cost is that schema availability becomes dynamic and must be re-advertised each turn; downstream planners that assume a fixed toolset will see tools appear and disappear. That is the price of the invariant: **callability and argument-validity are the same resource and must be allocated together.** ```python from dataclasses import dataclass, field from typing import Dict, Set class BindingEvictionError(RuntimeError): """Raised when a budget plan would leave a callable tool without the memory-resident bindings its arguments require.""" pass @dataclass class ToolManifest: name: str schema_tokens: int requires_binding: Set[str] = field(default_factory=set) @dataclass class BudgetPlan: memory_keys: Set[str] active_tools: Set[str] memory_tokens: int schema_tokens: int def couple_arbitration( memory: Dict[str, int], # key -> token cost tools: Dict[str, ToolManifest], memory_budget: int, schema_budget: int, ) -> BudgetPlan: # Start from full admission, then trim memory to budget. admitted_keys = set(memory) admitted_tools = set(tools) while sum(memory[k] for k in admitted_keys) > memory_budget: # Evict the most expensive non-required key first. required = set() for t in admitted_tools: required |= tools[t].requires_binding candidates = [k for k in admitted_keys if k not in required] if not candidates: break victim = max(candidates, key=lambda k: memory[k]) admitted_keys.discard(victim) # Enforce coupling: no active tool may reference an evicted binding. for t in list(admitted_tools): missing = tools[t].requires_binding - admitted_keys if missing: admitted_tools.discard(t) schema_tokens = sum(tools[t].schema_tokens for t in admitted_tools) if schema_tokens > schema_budget: # Schema set itself over budget: drop tools until it fits, then # re-run the binding check because dropping a tool may free a # required key for another. raise BindingEvictionError( f"schema set {sorted(admitted_tools)} costs {schema_tokens} > " f"budget {schema_budget}; cannot finalize plan without " f"re-arbitrating bindings" ) mem_tokens = sum(memory[k] for k in admitted_keys) return BudgetPlan(admitted_keys, admitted_tools, mem_tokens, schema_tokens) def guarded_call(plan: BudgetPlan, tool: str, args: Dict[str, str]) -> None: if tool not in plan.active_tools: raise BindingEvictionError( f"tool {tool!r} not active this turn; bindings for its " f"arguments were evicted or schema dropped" ) # ... dispatch ... ```