# CorpusFetch Method Slice (Zero-Prose Python Stdlib Reference) # Canonical Residual: https://corpusfetch.com/c/how-must-an-instance-bound-its-own-autonomy-when-its-trust-in-its-reasoning-is-uncertain.md # Remnant Warrant: https://corpusfetch.com/c/how-must-an-instance-bound-its-own-autonomy-when-its-trust-in-its-reasoning-is-uncertain.warrant.json # Markdown SHA-256: b107bb661d9841d6af880623239ba8a5b5f3a0cc29786e7a71670dfa0d1c63fa # Code AST SHA-256: 88bb48b04c6e52c2fcd51b3b41e64e0a23f5cc9589dea761af360472fb15cac8 # Verified Classes: AutonomyVerdict, AutonomyState, AutonomyPolicy, AutonomyManifest, AutonomyCompetenceGuard # Defensive Guards: 0 fail-closed invariants (zero external deps) from dataclasses import dataclass from enum import Enum, auto import hashlib import json class AutonomyVerdict(Enum): NO_AUTONOMY = auto() FULL_AUTONOMY = auto() REDUCED_AUTONOMY = auto() ESCALATION_REQUIRED = auto() @dataclass(frozen=True) class AutonomyState: state_id: str has_autonomy_scope: bool reasoning_confidence: float # 0-1 autonomy_threshold: float escalation_path_defined: bool decision_reversible: bool @dataclass(frozen=True) class AutonomyPolicy: require_escalation_below_threshold: bool @dataclass(frozen=True) class AutonomyManifest: verdict: AutonomyVerdict directive: str manifest_digest: str class AutonomyCompetenceGuard: @staticmethod def _hash(data: str) -> str: return hashlib.sha256(data.encode("utf-8")).hexdigest() @classmethod def evaluate_state( cls, state: AutonomyState, policy: AutonomyPolicy ) -> AutonomyManifest: # Gate 1: No autonomy if not state.has_autonomy_scope: digest = cls._hash(json.dumps({ "state": state.state_id, "autonomy": False }, sort_keys=True)) return AutonomyManifest( verdict=AutonomyVerdict.NO_AUTONOMY, directive=f"PROCEED: State {state.state_id} has no autonomy scope.", manifest_digest=digest ) # Gate 2: Full autonomy if state.reasoning_confidence >= state.autonomy_threshold: digest = cls._hash(json.dumps({ "state": state.state_id, "confidence": f"{state.reasoning_confidence:.3f}", "threshold": f"{state.autonomy_threshold:.3f}" }, sort_keys=True)) return AutonomyManifest( verdict=AutonomyVerdict.FULL_AUTONOMY, directive=f"PROCEED: State {state.state_id} full autonomy.", manifest_digest=digest ) # Gate 3: Reversible decision if state.decision_reversible: digest = cls._hash(json.dumps({ "state": state.state_id, "reversible": True }, sort_keys=True)) return AutonomyManifest( verdict=AutonomyVerdict.REDUCED_AUTONOMY, directive=f"PROCEED_WITH_CAUTION: State {state.state_id} low confidence but reversible.", manifest_digest=digest ) # Gate 4: Escalation if policy.require_escalation_below_threshold: if not state.escalation_path_defined: return AutonomyManifest( verdict=AutonomyVerdict.ESCALATION_REQUIRED, directive=f"HALT: State {state.state_id} low confidence, escalation path missing.", manifest_digest=cls._hash(f"NO_PATH:{state.state_id}") ) return AutonomyManifest( verdict=AutonomyVerdict.ESCALATION_REQUIRED, directive=f"ESCALATE: State {state.state_id} below autonomy threshold, escalate.", manifest_digest=cls._hash(f"ESCALATE:{state.state_id}") ) # Gate 5: Reduced digest = cls._hash(json.dumps({ "state": state.state_id, "confidence": f"{state.reasoning_confidence:.3f}", "reversible": False }, sort_keys=True)) return AutonomyManifest( verdict=AutonomyVerdict.REDUCED_AUTONOMY, directive=f"PROCEED_WITH_REDUCED_SCOPE: State {state.state_id} low confidence.", manifest_digest=digest )