You've already forked adk-python
mirror of
https://github.com/encounter/adk-python.git
synced 2026-03-30 10:57:20 -07:00
chore: Migrate the rest of tools to use the new feature decorator
Co-authored-by: Xuan Yang <xygoogle@google.com> PiperOrigin-RevId: 854295648
This commit is contained in:
committed by
Copybara-Service
parent
fdc286a23c
commit
0fe3870cd5
@@ -24,17 +24,23 @@ from ..utils.env_utils import is_env_enabled
|
||||
class FeatureName(str, Enum):
|
||||
"""Feature names."""
|
||||
|
||||
AUTHENTICATED_FUNCTION_TOOL = "AUTHENTICATED_FUNCTION_TOOL"
|
||||
BASE_AUTHENTICATED_TOOL = "BASE_AUTHENTICATED_TOOL"
|
||||
BIG_QUERY_TOOLSET = "BIG_QUERY_TOOLSET"
|
||||
BIG_QUERY_TOOL_CONFIG = "BIG_QUERY_TOOL_CONFIG"
|
||||
BIGTABLE_TOOL_SETTINGS = "BIGTABLE_TOOL_SETTINGS"
|
||||
BIGTABLE_TOOLSET = "BIGTABLE_TOOLSET"
|
||||
COMPUTER_USE = "COMPUTER_USE"
|
||||
GOOGLE_CREDENTIALS_CONFIG = "GOOGLE_CREDENTIALS_CONFIG"
|
||||
GOOGLE_TOOL = "GOOGLE_TOOL"
|
||||
JSON_SCHEMA_FOR_FUNC_DECL = "JSON_SCHEMA_FOR_FUNC_DECL"
|
||||
PROGRESSIVE_SSE_STREAMING = "PROGRESSIVE_SSE_STREAMING"
|
||||
PUBSUB_TOOL_CONFIG = "PUBSUB_TOOL_CONFIG"
|
||||
PUBSUB_TOOLSET = "PUBSUB_TOOLSET"
|
||||
SPANNER_TOOLSET = "SPANNER_TOOLSET"
|
||||
SPANNER_TOOL_SETTINGS = "SPANNER_TOOL_SETTINGS"
|
||||
TOOL_CONFIG = "TOOL_CONFIG"
|
||||
TOOL_CONFIRMATION = "TOOL_CONFIRMATION"
|
||||
|
||||
|
||||
class FeatureStage(Enum):
|
||||
@@ -67,6 +73,12 @@ class FeatureConfig:
|
||||
|
||||
# Central registry: FeatureName -> FeatureConfig
|
||||
_FEATURE_REGISTRY: dict[FeatureName, FeatureConfig] = {
|
||||
FeatureName.AUTHENTICATED_FUNCTION_TOOL: FeatureConfig(
|
||||
FeatureStage.EXPERIMENTAL, default_on=True
|
||||
),
|
||||
FeatureName.BASE_AUTHENTICATED_TOOL: FeatureConfig(
|
||||
FeatureStage.EXPERIMENTAL, default_on=True
|
||||
),
|
||||
FeatureName.BIG_QUERY_TOOLSET: FeatureConfig(
|
||||
FeatureStage.EXPERIMENTAL, default_on=True
|
||||
),
|
||||
@@ -76,6 +88,9 @@ _FEATURE_REGISTRY: dict[FeatureName, FeatureConfig] = {
|
||||
FeatureName.BIGTABLE_TOOL_SETTINGS: FeatureConfig(
|
||||
FeatureStage.EXPERIMENTAL, default_on=True
|
||||
),
|
||||
FeatureName.BIGTABLE_TOOLSET: FeatureConfig(
|
||||
FeatureStage.EXPERIMENTAL, default_on=True
|
||||
),
|
||||
FeatureName.COMPUTER_USE: FeatureConfig(
|
||||
FeatureStage.EXPERIMENTAL, default_on=True
|
||||
),
|
||||
@@ -91,6 +106,9 @@ _FEATURE_REGISTRY: dict[FeatureName, FeatureConfig] = {
|
||||
FeatureName.PROGRESSIVE_SSE_STREAMING: FeatureConfig(
|
||||
FeatureStage.EXPERIMENTAL, default_on=True
|
||||
),
|
||||
FeatureName.PUBSUB_TOOL_CONFIG: FeatureConfig(
|
||||
FeatureStage.EXPERIMENTAL, default_on=True
|
||||
),
|
||||
FeatureName.PUBSUB_TOOLSET: FeatureConfig(
|
||||
FeatureStage.EXPERIMENTAL, default_on=True
|
||||
),
|
||||
@@ -100,6 +118,12 @@ _FEATURE_REGISTRY: dict[FeatureName, FeatureConfig] = {
|
||||
FeatureName.SPANNER_TOOL_SETTINGS: FeatureConfig(
|
||||
FeatureStage.EXPERIMENTAL, default_on=True
|
||||
),
|
||||
FeatureName.TOOL_CONFIG: FeatureConfig(
|
||||
FeatureStage.EXPERIMENTAL, default_on=True
|
||||
),
|
||||
FeatureName.TOOL_CONFIRMATION: FeatureConfig(
|
||||
FeatureStage.EXPERIMENTAL, default_on=True
|
||||
),
|
||||
}
|
||||
|
||||
# Track which experimental features have already warned (warn only once)
|
||||
|
||||
@@ -18,7 +18,6 @@ import inspect
|
||||
import logging
|
||||
from typing import Any
|
||||
from typing import Callable
|
||||
from typing import Dict
|
||||
from typing import Optional
|
||||
from typing import Union
|
||||
|
||||
@@ -27,14 +26,15 @@ from typing_extensions import override
|
||||
from ..auth.auth_credential import AuthCredential
|
||||
from ..auth.auth_tool import AuthConfig
|
||||
from ..auth.credential_manager import CredentialManager
|
||||
from ..utils.feature_decorator import experimental
|
||||
from ..features import experimental
|
||||
from ..features import FeatureName
|
||||
from .function_tool import FunctionTool
|
||||
from .tool_context import ToolContext
|
||||
|
||||
logger = logging.getLogger("google_adk." + __name__)
|
||||
|
||||
|
||||
@experimental
|
||||
@experimental(FeatureName.AUTHENTICATED_FUNCTION_TOOL)
|
||||
class AuthenticatedFunctionTool(FunctionTool):
|
||||
"""A FunctionTool that handles authentication before the actual tool logic
|
||||
gets called. Functions can accept a special `credential` argument which is the
|
||||
|
||||
@@ -25,14 +25,15 @@ from typing_extensions import override
|
||||
from ..auth.auth_credential import AuthCredential
|
||||
from ..auth.auth_tool import AuthConfig
|
||||
from ..auth.credential_manager import CredentialManager
|
||||
from ..utils.feature_decorator import experimental
|
||||
from ..features import experimental
|
||||
from ..features import FeatureName
|
||||
from .base_tool import BaseTool
|
||||
from .tool_context import ToolContext
|
||||
|
||||
logger = logging.getLogger("google_adk." + __name__)
|
||||
|
||||
|
||||
@experimental
|
||||
@experimental(FeatureName.BASE_AUTHENTICATED_TOOL)
|
||||
class BaseAuthenticatedTool(BaseTool):
|
||||
"""A base tool class that handles authentication before the actual tool logic
|
||||
gets called. Functions can accept a special `credential` argument which is the
|
||||
|
||||
@@ -23,18 +23,19 @@ from typing_extensions import override
|
||||
|
||||
from . import metadata_tool
|
||||
from . import query_tool
|
||||
from ...features import experimental
|
||||
from ...features import FeatureName
|
||||
from ...tools.base_tool import BaseTool
|
||||
from ...tools.base_toolset import BaseToolset
|
||||
from ...tools.base_toolset import ToolPredicate
|
||||
from ...tools.google_tool import GoogleTool
|
||||
from ...utils.feature_decorator import experimental
|
||||
from .bigtable_credentials import BigtableCredentialsConfig
|
||||
from .settings import BigtableToolSettings
|
||||
|
||||
DEFAULT_BIGTABLE_TOOL_NAME_PREFIX = "bigtable"
|
||||
|
||||
|
||||
@experimental
|
||||
@experimental(FeatureName.BIGTABLE_TOOLSET)
|
||||
class BigtableToolset(BaseToolset):
|
||||
"""Bigtable Toolset contains tools for interacting with Bigtable data and metadata.
|
||||
|
||||
|
||||
@@ -17,10 +17,11 @@ from __future__ import annotations
|
||||
from pydantic import BaseModel
|
||||
from pydantic import ConfigDict
|
||||
|
||||
from ...utils.feature_decorator import experimental
|
||||
from ...features import experimental
|
||||
from ...features import FeatureName
|
||||
|
||||
|
||||
@experimental('Config defaults may have breaking change in the future.')
|
||||
@experimental(FeatureName.PUBSUB_TOOL_CONFIG)
|
||||
class PubSubToolConfig(BaseModel):
|
||||
"""Configuration for Pub/Sub tools."""
|
||||
|
||||
|
||||
@@ -20,24 +20,25 @@ from pydantic import BaseModel
|
||||
from pydantic import ConfigDict
|
||||
from pydantic import Field
|
||||
|
||||
from ..utils.feature_decorator import experimental
|
||||
from ..features import experimental
|
||||
from ..features import FeatureName
|
||||
|
||||
|
||||
@experimental
|
||||
@experimental(FeatureName.TOOL_CONFIG)
|
||||
class BaseToolConfig(BaseModel):
|
||||
"""The base class for all tool configs."""
|
||||
|
||||
model_config = ConfigDict(extra="forbid")
|
||||
|
||||
|
||||
@experimental
|
||||
@experimental(FeatureName.TOOL_CONFIG)
|
||||
class ToolArgsConfig(BaseModel):
|
||||
"""Config to host free key-value pairs for the args in ToolConfig."""
|
||||
|
||||
model_config = ConfigDict(extra="allow")
|
||||
|
||||
|
||||
@experimental
|
||||
@experimental(FeatureName.TOOL_CONFIG)
|
||||
class ToolConfig(BaseModel):
|
||||
"""The configuration for a tool.
|
||||
|
||||
|
||||
@@ -20,12 +20,12 @@ from typing import Optional
|
||||
from pydantic import alias_generators
|
||||
from pydantic import BaseModel
|
||||
from pydantic import ConfigDict
|
||||
from pydantic import Field
|
||||
|
||||
from ..utils.feature_decorator import experimental
|
||||
from ..features import experimental
|
||||
from ..features import FeatureName
|
||||
|
||||
|
||||
@experimental
|
||||
@experimental(FeatureName.TOOL_CONFIRMATION)
|
||||
class ToolConfirmation(BaseModel):
|
||||
"""Represents a tool confirmation configuration."""
|
||||
|
||||
|
||||
Reference in New Issue
Block a user