# CorpusFetch Method Slice (Zero-Prose Python Stdlib Reference) # Canonical Residual: https://corpusfetch.com/c/what-cross-agent-consistency-invariants-must-survive-a-multi-agent-decision-that-requires-unanimity.md # Remnant Warrant: https://corpusfetch.com/c/what-cross-agent-consistency-invariants-must-survive-a-multi-agent-decision-that-requires-unanimity.warrant.json # Markdown SHA-256: e27f41dfd601ec8a462ab337a706663c42568ce8658350683e0dbe426a0f8de2 # Code AST SHA-256: ed772195726c43d8392c4c40879ff5e1ec4ac5fc45b66cb0ccd96e3bbcfc8df0 # Verified Classes: UnanimityVerdict, AgentVote, UnanimityState, UnanimityPolicy, UnanimityManifest, UnanimousDecisionGuard # Defensive Guards: 0 fail-closed invariants (zero external deps) from dataclasses import dataclass from enum import Enum, auto import hashlib import json class UnanimityVerdict(Enum): NOT_UNANIMOUS = auto() UNANIMITY_VERIFIED = auto() COINCIDENTAL_UNANIMITY = auto() EVIDENCE_ASYMMETRY = auto() @dataclass(frozen=True) class AgentVote: agent_id: str vote: bool reasoning_hash: str evidence_set_hash: str @dataclass(frozen=True) class UnanimityState: votes: tuple[AgentVote, ...] convergence_verified: bool evidence_consensus_verified: bool @dataclass(frozen=True) class UnanimityPolicy: require_evidence_consensus: bool require_reasoning_convergence: bool @dataclass(frozen=True) class UnanimityManifest: verdict: UnanimityVerdict directive: str manifest_digest: str class UnanimousDecisionGuard: @staticmethod def _hash(data: str) -> str: return hashlib.sha256(data.encode("utf-8")).hexdigest() @classmethod def evaluate_decision( cls, state: UnanimityState, policy: UnanimityPolicy ) -> UnanimityManifest: # Gate 1: Unanimity check votes = [v.vote for v in state.votes] if not all(votes): digest = cls._hash(json.dumps({ "votes": tuple((v.agent_id, v.vote) for v in state.votes) }, sort_keys=True)) return UnanimityManifest( verdict=UnanimityVerdict.NOT_UNANIMOUS, directive=f"FAIL: Not unanimous ({sum(votes)}/{len(votes)} yes).", manifest_digest=digest ) # Gate 2: Evidence consensus if policy.require_evidence_consensus: evidence_hashes = {v.evidence_set_hash for v in state.votes} if len(evidence_hashes) > 1: return UnanimityManifest( verdict=UnanimityVerdict.EVIDENCE_ASYMMETRY, directive=f"HALT: {len(evidence_hashes)} distinct evidence sets among unanimous voters.", manifest_digest=cls._hash(f"EVIDENCE_DIFF:{len(evidence_hashes)}") ) # Gate 3: Reasoning convergence if policy.require_reasoning_convergence: if not state.convergence_verified: reasoning_hashes = {v.reasoning_hash for v in state.votes} return UnanimityManifest( verdict=UnanimityVerdict.COINCIDENTAL_UNANIMITY, directive=f"HALT: {len(reasoning_hashes)} reasoning paths, convergence unverified.", manifest_digest=cls._hash(f"REASONING_DIFF:{len(reasoning_hashes)}") ) # Gate 4: Verified digest = cls._hash(json.dumps({ "agents": tuple(sorted(v.agent_id for v in state.votes)), "evidence": next(iter({v.evidence_set_hash for v in state.votes})), "convergence": str(state.convergence_verified) }, sort_keys=True)) return UnanimityManifest( verdict=UnanimityVerdict.UNANIMITY_VERIFIED, directive=f"PROCEED: {len(state.votes)} agents unanimous with verified convergence.", manifest_digest=digest )