From 81e9d5a3f6566efe3305d5fdb39819efba28b68a Mon Sep 17 00:00:00 2001 From: Michael Panchenko Date: Sat, 5 Apr 2025 19:21:32 +0200 Subject: [PATCH] Minor deduplication --- src/serena/agent.py | 13 +++++-------- 1 file changed, 5 insertions(+), 8 deletions(-) diff --git a/src/serena/agent.py b/src/serena/agent.py index e4603e1..88983da 100644 --- a/src/serena/agent.py +++ b/src/serena/agent.py @@ -209,14 +209,14 @@ _DEFAULT_MAX_ANSWER_LENGTH = int(2e5) 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 an exception at runtime. + # Failure to do so will result in a RuntimeError at tool execution time. # The apply method is not declared as part of the base Tool interface since we cannot # know the signature of the (input parameters of the) method in advance. - # + # # The docstring and types of the apply method are used to generate the tool description # (which is use by the LLM, so a good description is important) # and to validate the tool call arguments. - + @classmethod def get_name(cls) -> str: name = cls.__name__ @@ -229,7 +229,7 @@ class Tool(Component): def get_apply_fn(self) -> Callable: apply_fn = getattr(self, "apply") if apply_fn is None: - raise Exception(f"{self} does not define method apply") + raise RuntimeError(f"apply not defined in {self}. Did you forget to implement it?") return apply_fn @classmethod @@ -271,10 +271,7 @@ class Tool(Component): """ Applies the tool with the given arguments """ - apply_fn = getattr(self, "apply") - if apply_fn is None: - raise ValueError(f"apply not defined in {self}. Did you forget to implement it?") - + apply_fn = self.get_apply_fn() if log_call: self._log_tool_application(inspect.currentframe()) try: