fix: add the missing from_config class method in BaseToolset

PiperOrigin-RevId: 799893557
This commit is contained in:
Wei Sun (Jack)
2025-08-26 23:47:26 -07:00
committed by Copybara-Service
parent 3b997a0a07
commit 2dd432cc1f
+22
View File
@@ -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: