Buckets:
AnonymousSpottedToad/candidate_bucket / codebase /python /dislovelhl_enhanced-agent-bus /bus /governance.py
| """ | |
| Adaptive governance integration for EnhancedAgentBus. | |
| Constitutional Hash: 608508a9bd224290 | |
| """ | |
| from __future__ import annotations | |
| from collections.abc import Callable | |
| from typing import TYPE_CHECKING, Any | |
| if TYPE_CHECKING: | |
| from enhanced_agent_bus._compat.types import JSONDict | |
| else: | |
| try: | |
| from enhanced_agent_bus._compat.types import JSONDict as _JSONDict | |
| except ImportError: | |
| _JSONDict = dict[str, Any] | |
| JSONDict = _JSONDict | |
| from enhanced_agent_bus.observability.structured_logging import get_logger | |
| from ..utils import get_iso_timestamp | |
| if TYPE_CHECKING: | |
| from enhanced_agent_bus.models import AgentMessage | |
| from ..components import GovernanceValidator | |
| logger = get_logger(__name__) | |
| class GovernanceIntegration: | |
| """ | |
| Handles adaptive governance evaluation for message processing. | |
| Constitutional Hash: 608508a9bd224290 | |
| """ | |
| def __init__( | |
| self, | |
| governance: GovernanceValidator, | |
| get_registered_agents: Callable[[], list[str]], | |
| metrics: JSONDict, | |
| ) -> None: | |
| """ | |
| Initialize governance integration. | |
| Args: | |
| governance: GovernanceValidator component. | |
| get_registered_agents: Callable to get registered agents list. | |
| metrics: Metrics dictionary reference. | |
| """ | |
| self._governance = governance | |
| self._get_registered_agents = get_registered_agents | |
| self._metrics = metrics | |
| async def evaluate_with_adaptive_governance(self, msg: AgentMessage) -> tuple[bool, str]: | |
| """ | |
| Evaluate message with adaptive governance. | |
| Args: | |
| msg: Message to evaluate. | |
| Returns: | |
| Tuple of (allowed: bool, reasoning: str). | |
| """ | |
| context = { | |
| "active_agents": self._get_registered_agents(), | |
| "time": get_iso_timestamp(), | |
| "current_metrics": dict(self._metrics), | |
| } | |
| result: tuple[bool, str] = await self._governance.evaluate_adaptive_governance(msg, context) | |
| return result | |
| def provide_feedback(self, msg: AgentMessage, success: bool) -> None: | |
| """ | |
| Provide feedback to adaptive governance system. | |
| Args: | |
| msg: The processed message. | |
| success: Whether delivery was successful. | |
| """ | |
| if self._governance: | |
| self._governance.provide_feedback(msg, success) | |
Xet Storage Details
- Size:
- 2.41 kB
- Xet hash:
- b30ce5ffa41aeb291d3cc2a4b01a38366e850bbad1e574a3b593d202cc5a0c24
·
Xet efficiently stores files, intelligently splitting them into unique chunks and accelerating uploads and downloads. More info.