Skip to content

src.tools.core.base_tool.BaseTool

Abstract base class for all tools in the system.

Provides the foundation for tool implementation with standard interfaces for execution, definition retrieval, and output parsing.

Source code in src/tools/core/base_tool.py
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
class BaseTool:
    """Abstract base class for all tools in the system.

    Provides the foundation for tool implementation with standard interfaces
    for execution, definition retrieval, and output parsing.
    """
    name: str

    def __init__(self, config: Optional[Dict] = None):
        self.config = config or {}
        self.description = None
        self.parameters = {}
        self.strict = False

    @abstractmethod
    async def execute(self, context: Optional[StreamContext] = None, **kwargs) -> ToolResponse:
        """Execute the tool's main functionality."""
        pass

    def get_definition(self) -> Tool:
        """Get the tool's OpenAI-compatible definition.

        Returns:
            Tool: Tool definition including type, function details and parameters.
        """
        return Tool(
            type="function",
            function=Function(
                name=self.name,
                description=self.description,
                parameters=FunctionParameters(
                    type="object",
                    properties=self.parameters.get("properties", {}),
                    required=self.parameters.get("required", []),
                    additionalProperties=self.parameters.get("additionalProperties", None)
                ),
                strict=self.strict
            )
        )

    @abstractmethod
    def parse_output(self, output: str):
        """Parse the tool's output."""
        pass

    def get_tool_specific_instruction(self) -> str:
        """Get formatted tool-specific instruction."""
        return ""

execute(context=None, **kwargs) abstractmethod async

Execute the tool's main functionality.

Source code in src/tools/core/base_tool.py
24
25
26
27
@abstractmethod
async def execute(self, context: Optional[StreamContext] = None, **kwargs) -> ToolResponse:
    """Execute the tool's main functionality."""
    pass

get_definition()

Get the tool's OpenAI-compatible definition.

Returns:

Name Type Description
Tool Tool

Tool definition including type, function details and parameters.

Source code in src/tools/core/base_tool.py
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
def get_definition(self) -> Tool:
    """Get the tool's OpenAI-compatible definition.

    Returns:
        Tool: Tool definition including type, function details and parameters.
    """
    return Tool(
        type="function",
        function=Function(
            name=self.name,
            description=self.description,
            parameters=FunctionParameters(
                type="object",
                properties=self.parameters.get("properties", {}),
                required=self.parameters.get("required", []),
                additionalProperties=self.parameters.get("additionalProperties", None)
            ),
            strict=self.strict
        )
    )

get_tool_specific_instruction()

Get formatted tool-specific instruction.

Source code in src/tools/core/base_tool.py
55
56
57
def get_tool_specific_instruction(self) -> str:
    """Get formatted tool-specific instruction."""
    return ""

parse_output(output) abstractmethod

Parse the tool's output.

Source code in src/tools/core/base_tool.py
50
51
52
53
@abstractmethod
def parse_output(self, output: str):
    """Parse the tool's output."""
    pass