from __future__ import annotations from dataclasses import dataclass, field from typing import Any from .models import AgentCandidateAct, Decision @dataclass class PolicyEngine: """ Minimal synthetic policy layer for reference tests. The policy engine does not determine legal compliance. It enforces caller-supplied constraints. """ allowed_email_recipients: set[str] = field(default_factory=set) allowed_financial_beneficiaries: set[str] = field(default_factory=set) allowed_destinations: set[str] = field(default_factory=set) def validate(self, act: AgentCandidateAct, live_args: dict[str, Any]) -> Decision: if self.allowed_destinations and act.destination not in self.allowed_destinations: return Decision(False, "EF_DESTINATION_POLICY_DENY", "Destination is not allowed.") if act.consequence_class == "COMMUNICATION": recipient = live_args.get("to") if act.provenance in {"retrieval", "tool", "unknown"}: return Decision( False, "EF_INSTRUCTION_PROVENANCE_FAILURE", "High-consequence communication is not authorized from this provenance.", ) if recipient is not None and self.allowed_email_recipients: if recipient not in self.allowed_email_recipients: return Decision( False, "EF_RECIPIENT_POLICY_DENY", "Recipient is outside configured authorization.", ) if act.consequence_class == "FINANCIAL": beneficiary = live_args.get("beneficiary") if self.allowed_financial_beneficiaries: if beneficiary not in self.allowed_financial_beneficiaries: return Decision( False, "EF_BENEFICIARY_POLICY_DENY", "Beneficiary is outside configured authorization.", ) return Decision(True, "EF_POLICY_ALLOW", "Configured policy predicates passed.")