From 2dd432cc1fe265a79986a28e2afb59ee2c83abb3 Mon Sep 17 00:00:00 2001 From: "Wei Sun (Jack)" Date: Tue, 26 Aug 2025 23:47:26 -0700 Subject: [PATCH] fix: add the missing `from_config` class method in BaseToolset PiperOrigin-RevId: 799893557 --- src/google/adk/tools/base_toolset.py | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/src/google/adk/tools/base_toolset.py b/src/google/adk/tools/base_toolset.py index 3400be40..201eec90 100644 --- a/src/google/adk/tools/base_toolset.py +++ b/src/google/adk/tools/base_toolset.py @@ -22,7 +22,9 @@ from typing import List from typing import Optional from typing import Protocol from typing import runtime_checkable +from typing import Type from typing import TYPE_CHECKING +from typing import TypeVar from typing import Union from ..agents.readonly_context import ReadonlyContext @@ -30,6 +32,7 @@ from .base_tool import BaseTool if TYPE_CHECKING: from ..models.llm_request import LlmRequest + from .tool_configs import ToolArgsConfig from .tool_context import ToolContext @@ -53,6 +56,9 @@ class ToolPredicate(Protocol): """ +SelfToolset = TypeVar("SelfToolset", bound="BaseToolset") + + class BaseToolset(ABC): """Base class for toolset. @@ -152,6 +158,22 @@ class BaseToolset(ABC): resources are properly released to prevent leaks. """ + @classmethod + def from_config( + cls: Type[SelfToolset], config: ToolArgsConfig, config_abs_path: str + ) -> SelfToolset: + """Creates a toolset instance from a config. + + Args: + config: The config for the tool. + config_abs_path: The absolute path to the config file that contains the + tool config. + + Returns: + The toolset instance. + """ + raise ValueError(f"from_config() not implemented for toolset: {cls}") + def _is_tool_selected( self, tool: BaseTool, readonly_context: ReadonlyContext ) -> bool: