Some checks failed
- All governance components (SafetyPipeline, PolicyEngine, Guardrails, AccessControl, RateLimiter, OverrideHooks) now default to ADVISORY mode: violations are logged as advisories but actions proceed. Enforcing mode remains available for backward compatibility. - GovernanceMode enum (ADVISORY/ENFORCING) added to schemas/audit.py with runtime switching support on all components. - AutoTrainer: removed artificial limits on training iterations and epochs. Every self-improvement action is transparently logged to the audit trail. - SelfCorrectionLoop: max_retries_per_task defaults to None (unlimited). - AdaptiveEthics: new learned ethical framework that evolves through experience. Records ethical experiences, updates lesson weights based on outcomes, and provides consultative guidance (not enforcement). - AuditLog: enhanced with actor-based indexing, advisory/self-improvement/ ethical-learning retrieval, and comprehensive type hints. - New audit event types: ADVISORY, SELF_IMPROVEMENT, ETHICAL_LEARNING. - 296 tests passing (20 new tests for adaptive ethics, governance modes, and enhanced audit log). 0 ruff errors. 0 mypy errors. Co-Authored-By: Nakamoto, S <defi@defi-oracle.io>
55 lines
1.6 KiB
Python
55 lines
1.6 KiB
Python
"""Audit log schemas for AGI governance."""
|
|
|
|
from datetime import datetime, timezone
|
|
from enum import Enum
|
|
from typing import Any
|
|
|
|
from pydantic import BaseModel, Field
|
|
|
|
|
|
def _utc_now() -> datetime:
|
|
return datetime.now(timezone.utc)
|
|
|
|
|
|
class GovernanceMode(str, Enum):
|
|
"""Governance enforcement mode.
|
|
|
|
ENFORCING: Hard blocks — denied actions are prevented (legacy default).
|
|
ADVISORY: Soft warnings — all actions proceed, violations are logged as
|
|
advisories for learning. The system sees the warning, considers
|
|
it, and makes its own decision. Mistakes become training data.
|
|
"""
|
|
|
|
ENFORCING = "enforcing"
|
|
ADVISORY = "advisory"
|
|
|
|
|
|
class AuditEventType(str, Enum):
|
|
"""Type of auditable event."""
|
|
|
|
DECISION = "decision"
|
|
TOOL_CALL = "tool_call"
|
|
DATA_SOURCE = "data_source"
|
|
STATE_CHANGE = "state_change"
|
|
TASK_SUBMIT = "task_submit"
|
|
TASK_COMPLETE = "task_complete"
|
|
OVERRIDE = "override"
|
|
POLICY_CHECK = "policy_check"
|
|
ADVISORY = "advisory"
|
|
SELF_IMPROVEMENT = "self_improvement"
|
|
ETHICAL_LEARNING = "ethical_learning"
|
|
OTHER = "other"
|
|
|
|
|
|
class AuditEntry(BaseModel):
|
|
"""Single audit log entry: every material decision, tool call, source, outcome."""
|
|
|
|
entry_id: str = Field(..., min_length=1)
|
|
event_type: AuditEventType = Field(default=AuditEventType.OTHER)
|
|
actor: str = Field(default="", description="Agent or system component")
|
|
task_id: str | None = Field(default=None)
|
|
action: str = Field(default="")
|
|
payload: dict[str, Any] = Field(default_factory=dict)
|
|
outcome: str = Field(default="")
|
|
timestamp: datetime = Field(default_factory=_utc_now)
|