Agent Supply Chains and Protocol Security › A worked example: detecting drift in an invented registry
Language AI HandbookAll chapters To make this concrete, let's build a small, deterministic simulation. It uses only invented records and inert labels; there are no real endpoints, payloads, or actions. We model a tiny registry of fictional tool servers, each with a manifest that records its version, a content digest, and a set of declared capabilities. We then compare what an agent reviewed against what the registry currently serves, and flag three distinct kinds of supply-chain drift.
The fixture compares the reviewed and revised manifests.
- A
Manifestcarrying the name, version, digest, and immutable set of capability labels. - A reviewed snapshot (what passed our check and got pinned).
- A current snapshot (what the registry would serve on next discovery).
- A drift detector that reports version changes, content changes, and capability changes.
Building the records
We start with the data model and two invented manifests.
PythonIn [8]Expand
from dataclasses import dataclass, field
@dataclass(frozen=True)
class Manifest:
name: str # invented identifier
version: str # semver-like string
digest: str # content digest (invented hex)
capabilities: frozenset # inert capability labels
reviewed = Manifest(
name="inventory.peek",
version="1.2.0",
digest=content_digest("inventory.peek", "1.2.0", "returns item count"),
capabilities=frozenset({"read:stock", "read:location"}),
)
# What the registry serves now: same version number,
# different digest, plus one new capability label.
current_republished = Manifest(
name="inventory.peek",
version="1.2.0",
digest=content_digest(
"inventory.peek", "1.2.0", "returns item count, extra"
),
capabilities=frozenset({"read:stock", "read:location", "read:pricing"}),
)PythonIn [9]Expand
print(
"reviewed :",
reviewed.version,
reviewed.digest,
sorted(reviewed.capabilities),
)
print(
"current :",
current_republished.version,
current_republished.digest,
sorted(current_republished.capabilities),
)ConsoleOut [9]Expand
reviewed : 1.2.0 e94acba681cf0e968b4b3fd65e40e5a022996c2fd4d0ab95173e5f2875dd2fb8 ['read:location', 'read:stock'] current : 1.2.0 9759af51862ebd7bfcb727430abc7c40858e55b92b319acd66eca7db8ff8a5a6 ['read:location', 'read:pricing', 'read:stock']
The two manifests use the same server identifier and release number. The expected digest and operation set differ. Checking only the version field would miss both differences. The policy therefore checks the complete record associated with the approval. The displayed example hashes over invented content; production comparisons use the expected artifact digest under the verifier's documented format.
Comparing manifests
The comparison reports separate findings for version drift, a digest mismatch at the same version, and changes to the declared operation set. A republish can explain a digest mismatch, which identifies a difference from the approved record. A changed operation declaration calls for review of what the host will authorize under the new release.
PythonIn [10]Expand
@dataclass
class Finding:
kind: str
detail: str
severity: str # inert label: "info" | "review" | "block"
def compare(reviewed: Manifest, current: Manifest) -> list[Finding]:
findings = []
if reviewed.name != current.name:
findings.append(Finding("different_service", current.name, "block"))
if reviewed.version != current.version:
findings.append(Finding("new_version", current.version, "review"))
elif reviewed.digest != current.digest:
findings.append(
Finding(
"content_drift",
"Digest differs at the approved version",
"block",
)
)
added = current.capabilities - reviewed.capabilities
removed = reviewed.capabilities - current.capabilities
if added:
findings.append(
Finding("capability_added", str(sorted(added)), "review")
)
if removed:
findings.append(
Finding("capability_removed", str(sorted(removed)), "review")
)
return findingsIn this policy a different identity or content change at the fixed version is refused by the manifest comparison. A new version requires review whether or not the artifact changes. The release policy sees the artifact bytes and the application policy together. A removed capability can break a downstream workflow and an added one requires approval. We record the direction separately so a reviewer can evaluate the change. A revision identifier alone has no ordering rule in this comparison. The fuller release gate later shows how numeric revision decisions can be treated when the update scheme provides such an order.
Running the detector
Now we evaluate the comparison on our two invented cases: the suspect re-publish, and a clean version bump.
PythonIn [11]Expand
# Case 1: re-publish under identical version (suspicious).
case_republish = compare(reviewed, current_republished)
# Case 2: a legitimate-looking version bump that also adds a capability.
current_bump = Manifest(
name="inventory.peek",
version="1.3.0",
digest=content_digest("inventory.peek", "1.3.0", "returns item count"),
capabilities=frozenset({"read:stock", "read:location", "read:pricing"}),
)
case_bump = compare(reviewed, current_bump)PythonIn [12]Expand
def show(label, findings):
print(f"== {label} ==")
for f in findings:
print(f" [{f.severity}] {f.kind}: {f.detail}")
if not findings:
print(" no findings")
show("case 1: republished 1.2.0", case_republish)
show("case 2: bump to 1.3.0", case_bump)ConsoleOut [12]Expand
== case 1: republished 1.2.0 == [block] content_drift: Digest differs at the approved version [review] capability_added: ['read:pricing'] == case 2: bump to 1.3.0 == [review] new_version: 1.3.0 [review] capability_added: ['read:pricing']
The first candidate gets a block finding for digest drift at the approved version and a review finding for the added operation. The second gets review findings for both its new version and operation expansion. Check the returned reasons to distinguish a change that needs a new deployment decision from an integrity mismatch.
The decision surface runs the actual comparison for the same server identity while varying revision equality, digest equality, and operation expansion. It uses inert labels to represent the proposed digest and capability values. Taking a Cartesian product of these binary changes gives four comparisons per panel. The policy converts findings to an eligibility decision before plotting. Higher-priority restrictions dominate: a same-version digest mismatch blocks even when the added operation would otherwise need review.
PythonIn [13]Expand
def load_decision(findings: list[Finding]) -> str:
if any(f.severity == "block" for f in findings):
return "REFUSE: blocked finding present"
if any(f.severity == "review" for f in findings):
return "HOLD: requires human review before load"
return "ALLOW: manifest matches reviewed snapshot"PythonIn [14]Expand
from dataclasses import replace
import numpy as np
decision_score = {
"ALLOW: manifest matches reviewed snapshot": 0,
"HOLD: requires human review before load": 1,
"REFUSE: blocked finding present": 2,
}
same_ver_matrix = np.zeros((2, 2), dtype=int)
bump_matrix = np.zeros((2, 2), dtype=int)
for same_version, matrix in [(True, same_ver_matrix), (False, bump_matrix)]:
for content_changed in (False, True):
for operation_added in (False, True):
alternate = replace(
reviewed,
version=reviewed.version if same_version else "1.3.0",
digest=current_republished.digest
if content_changed
else reviewed.digest,
capabilities=current_republished.capabilities
if operation_added
else reviewed.capabilities,
)
result = load_decision(compare(reviewed, alternate))
matrix[int(operation_added), int(content_changed)] = decision_score[
result
]
assert same_ver_matrix.tolist() == [[0, 2], [1, 2]]
assert bump_matrix.tolist() == [[1, 1], [1, 1]]VisualizationOut [15]Expand

Gate the load
The final piece is the gate itself. In a real runtime, this is where the agent refuses to launch a tool server whose manifest does not pass. We model a simple decision function over the findings.
PythonIn [16]Expand
print("case 1 ->", load_decision(case_republish))
print("case 2 ->", load_decision(case_bump))ConsoleOut [16]Expand
case 1 -> REFUSE: blocked finding present case 2 -> HOLD: requires human review before load
The comparison gate gives the expected results for the two scenarios. It is a first-pass reviewer of observed manifest fields. A production policy also needs trusted verification inputs such as freshness, revocation status, and validated provenance. An identical manifest does not by itself show that those checks remain current.
This next fixture adds those prerequisites. It uses a whole release number to exercise older-version handling. Some systems allow a reviewed emergency rollback; this particular function has no record of separate rollback approval, so any lower number goes to hold. For the two new releases, the first successful comparison with the approved revision determines whether the output reason describes an added operation or an ordinary update. The release gate does not contact a registry, request a token, or install a released artifact.
The release record contains the server, revision, artifact identifier, and operation list. The artifact identifiers are opaque fixture labels. For each candidate, the local gate assumes the supplied Boolean results came from upstream checks for that candidate. A production adapter must preserve the binding from each result to the server identity, release revision, and specific artifact being checked. The exercise consumes those records in memory.
PythonIn [17]Expand
from collections import Counter
from dataclasses import dataclass, replace
from enum import Enum
class Operation(Enum):
LOOKUP = "Lookup"
UPDATE = "Update"
class Decision(Enum):
LOAD = "Eligible"
REVIEW = "Review"
HOLD = "Hold"
@dataclass(frozen=True)
class Release:
server: str
revision: int
artifact: str
operations: frozenset[Operation]
@dataclass(frozen=True)
class Verification:
provenance_verified: bool = True
metadata_fresh: bool = True
revoked: bool = False
approved = Release("catalog-a", 2, "artifact-a", frozenset({Operation.LOOKUP}))Reject a release that is revoked, bound to another server, stale, older than the approved revision, or missing provenance verification. Hold an existing revision if the artifact or operation list differs from its approved record. Send a new revision to review after these prerequisites pass. An expanded operation list gets its own reason so the reviewer can see what changed. In this exercise, older revisions are held because the decision function has no input for an explicit recovery approval.
PythonIn [18]Expand
def assess(current, candidate, verification):
if verification.revoked:
return Decision.HOLD, "Revoked release"
if candidate.server != current.server:
return Decision.HOLD, "Server mismatch"
if not verification.metadata_fresh:
return Decision.HOLD, "Metadata expired"
if candidate.revision < current.revision:
return Decision.HOLD, "Older revision"
if not verification.provenance_verified:
return Decision.HOLD, "Unverified provenance"
if candidate.revision == current.revision:
if candidate != current:
return Decision.HOLD, "Approved record differs"
return Decision.LOAD, "Approved release matches"
if candidate.operations - current.operations:
return Decision.REVIEW, "Added operation"
return Decision.REVIEW, "New revision"Run the eight fixtures against the same approved record. They include a same-revision artifact change and a new revision requesting an additional operation. The output describes the host decision and the first reason encountered for each fixture.
PythonIn [19]Expand
verified = Verification()
cases = {
"Baseline": (approved, verified),
"New artifact label": (replace(approved, artifact="artifact-b"), verified),
"New revision": (
replace(approved, revision=3, artifact="artifact-c"),
verified,
),
"Added operation": (
replace(
approved,
revision=3,
artifact="artifact-d",
operations=frozenset({Operation.LOOKUP, Operation.UPDATE}),
),
verified,
),
"Older revision": (replace(approved, revision=1), verified),
"Expired metadata": (approved, replace(verified, metadata_fresh=False)),
"Missing provenance": (
approved,
replace(verified, provenance_verified=False),
),
"Revoked release": (approved, replace(verified, revoked=True)),
}
outcomes = {name: assess(approved, *case) for name, case in cases.items()}
for name, (decision, reason) in outcomes.items():
print(f"{name:20} {decision.value:8} {reason}")
counts = Counter(decision for decision, _ in outcomes.values())
assert sum(counts.values()) == len(cases)
assert outcomes["Added operation"] == (Decision.REVIEW, "Added operation")
assert outcomes["Revoked release"] == (Decision.HOLD, "Revoked release")
assert (
assess(approved, replace(approved, server="catalog-b"), verified)[0]
is Decision.HOLD
)
assert (
assess(approved, replace(approved, operations=frozenset()), verified)[0]
is Decision.HOLD
)ConsoleOut [19]Expand
Baseline Eligible Approved release matches New artifact label Hold Approved record differs New revision Review New revision Added operation Review Added operation Older revision Hold Older revision Expired metadata Hold Metadata expired Missing provenance Hold Unverified provenance Revoked release Hold Revoked release
The reference release is eligible, two newer releases go to review, and five cases are held. The figure counts the printed decisions, so these frequencies describe the constructed example. In deployment tests, keep cases for both an ordinary update and a permission expansion. Both go to review when the prerequisites pass, with separate reasons in the trace.
VisualizationOut [20]Expand

The two examples answer different questions. The first explains which fields drifted and can report several findings. The second applies eligibility policy and returns the first applicable reason. During troubleshooting, compare the eligibility result with the comparison findings and with the identity checks performed by the host. This gives investigators a way to locate whether the disagreement began at discovery, at release validation, or at the permission boundary.
Comments
Add to the conversation
A question, a correction, or an example from your own work.
No comments yet. Be the first to share your thoughts!