File size: 1,705 Bytes
f7e620e
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
51
52
53
54
55
56
57
58
59
"""
Base agent class for EmotionMirror application.
Provides the foundation for all agent implementations.
"""
from abc import ABC, abstractmethod
import logging
from typing import Dict, Any

class BaseAgent(ABC):
    """Base class for all agents in EmotionMirror"""
    
    def __init__(self, name: str, description: str = ""):
        """
        Initialize the base agent.
        
        Args:
            name: Name of the agent
            description: Description of the agent's purpose
        """
        self.name = name
        self.description = description
        self.logger = logging.getLogger(f"agent.{name}")
        
    @abstractmethod
    def process(self, data: Dict[str, Any]) -> Dict[str, Any]:
        """
        Process data and return a result.
        
        Args:
            data: Input data to process
            
        Returns:
            Dictionary with processing results
        """
        pass
    
    def log_activity(self, message: str, level: str = 'info') -> None:
        """
        Log agent activity.
        
        Args:
            message: Log message
            level: Log level (debug, info, warning, error, critical)
        """
        log_methods = {
            'debug': self.logger.debug,
            'info': self.logger.info,
            'warning': self.logger.warning,
            'error': self.logger.error,
            'critical': self.logger.critical
        }
        
        log_method = log_methods.get(level.lower(), self.logger.info)
        log_method(f"[{self.name}] {message}")
        
    def __str__(self) -> str:
        """String representation of the agent"""
        return f"Agent({self.name}): {self.description}"