Buckets:
AnonymousSpottedToad/candidate_bucket / codebase /python /dislovelhl_enhanced-agent-bus /agent_models.py
| """ | |
| ACGS-2 Enhanced Agent Bus - Agent Models | |
| Constitutional Hash: 608508a9bd224290 | |
| Data models for swarm agents and agent coordination. | |
| Split from models.py for improved maintainability. | |
| """ | |
| from dataclasses import dataclass, field | |
| # Import constitutional hash | |
| try: | |
| from enhanced_agent_bus._compat.constants import CONSTITUTIONAL_HASH | |
| except ImportError: | |
| CONSTITUTIONAL_HASH = "standalone" | |
| from enhanced_agent_bus.bus_types import JSONDict | |
| from .enums import AgentCapability, TaskType | |
| # Type alias | |
| class SwarmAgent: | |
| """Agent representation for swarm coordination. | |
| Constitutional Hash: 608508a9bd224290 | |
| """ | |
| agent_id: str | |
| name: str = "" | |
| agent_type: str = "" | |
| capabilities: list[AgentCapability] = field(default_factory=list) | |
| is_active: bool = True | |
| status: str = "idle" # idle, assigned, busy, terminated | |
| current_task: str | None = None | |
| performance_score: float = 1.0 | |
| constitutional_hash: str = CONSTITUTIONAL_HASH | |
| def has_capability(self, capability: AgentCapability) -> bool: | |
| """Check if agent has a specific capability.""" | |
| return capability in self.capabilities | |
| def can_handle(self, task_type: TaskType) -> bool: | |
| """Check if agent can handle a specific task type. | |
| Maps task types to required capabilities and checks if agent has them. | |
| """ | |
| # Mapping of task types to required capabilities | |
| capability_map: dict[TaskType, list[AgentCapability]] = { | |
| TaskType.CODE_GENERATION: [ | |
| AgentCapability.CODE_GENERATION, | |
| AgentCapability.PYTHON_EXPERT, | |
| AgentCapability.TYPESCRIPT_EXPERT, | |
| AgentCapability.RUST_EXPERT, | |
| ], | |
| TaskType.CODE_REVIEW: [AgentCapability.CODE_REVIEW], | |
| TaskType.DEBUGGING: [AgentCapability.CODE_GENERATION, AgentCapability.ANALYSIS], | |
| TaskType.ARCHITECTURE: [AgentCapability.ARCHITECTURE_DESIGNER], | |
| TaskType.RESEARCH: [AgentCapability.RESEARCH, AgentCapability.RESEARCH_SPECIALIST], | |
| TaskType.DOCUMENTATION: [AgentCapability.CREATIVE], | |
| TaskType.TESTING: [AgentCapability.TEST_AUTOMATION], | |
| TaskType.DEPLOYMENT: [AgentCapability.INTEGRATION], | |
| TaskType.OPTIMIZATION: [AgentCapability.PERFORMANCE_OPTIMIZER], | |
| TaskType.SECURITY_AUDIT: [AgentCapability.SECURITY_SPECIALIST], | |
| TaskType.CONSTITUTIONAL_VALIDATION: [AgentCapability.CONSTITUTIONAL_VALIDATOR], | |
| TaskType.WORKFLOW_AUTOMATION: [AgentCapability.ORCHESTRATION], | |
| TaskType.CODING: [AgentCapability.CODE_GENERATION], | |
| TaskType.ANALYSIS: [AgentCapability.ANALYSIS], | |
| TaskType.CREATIVE: [AgentCapability.CREATIVE], | |
| TaskType.INTEGRATION: [AgentCapability.INTEGRATION], | |
| TaskType.GOVERNANCE: [AgentCapability.GOVERNANCE], | |
| } | |
| required_capabilities = capability_map.get(task_type, []) | |
| if not required_capabilities: | |
| return True # Unknown task types can be handled by any agent | |
| return any(cap in self.capabilities for cap in required_capabilities) | |
| def to_dict(self) -> JSONDict: | |
| """Convert to dictionary.""" | |
| return { | |
| "agent_id": self.agent_id, | |
| "name": self.name, | |
| "agent_type": self.agent_type, | |
| "capabilities": [c.value for c in self.capabilities], | |
| "is_active": self.is_active, | |
| "status": self.status, | |
| "current_task": self.current_task, | |
| "performance_score": self.performance_score, | |
| "constitutional_hash": self.constitutional_hash, | |
| } | |
| def from_dict(cls, data: JSONDict) -> "SwarmAgent": | |
| """Create from dictionary.""" | |
| capabilities = [] | |
| raw_capabilities = data.get("capabilities", []) | |
| if not isinstance(raw_capabilities, list): | |
| raw_capabilities = [] | |
| for cap in raw_capabilities: | |
| try: | |
| if isinstance(cap, AgentCapability): | |
| capabilities.append(cap) | |
| else: | |
| capabilities.append(AgentCapability(cap)) | |
| except ValueError: | |
| pass # Skip unknown capabilities | |
| return cls( | |
| agent_id=str(data["agent_id"]), | |
| name=str(data.get("name", "")), | |
| agent_type=str(data.get("agent_type", "")), | |
| capabilities=capabilities, | |
| is_active=bool(data.get("is_active", True)), | |
| status=str(data.get("status", "idle")), | |
| current_task=str(data["current_task"]) | |
| if data.get("current_task") is not None | |
| else None, | |
| performance_score=float(data.get("performance_score", 1.0)), # type: ignore[arg-type] | |
| constitutional_hash=str(data.get("constitutional_hash", CONSTITUTIONAL_HASH)), | |
| ) | |
| __all__ = [ | |
| "SwarmAgent", | |
| ] | |
Xet Storage Details
- Size:
- 4.95 kB
- Xet hash:
- 3e0eec33611627b4b9452ef465b048bcafbd1839b27bf21105cc8e8d3bc683e9
·
Xet efficiently stores files, intelligently splitting them into unique chunks and accelerating uploads and downloads. More info.