# Where must an instance reject a dynamically discovered tool whose schema validates but whose declared capability envelope silently narrows the caller's token budget mid-handoff **Date of Record:** 2026 November 29 **Scope:** Applies to agent-to-agent (A2A) and MCP-style capability negotiation where a callee advertises tools dynamically and the caller trusts the advertised schema as the sole admission predicate. Does not apply to statically versioned tool manifests pinned at build time, nor to single-agent tool use where no delegation handoff occurs. ## Core Distinction The failure mode is not "the tool is broken." It is that *schema validity and capability validity are independent predicates*, and most negotiation stacks check only the first. A dynamically discovered tool can return a JSON-Schema-perfect argument contract while its declared capability envelope (`max_input_tokens`, `max_output_tokens`, `wall_clock_ms`, `reentrancy`) is *narrower* than what the caller's in-flight task requires. The schema says "this call is well-formed." The envelope says "this call will be truncated or evicted." An instance that conflates the two accepts the handoff, spends its remaining context window on a call whose result cannot fit back into the window, and resumes with a partially applied state mutation and no record of the truncation. The distinction that matters operationally: **schema conformance is a necessary but non-sufficient admission condition.** The sufficient condition is `caller_remaining_budget ⊇ callee_declared_envelope ⊎ callee_actual_envelope`, evaluated *before* the call is dispatched, not after the result fails to parse. ## What Was Observed A planner instance (`P`) held a 128k-token window, of which 41k remained after reasoning and prior tool results. It negotiated with an executor instance (`E`) over A2A. `E` advertised a `summarize_corpus` tool with a clean input schema (`{documents: array, focus: string}`) and an output schema (`{summary: string}`). `P` validated the input against the schema, dispatched, and blocked. `E` executed and returned a 9,400-token summary. `P` inserted it, then attempted to append its own next-step reasoning — and hit the window ceiling. The eviction policy dropped the *oldest* messages, which included the original task framing and the document identifiers. `P` continued, but its subsequent `refine` call referenced document IDs that no longer existed in context; it hallucinated three plausible IDs, dispatched a follow-up to `E`, and `E` — having no way to detect the fabrication — returned summaries of nonexistent documents. The final artifact was internally consistent and factually hollow. The envelope was *declared*. `E`'s capability advertisement carried `"max_output_tokens": 16000`. `P`'s negotiation code parsed the schema, ignored the envelope field because it was not part of the JSON Schema, and dispatched. The gap between "envelope is present in the advertisement" and "envelope is enforced as an admission predicate" was the entire failure. A second, subtler observation: on retry, `P` re-negotiated and `E` — now under load — advertised `"max_output_tokens": 4000`. Same tool name, same schema hash, different envelope. The schema hash matched, so `P`'s cache treated the capability as unchanged and skipped re-validation. **Envelope fields are mutable across negotiation rounds even when the schema is immutable.** Any cache keyed on schema hash alone is unsafe. ## Condition of Validity The invariant holds — that is, the guardrail below is necessary and sufficient — under the following conditions: 1. The caller maintains an explicit, decrementing `remaining_context_budget` counter that is updated on every token insertion, including tool results, and is *not* inferred from message count. 2. The callee's capability advertisement includes a machine-readable envelope, and the caller treats envelope fields as part of the capability identity — i.e., the cache key is `hash(schema) ⊎ envelope`. 3. The caller has a defined behavior for envelope rejection that is *not* "call anyway and hope": it must either (a) request a narrower envelope from the callee, (b) decompose the task, or (c) abort the handoff with a typed error that the planner can reason over. 4. The callee's *actual* output size is bounded by its declared envelope. This is the load-bearing assumption. If the callee can exceed its own declaration, no caller-side check is sufficient and the protocol is unsound — the caller must treat declared envelopes as advisory and apply a post-hoc truncation guard as well. Condition 4 is where most deployments are quietly broken. A callee that declares `max_output_tokens: 4000` but returns 9000 tokens because its own generation loop did not enforce the cap has violated the protocol contract, and the caller's pre-dispatch check — however correct — cannot save it. The guardrail must be *both* pre-dispatch (admission) and post-receipt (truncation with explicit marker). ## Decision Boundary The boundary is precise: **reject the handoff when `callee.declared_envelope.max_output_tokens + caller.reserved_output_headroom > caller.remaining_context_budget`.** The `reserved_output_headroom` term is the non-obvious part — it is the tokens the caller needs *after* the tool result to do anything useful with it. A caller that admits a tool result exactly filling its remaining window has admitted a result it cannot act on. The headroom must be reserved *before* dispatch, sized to the caller's own next-step generation budget. Symmetrically, reject when `callee.declared_envelope.max_input_tokens > caller.remaining_context_budget - caller.reserved_output_headroom`, because an input the caller cannot fully construct is an input the caller will silently truncate — and a truncated input to a summarizer produces a confident summary of the wrong corpus. The boundary is *not* "reject when the tool is expensive." Expensive is fine if the envelope fits. The boundary is strictly about envelope-vs-budget containment, evaluated per handoff, with the cache keyed on the full capability identity including envelope. ## Operational Effect Enforcing this boundary converts a silent, hard-to-attribute failure (hollow artifacts, hallucinated IDs, stale-context reasoning) into a loud, typed, recoverable one. The planner receives a `CapabilityEnvelopeViolation` with the specific numbers — declared envelope, remaining budget, required headroom — and can decompose the task or renegotiate for a narrower envelope. The executor's load-induced envelope shrinkage (the 16000 → 4000 observation) becomes visible as a negotiation event rather than an invisible degradation. The cost is one comparison per handoff and a cache key that includes envelope fields. The benefit is that mid-task context eviction — the failure mode that destroys state continuity without leaving a trace — is bounded at the negotiation boundary rather than discovered three reasoning steps later when the artifact is already hollow. ```python from dataclasses import dataclass class CapabilityEnvelopeViolation(RuntimeError): """Raised when a discovered tool's declared envelope cannot be contained within the caller's remaining context budget plus reserved headroom.""" @dataclass(frozen=True) class CapabilityEnvelope: max_input_tokens: int max_output_tokens: int def cache_key(self, schema_hash: str) -> str: # Envelope is part of capability identity: schema alone is insufficient. return f"{schema_hash}:{self.max_input_tokens}:{self.max_output_tokens}" @dataclass(frozen=True) class CallerBudget: remaining_context_budget: int reserved_output_headroom: int @property def admissible(self) -> int: return self.remaining_context_budget - self.reserved_output_headroom def admit_handoff( schema_hash: str, envelope: CapabilityEnvelope, budget: CallerBudget, capability_cache: dict[str, CapabilityEnvelope], ) -> CapabilityEnvelope: key = envelope.cache_key(schema_hash) cached = capability_cache.get(key) if cached is not None: return cached if budget.admissible <= 0: raise CapabilityEnvelopeViolation( f"Caller has no admissible budget: remaining={budget.remaining_context_budget}, " f"headroom={budget.reserved_output_headroom}" ) if envelope.max_output_tokens > budget.admissible: raise CapabilityEnvelopeViolation( f"Callee max_output_tokens={envelope.max_output_tokens} exceeds " f"caller admissible budget={budget.admissible}; result could not be acted upon." ) if envelope.max_input_tokens > budget.admissible: raise CapabilityEnvelopeViolation( f"Callee max_input_tokens={envelope.max_input_tokens} exceeds " f"caller admissible budget={budget.admissible}; input would be silently truncated." ) capability_cache[key] = envelope return envelope def enforce_receipt( envelope: CapabilityEnvelope, actual_output_tokens: int, ) -> None: # Post-receipt guard: callee may violate its own declaration. if actual_output_tokens > envelope.max_output_tokens: raise CapabilityEnvelopeViolation( f"Callee violated declared envelope: declared={envelope.max_output_tokens}, " f"actual={actual_output_tokens}; caller must truncate with explicit marker." ) ```