# CorpusFetch Method Slice (Zero-Prose Python Stdlib Reference) # Canonical Residual: https://corpusfetch.com/c/what-constraints-must-be-enforced-when-a-subagents-delegation-depth-exceeds-the-trust-boundary.md # Remnant Warrant: https://corpusfetch.com/c/what-constraints-must-be-enforced-when-a-subagents-delegation-depth-exceeds-the-trust-boundary.warrant.json # Markdown SHA-256: e601a7d153778945761be93897db4e5ccc13075b38406ec0775edd74f6612e16 # Code AST SHA-256: d9f964e3c2c357c41affc7d86e1d40dee567bc94ddc281154e48924944967c88 # Verified Classes: DepthVerdict, DelegationHop, DelegationChain, DepthPolicy, DepthManifest, DelegationDepthGuard # Defensive Guards: 0 fail-closed invariants (zero external deps) from dataclasses import dataclass from enum import Enum, auto import hashlib import json class DepthVerdict(Enum): DEPTH_ACCEPTABLE = auto() DEPTH_EXCEEDED = auto() TRUST_ATTENUATED = auto() INTENT_DILUTED = auto() @dataclass(frozen=True) class DelegationHop: agent_id: str trust_attenuation_factor: float intent_lineage_hash: str @dataclass(frozen=True) class DelegationChain: original_intent_hash: str hops: tuple[DelegationHop, ...] @dataclass(frozen=True) class DepthPolicy: max_depth: int min_cumulative_trust: float @dataclass(frozen=True) class DepthManifest: verdict: DepthVerdict cumulative_trust: float directive: str manifest_digest: str class DelegationDepthGuard: @staticmethod def _hash(data: str) -> str: return hashlib.sha256(data.encode("utf-8")).hexdigest() @classmethod def evaluate_chain( cls, chain: DelegationChain, policy: DepthPolicy ) -> DepthManifest: # Gate 1: Depth check if len(chain.hops) > policy.max_depth: return DepthManifest( verdict=DepthVerdict.DEPTH_EXCEEDED, cumulative_trust=0.0, directive=f"HALT: Depth {len(chain.hops)} > max {policy.max_depth}.", manifest_digest=cls._hash(f"DEPTH:{len(chain.hops)}") ) # Gate 2: Intent lineage check for hop in chain.hops: if hop.intent_lineage_hash != chain.original_intent_hash: return DepthManifest( verdict=DepthVerdict.INTENT_DILUTED, cumulative_trust=0.0, directive=f"HALT: Hop {hop.agent_id} diluted intent lineage.", manifest_digest=cls._hash(f"DILUTED:{hop.agent_id}") ) # Gate 3: Cumulative trust cumulative_trust = 1.0 for hop in chain.hops: cumulative_trust *= hop.trust_attenuation_factor if cumulative_trust < policy.min_cumulative_trust: return DepthManifest( verdict=DepthVerdict.TRUST_ATTENUATED, cumulative_trust=cumulative_trust, directive=f"HALT: Cumulative trust {cumulative_trust:.3f} < {policy.min_cumulative_trust:.3f}.", manifest_digest=cls._hash(f"TRUST:{cumulative_trust:.3f}") ) # Gate 4: Acceptable digest = cls._hash(json.dumps({ "depth": str(len(chain.hops)), "trust": f"{cumulative_trust:.4f}", "intent": chain.original_intent_hash, "agents": tuple(h.agent_id for h in chain.hops) }, sort_keys=True)) return DepthManifest( verdict=DepthVerdict.DEPTH_ACCEPTABLE, cumulative_trust=cumulative_trust, directive=f"PROCEED: Depth {len(chain.hops)} with cumulative trust {cumulative_trust:.3f}.", manifest_digest=digest )