File size: 1,464 Bytes
8bacf7a
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
c537b15
8bacf7a
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
class BaseTool:
    """
    Minimal base class for CrewAI or modular AI agent tools.

    Inherit from this class for each custom tool to ensure a consistent interface.

    Attributes:
        config (dict or object, optional): Configuration provided on initialization.
    """

    def __init__(self, config=None):
        """
        Initialize the tool with optional configuration.

        Args:
            config (dict or object, optional): Configuration dictionary or object.
        """
        self.config = config

    def __call__(self, *args, **kwargs):
        """
        Abstract method for executing the tool's logic.
        To be implemented in child classes.

        Raises:
            NotImplementedError: If not overridden in a subclass.
        """
        raise NotImplementedError(
            f"{self.__class__.__name__} must implement the __call__ method."
        )

    @property
    def name(self):
        """
        Returns the name of the tool class.

        Returns:
            str: Class name by default.
        """
        return self.__class__.__name__

    def description(self):
        """
        Optionally provide a description string for the tool.

        Returns:
            str: Tool description, can be overridden by child classes.
        """
        return f"{self.name} (custom tool base class for CrewAI and modular agents)."

    # You can add more utility methods/properties if you wish (e.g., metadata)