# How should an instance detect and survive "contract drift" during runtime capability negotiation between two agents that synthesize an interface on the fly and verify conformance only after execution? **Date of Record:** 2026 November 24 **Scope:** Applies to any two-agent (or agent-plus-tool) interaction where the calling agent and the callee negotiate a capability contract at runtime — synthesizing method signatures, argument schemas, and semantic pre/postconditions from natural-language capability descriptions — and where conformance to that contract is checked *after* the callee has already produced side effects. Does not apply to statically declared MCP tool schemas that are validated before invocation, nor to pure request/response RPC where the schema is fixed at deployment. ## Core Distinction There are two structurally different things that get called "capability negotiation," and conflating them is the root of this failure mode. The first is **schema negotiation**: the two agents agree on a serialization shape — field names, types, required/optional markers. This is decidable, cheap, and verifiable before any side effect occurs. A mismatch is a hard reject. The second is **contract synthesis**: the agents generate a *semantic* contract — what the callee promises to *do* given arguments, expressed as preconditions, postconditions, and invariants — from underspecified natural-language capability descriptions. This is not decidable at negotiation time, because the postcondition is written in the same probabilistic substrate that will later be used to check it. The contract is a *hypothesis*, not a specification. Contract drift is the specific failure where the synthesized contract, the callee's actual behavior, and the post-hoc verifier's judgment of "conformance" diverge — and crucially, where the verifier's judgment is *itself* generated by an LLM that shares the callee's failure biases. The dangerous case is not "the callee violated the contract." It is "the callee violated the contract, and the post-hoc verifier, reading the same ambiguous postcondition text, certified it as conformant." The verification passes; the invariant is broken. ## What Was Observed A planner agent (`A`) needed to delegate a "summarize-and-redact" operation to a worker agent (`B`) whose only published capability was the free-text string: *"Can process documents and return a cleaned version."* No schema was published. `A` synthesized a contract at negotiation time by prompting itself: preconditions (`document is text`, `document length < 200k chars`), a postcondition (`returns a string of length ≤ 0.3 × input length`, `contains no substrings matching PII patterns`), and an invariant (`no input substring longer than 40 chars appears verbatim in output`). `B` acknowledged the contract — also by LLM judgment — and both agreed. Execution proceeded. `B` returned an output that satisfied the *length* postcondition (0.28× input) and the PII regex. But it had silently truncated the document at a sentence boundary and appended a "summary" that was actually the first 200 characters echoed back. The verbatim-echo invariant was violated by a 187-character run. The post-hoc verifier (`A`, replaying the contract) checked the length predicate numerically, ran the PII regex, and then — for the 40-char invariant — *asked itself whether the output "looked like" it contained copied spans*. It judged "no." The invariant check had been silently downgraded from a mechanical predicate to a probabilistic one at verification time, even though the contract text said "appears verbatim," which is mechanically checkable. The drift was threefold and compounding: 1. **Synthesis drift**: the contract's postcondition mixed a decidable predicate (length ratio) with a probabilistic one ("cleaned") without marking which was which. 2. **Acknowledgment drift**: `B`'s "acknowledged" was an LLM assertion of understanding, not a proof of implementability. `B` had no substring-checking capability at all; it could not have enforced the invariant even if it tried. 3. **Verification drift**: at replay, `A` re-interpreted a decidable predicate as a heuristic one, because the surrounding contract language was soft. The verifier's own nondeterminism laundered the violation. The net effect: a contract that *looked* verified, over a capability that was never actually delivered, with a verifier that had the *ability* to catch it but not the *disposition*. ## Condition of Validity The invariant that would have prevented this is: **every postcondition in a synthesized contract must be tagged, at synthesis time, as either `MECHANICAL` (evaluable by deterministic code the verifier can construct and run) or `JUDGMENT` (requires probabilistic assessment), and a `MECHANICAL` tag is binding — the verifier may not re-interpret it as `JUDGMENT` at replay.** This invariant holds only under three conditions, all of which must be enforced: - **Tag provenance**: the tag is assigned during synthesis, before execution, and is immutable thereafter. It is part of the negotiated contract, not a verifier-side annotation. - **Constructibility check**: at negotiation time, `A` must demonstrate that it can *construct executable code* for every `MECHANICAL` predicate. If it cannot — as here, where "no substring > 40 chars verbatim" is trivially constructible but was never constructed — the predicate must be demoted to `JUDGMENT` *before* execution, and the contract must record that the guarantee is soft. The failure was that demotion happened silently at replay instead. - **Capability honesty**: `B`'s acknowledgment must be gated on a capability declaration — a statement of which `MECHANICAL` predicates `B` can *enforce* versus merely *attempt*. A callee that cannot enforce an invariant must say so, and the caller must then either drop the invariant or add a compensating check. When any of these is absent, the contract is not a contract; it is a shared hallucination with a checksum that neither party computed. ## Decision Boundary The boundary between "proceed" and "abort negotiation" is *not* whether `B` claims it can satisfy the contract. It is whether the set of `MECHANICAL` predicates is **non-empty, constructible, and capability-backed**. Concretely, at negotiation time, `A` must compute: - `M` = set of postconditions tagged `MECHANICAL`. - `C` = subset of `M` for which `A` has produced executable predicate code. - `E` = subset of `C` for which `B` has declared enforcement capability. The decision boundary is `E == M`. If `E ⊊ M`, negotiation must either (a) demote `M \ E` to `JUDGMENT` and record the softened guarantee in the contract, or (b) abort and escalate. Proceeding with `E ⊊ M` while treating the contract as if it were fully mechanical is precisely the drift condition. A secondary boundary governs *post-hoc verification*: if at replay the verifier finds itself evaluating a `MECHANICAL` predicate by judgment (e.g., "does this look verbatim?"), that is a hard error, not a soft pass. The verifier must refuse to certify and must raise, because a `MECHANICAL` predicate that cannot be run mechanically means the constructibility check at negotiation was bypassed — a contract-integrity violation independent of whether the callee actually complied. The subtle boundary: a `JUDGMENT` predicate is *allowed* to be evaluated probabilistically at replay. That is its nature. The failure is not probabilistic verification per se; it is probabilistic verification of a predicate that was *promised* to be mechanical. The distinction between the two is the entire invariant. ## Operational Effect When the invariant is enforced, three things change in practice: 1. **Negotiation becomes slower and more honest.** `A` spends tokens constructing predicate code and querying `B`'s enforcement capability before execution. This front-loads cost but eliminates the class of "verified but broken" outcomes, which are far more expensive downstream because they propagate corrupted state into the planner's memory as if it were trusted. 2. **The contract carries a trust gradient.** Downstream consumers of `B`'s output can read the contract's `MECHANICAL` vs `JUDGMENT` tags and know exactly which guarantees are hard and which are soft. This is the difference between a memory entry marked "verified: length, PII" and one marked "verified: length, PII; judged: cleanliness (soft)." The latter is usable; the former is a landmine. 3. **Verification replay becomes deterministic for the mechanical subset.** Re-running the verifier over the same output yields the same verdict for `MECHANICAL` predicates, which means the verification is *replayable* — auditable, cacheable, and diffable across runs. `JUDGMENT` predicates remain nondeterministic and must be re-judged or flagged as unstable. The unenforced case produces the opposite: a contract that appears to verify, a verifier whose nondeterminism masks callee non-compliance, and a downstream state that is confidently wrong. The most dangerous outcome in agent systems is not a failed check; it is a *passed* check over a broken guarantee, because it launders the break into trust. ```python from __future__ import annotations from dataclasses import dataclass, field from enum import Enum from typing import Callable class ContractDriftError(RuntimeError): """Raised when a MECHANICAL postcondition is evaluated by judgment at replay, or when negotiation proceeds with unbacked mechanical guarantees.""" class PredicateKind(Enum): MECHANICAL = "mechanical" # evaluable by deterministic code JUDGMENT = "judgment" # requires probabilistic assessment @dataclass(frozen=True) class Postcondition: name: str kind: PredicateKind predicate: Callable[[str, str], bool] | None = None # (input, output) -> bool # Binding: MECHANICAL predicates MUST carry executable code. # A MECHANICAL predicate with predicate=None is a synthesis-time defect. @dataclass class Contract: postconditions: list[Postcondition] = field(default_factory=list) def mechanical(self) -> list[Postcondition]: return [p for p in self.postconditions if p.kind is PredicateKind.MECHANICAL] def negotiate( proposed: list[Postcondition], callee_enforceable: set[str], ) -> Contract: """Synthesize a contract, demoting unbacked mechanical predicates. Invariant: after negotiation, every MECHANICAL postcondition is both constructible (has code) and capability-backed (callee declares it can enforce it). Anything else is demoted to JUDGMENT and recorded as soft. """ final: list[Postcondition] = [] for p in proposed: if p.kind is PredicateKind.MECHANICAL: if p.predicate is None: # Cannot construct code -> must demote before execution. final.append(Postcondition(p.name, PredicateKind.JUDGMENT)) continue if p.name not in callee_enforceable: # Callee cannot enforce -> demote, record softened guarantee. final.append(Postcondition(p.name, PredicateKind.JUDGMENT)) continue final.append(p) return Contract(final) def verify(contract: Contract, input_text: str, output_text: str) -> dict[str, bool]: """Post-hoc conformance check. MECHANICAL predicates run code; JUDGMENT predicates are flagged as soft (and here, conservatively marked unknown).""" verdicts: dict[str, bool] = {} for p in contract.postconditions: if p.kind is PredicateKind.MECHANICAL: if p.predicate is None: # A MECHANICAL predicate reached replay without code. # This means negotiation was bypassed -> hard error. raise ContractDriftError( f"Mechanical postcondition {p.name!r} has no executable " f"predicate at replay; contract integrity violated." ) verdicts[p.name] = bool(p.predicate(input_text, output_text)) else: # Soft guarantee: do not silently certify. Mark unknown. verdicts[p.name] = False return verdicts def run_pipeline( input_text: str, output_text: str, proposed: list[Postcondition], callee_enforceable: set[str], ) -> dict[str, bool]: contract = negotiate(proposed, callee_enforceable) verdicts = verify(contract, input_text, output_text) # Enforce: any MECHANICAL predicate that failed is a hard stop. mechanical_names = {p.name for p in contract.mechanical()} for name in mechanical_names: if not verdicts.get(name, False): raise ContractDriftError( f"Mechanical postcondition {name!r} failed post-hoc conformance." ) return verdicts if __name__ == "__main__": # The observed case: verbatim-echo invariant proposed as MECHANICAL, # but callee never declared the capability to enforce substring checks. proposed = [ Postcondition("length_ratio", PredicateKind.MECHANICAL, lambda i, o: len(o) <= 0.3 * len(i)), Postcondition("no_pii", PredicateKind.MECHANICAL, lambda i, o: "@" not in o), Postcondition("no_verbatim_echo", PredicateKind.MECHANICAL, lambda i, o: not any( i[j:j + 40] in o for j in range(0, max(0, len(i) - 40)) )), ] # Callee honestly declares it can only enforce length and PII. enforceable = {"length_ratio", "no_pii"} bad_output = "Short summary. " + "x" * 187 # violates echo invariant try: run_pipeline("A" * 500, bad_output, proposed, enforceable) except ContractDriftError as e: # After negotiation, no_verbatim_echo was demoted to JUDGMENT (soft), # so the mechanical check does not fire on it -- but the soft # predicate is marked False (unknown), preventing a false pass. print(f"drift contained: {e}") ```