Remove obsolete base class ToolInterface

This commit is contained in:
Dominik Jain
2025-07-10 00:12:13 +02:00
committed by Dominik Jain
parent 84e066e647
commit ee88204cba
2 changed files with 9 additions and 33 deletions
+4 -4
View File
@@ -25,7 +25,7 @@ from serena.agent import (
)
from serena.config.context_mode import SerenaAgentContext, SerenaAgentMode
from serena.constants import DEFAULT_CONTEXT, DEFAULT_MODES
from serena.tools import ToolInterface
from serena.tools import Tool
from serena.util.exception import show_fatal_exception_safe
log = logging.getLogger(__name__)
@@ -62,7 +62,7 @@ class SerenaMCPFactory:
self.project = project
@staticmethod
def make_mcp_tool(tool: ToolInterface) -> MCPTool:
def make_mcp_tool(tool: Tool) -> MCPTool:
func_name = tool.get_name()
func_doc = tool.get_apply_docstring() or ""
func_arg_metadata = tool.get_apply_fn_metadata()
@@ -106,7 +106,7 @@ class SerenaMCPFactory:
)
@abstractmethod
def _iter_tools(self) -> Iterator[ToolInterface]:
def _iter_tools(self) -> Iterator[Tool]:
pass
# noinspection PyProtectedMember
@@ -204,7 +204,7 @@ class SerenaMCPFactorySingleProcess(SerenaMCPFactory):
def _instantiate_agent(self, serena_config: SerenaConfig, modes: list[SerenaAgentMode]) -> None:
self.agent = SerenaAgent(project=self.project, serena_config=serena_config, context=self.context, modes=modes)
def _iter_tools(self) -> Iterator[ToolInterface]:
def _iter_tools(self) -> Iterator[Tool]:
assert self.agent is not None
yield from self.agent.get_exposed_tool_instances()
+5 -29
View File
@@ -1,7 +1,7 @@
import inspect
import os
import traceback
from abc import ABC, abstractmethod
from abc import ABC
from collections.abc import Callable, Iterable
from dataclasses import dataclass
from types import TracebackType
@@ -87,31 +87,7 @@ class ToolMarkerOptional:
"""
class ToolInterface(ABC):
"""Protocol defining the complete interface that make_tool() expects from a tool."""
@abstractmethod
def get_name(self) -> str:
"""Get the tool name."""
...
@abstractmethod
def get_apply_docstring(self) -> str:
"""Get the docstring for the tool application, used by the MCP server."""
...
@abstractmethod
def get_apply_fn_metadata(self) -> FuncMetadata:
"""Get the metadata for the tool application function, used by the MCP server."""
...
@abstractmethod
def apply_ex(self, log_call: bool = True, catch_exceptions: bool = True, **kwargs: Any) -> str:
"""Apply the tool with logging and exception handling."""
...
class Tool(Component, ToolInterface):
class Tool(Component):
# NOTE: each tool should implement the apply method, which is then used in
# the central method of the Tool class `apply_ex`.
# Failure to do so will result in a RuntimeError at tool execution time.
@@ -176,11 +152,11 @@ class Tool(Component, ToolInterface):
return docstring.strip()
def get_apply_docstring(self) -> str:
"""Get the docstring for the apply method (instance method implementing ToolProtocol)."""
"""Gets the docstring for the tool application, used by the MCP server."""
return self.get_apply_docstring_from_cls()
def get_apply_fn_metadata(self) -> FuncMetadata:
"""Get the metadata for the apply method (instance method implementing ToolProtocol)."""
"""Gets the metadata for the tool application function, used by the MCP server."""
return self.get_apply_fn_metadata_from_cls()
@classmethod
@@ -225,7 +201,7 @@ class Tool(Component, ToolInterface):
def apply_ex(self, log_call: bool = True, catch_exceptions: bool = True, **kwargs) -> str: # type: ignore
"""
Applies the tool with the given arguments
Applies the tool with logging and exception handling, using the given keyword arguments
"""
def task() -> str: