Spaces:
Sleeping
Sleeping
File size: 1,315 Bytes
c34b33b |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 |
"""
Base Agent Module
==================
Abstract base class for all agents in the system.
"""
from abc import ABC, abstractmethod
from dataclasses import dataclass, field
from typing import Any
import logging
import uuid
# Configure logging
logging.basicConfig(level=logging.INFO)
@dataclass
class BaseAgent(ABC):
"""
Abstract base class for all agents.
Attributes:
id: Unique identifier for the agent instance
role: The role/purpose of this agent
tools: List of tool names this agent can use
"""
role: str
tools: list[str] = field(default_factory=list)
id: str = field(default_factory=lambda: str(uuid.uuid4())[:8])
def __post_init__(self):
self.logger = logging.getLogger(f"Agent-{self.role}-{self.id}")
@abstractmethod
async def run(self, input: dict[str, Any]) -> dict[str, Any]:
"""
Execute the agent's main task.
Args:
input: Dictionary containing input parameters for the agent
Returns:
Dictionary containing the agent's output/results
"""
pass
def log(self, message: str, level: str = "info"):
"""Log a message with the agent's context."""
getattr(self.logger, level)(f"[{self.role}] {message}")
|