8000 refactor(config): move BaseToolConfig to a separate file · iambenn/adk-python@ef83701 · GitHub
[go: up one dir, main page]

Skip to content

Commit ef83701

Browse files
wuliang229copybara-github
authored andcommitted
refactor(config): move BaseToolConfig to a separate file
PiperOrigin-RevId: 791841562
1 parent 54cc849 commit ef83701

File tree

9 files changed

+139
-114
lines changed
  • tools
  • tests/unittests/tools
  • 9 files changed

    +139
    -114
    lines changed

    src/google/adk/agents/llm_agent.py

    Lines changed: 1 addition & 1 deletion
    Original file line numberDiff line numberDiff line change
    @@ -47,9 +47,9 @@
    4747
    from ..models.registry import LLMRegistry
    4848
    from ..planners.base_planner import BasePlanner
    4949
    from ..tools.base_tool import BaseTool
    50-
    from ..tools.base_tool import ToolConfig
    5150
    from ..tools.base_toolset import BaseToolset
    5251
    from ..tools.function_tool import FunctionTool
    52+
    from ..tools.tool_configs import ToolConfig
    5353
    from ..tools.tool_context import ToolContext
    5454
    from ..utils.feature_decorator import working_in_progress
    5555
    from .base_agent import BaseAgent

    src/google/adk/agents/llm_agent_config.py

    Lines changed: 1 addition & 1 deletion
    Original file line numberDiff line numberDiff line change
    @@ -22,7 +22,7 @@
    2222
    from google.genai import types
    2323
    from pydantic import ConfigDict
    2424

    25-
    from ..tools.base_tool import ToolConfig
    25+
    from ..tools.tool_configs import ToolConfig
    2626
    from .base_agent_config import BaseAgentConfig
    2727
    from .common_configs import CodeConfig
    2828

    src/google/adk/tools/agent_tool.py

    Lines changed: 2 additions & 2 deletions
    Original file line numberDiff line numberDiff line change
    @@ -28,8 +28,8 @@
    2828
    from ..memory.in_memory_memory_service import InMemoryMemoryService
    2929
    from ._forwarding_artifact_service import ForwardingArtifactService
    3030
    from .base_tool import BaseTool
    31-
    from .base_tool import BaseToolConfig
    32-
    from .base_tool import ToolArgsConfig
    31+
    from .tool_configs import BaseToolConfig
    32+
    from .tool_configs import ToolArgsConfig
    3333
    from .tool_context import ToolContext
    3434

    3535
    if TYPE_CHECKING:

    src/google/adk/tools/base_tool.py

    Lines changed: 0 additions & 103 deletions
    Original file line numberDiff line numberDiff line change
    @@ -249,106 +249,3 @@ def _find_tool_with_function_declarations(
    249249
    ),
    250250
    None,
    251251
    )
    252-
    253-
    254-
    class ToolArgsConfig(BaseModel):
    255-
    """The configuration for tool arguments.
    256-
    257-
    This config allows arbitrary key-value pairs as tool arguments.
    258-
    """
    259-
    260-
    model_config = ConfigDict(extra="allow")
    261-
    262-
    263-
    class ToolConfig(BaseModel):
    264-
    """The configuration for a tool.
    265-
    266-
    The config supports these types of tools:
    267-
    1. ADK built-in tools
    268-
    2. User-defined tool instances
    269-
    3. User-defined tool classes
    270-
    4. User-defined functions that generate tool instances
    271-
    5. User-defined function tools
    272-
    273-
    For examples:
    274-
    275-
    1. For ADK built-in tool instances or classes in `google.adk.tools` package,
    276-
    they can be referenced directly with the `name` and optionally with
    277-
    `config`.
    278-
    279-
    ```
    280-
    tools:
    281-
    - name: google_search
    282-
    - name: AgentTool
    283-
    config:
    284-
    agent: ./another_agent.yaml
    285-
    skip_summarization: true
    286-
    ```
    287-
    288-
    2. For user-defined tool instances, the `name` is the fully qualified path
    289-
    to the tool instance.
    290-
    291-
    ```
    292-
    tools:
    293-
    - name: my_package.my_module.my_tool
    294-
    ```
    295-
    296-
    3. For user-defined tool classes (custom tools), the `name` is the fully
    297-
    qualified path to the tool class and `config` is the arguments for the tool.
    298-
    299-
    ```
    300-
    tools:
    301-
    - name: my_package.my_module.my_tool_class
    302-
    config:
    303-
    my_tool_arg1: value1
    304-
    my_tool_arg2: value2
    305-
    ```
    306-
    307-
    4. For user-defined functions that generate tool instances, the `name` is
    308-
    the fully qualified path to the function and `config` is passed to the
    309-
    function as arguments.
    310-
    311-
    ```
    312-
    tools:
    313-
    - name: my_package.my_module.my_tool_function
    314-
    config:
    315-
    my_function_arg1: value1
    316-
    my_function_arg2: value2
    317-
    ```
    318-
    319-
    The function must have the following signature:
    320-
    ```
    321-
    def my_function(config: ToolArgsConfig) -> BaseTool:
    322-
    ...
    323-
    ```
    324-
    325-
    5. For user-defined function tools, the `name` is the fully qualified path
    326-
    to the function.
    327-
    328-
    ```
    329-
    tools:
    330-
    - name: my_package.my_module.my_function_tool
    331-
    ```
    332-
    """
    333-
    334-
    model_config = ConfigDict(extra="forbid")
    335-
    336-
    name: str
    337-
    """The name of the tool.
    338-
    339-
    For ADK built-in tools, the name is the name of the tool, e.g. `google_search`
    340-
    or `AgentTool`.
    341-
    342-
    For user-defined tools, the name is the fully qualified path to the tool, e.g.
    343-
    `my_package.my_module.my_tool`.
    344-
    """
    345-
    346-
    args: Optional[ToolArgsConfig] = None
    347-
    """The args for the tool."""
    348-
    349-
    350-
    class BaseToolConfig(BaseModel):
    351-
    """The base configurations for all the tools."""
    352-
    353-
    model_config = ConfigDict(extra="forbid")
    354-
    """Forbid extra fields."""

    src/google/adk/tools/crewai_tool.py

    Lines changed: 2 additions & 2 deletions
    Original file line numberDiff line numberDiff line change
    @@ -18,9 +18,9 @@
    1818
    from typing_extensions import override
    1919

    2020
    from . import _automatic_function_calling_util
    21-
    from .base_tool import BaseToolConfig
    22-
    from .base_tool import ToolArgsConfig
    2321
    from .function_tool import FunctionTool
    22+
    from .tool_configs import BaseToolConfig
    23+
    from .tool_configs import ToolArgsConfig
    2424

    2525
    try:
    2626
    from crewai.tools import BaseTool as CrewaiBaseTool

    src/google/adk/tools/example_tool.py

    Lines changed: 2 additions & 2 deletions
    Original file line numberDiff line numberDiff line change
    @@ -24,8 +24,8 @@
    2424
    from ..examples.base_example_provider import BaseExampleProvider
    2525
    from ..examples.example import Example
    2626
    from .base_tool import BaseTool
    27-
    from .base_tool import BaseToolConfig
    28-
    from .base_tool import ToolArgsConfig
    27+
    from .tool_configs import BaseToolConfig
    28+
    from .tool_configs import ToolArgsConfig
    2929
    from .tool_context import ToolContext
    3030

    3131
    if TYPE_CHECKING:

    src/google/adk/tools/langchain_tool.py

    Lines changed: 2 additions & 2 deletions
    Original file line numberDiff line numberDiff line change
    @@ -24,9 +24,9 @@
    2424
    from typing_extensions import override
    2525

    2626
    from . import _automatic_function_calling_util
    27-
    from .base_tool import BaseToolConfig
    28-
    from .base_tool import ToolArgsConfig
    2927
    from .function_tool import FunctionTool
    28+
    from .tool_configs import BaseToolConfig
    29+
    from .tool_configs import ToolArgsConfig
    3030

    3131

    3232
    class LangchainTool(FunctionTool):
    Lines changed: 128 additions & 0 deletions
    < 2925 td data-grid-cell-id="diff-8c6346f02016f8d1120d2707c272a1140b13c95750c83c15737bb8e074a67cfe-empty-16-2" data-line-anchor="diff-8c6346f02016f8d1120d2707c272a1140b13c95750c83c15737bb8e074a67cfeR16" data-selected="false" role="gridcell" style="background-color:var(--diffBlob-additionLine-bgColor, var(--diffBlob-addition-bgColor-line));padding-right:24px" tabindex="-1" valign="top" class="focusable-grid-cell diff-text-cell right-side-diff-cell pt-4 left-side">+
    Original file line numberDiff line numberDiff line change
    @@ -0,0 +1,128 @@
    1+
    # Copyright 2025 Google LLC
    2+
    #
    3+
    # Licensed under the Apache License, Version 2.0 (the "License");
    4+
    # you may not use this file except in compliance with the License.
    5+
    # You may obtain a copy of the License at
    6+
    #
    7+
    # http://www.apache.org/licenses/LICENSE-2.0
    8+
    #
    9+
    # Unless required by applicable law or agreed to in writing, software
    10+
    # distributed under the License is distributed on an "AS IS" BASIS,
    11+
    # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    12+
    # See the License for the specific language governing permissions and
    13+
    # limitations under the License.
    14+
    15+
    from __future__ import annotations
    16
    17+
    from typing import Optional
    18+
    19+
    from pydantic import BaseModel
    20+
    from pydantic import ConfigDict
    21+
    22+
    from ..utils.feature_decorator import working_in_progress
    23+
    24+
    25+
    @working_in_progress("BaseToolConfig is not ready for use.")
    26+
    class BaseToolConfig(BaseModel):
    27+
    """The base class for all tool configs."""
    28+
    29+
    model_config = ConfigDict(extra="forbid")
    30+
    """Forbid extra fields."""
    31+
    32+
    33+
    @working_in_progress("ToolArgsConfig is not ready for use.")
    34+
    class ToolArgsConfig(BaseModel):
    35+
    """Config to host free key-value pairs for the args in ToolConfig."""
    36+
    37+
    model_config = ConfigDict(extra="allow")
    38+
    39+
    40+
    @working_in_progress("ToolConfig is not ready for use.")
    41+
    class ToolConfig(BaseModel):
    42+
    """The configuration for a tool.
    43+
    44+
    The config supports these types of tools:
    45+
    1. ADK built-in tools
    46+
    2. User-defined tool instances
    47+
    3. User-defined tool classes
    48+
    4. User-defined functions that generate tool instances
    49+
    5. User-defined function tools
    50+
    51+
    For examples:
    52+
    53+
    1. For ADK built-in tool instances or classes in `google.adk.tools` package,
    54+
    they can be referenced directly with the `name` and optionally with
    55+
    `args`.
    56+
    57+
    ```
    58+
    tools:
    59+
    - name: google_search
    60+
    - name: AgentTool
    61+
    args:
    62+
    agent: ./another_agent.yaml
    63+
    skip_summarization: true
    64+
    ```
    65+
    66+
    2. For user-defined tool instances, the `name` is the fully qualified path
    67+
    to the tool instance.
    68+
    69+
    ```
    70+
    tools:
    71+
    - name: my_package.my_module.my_tool
    72+
    ```
    73+
    74+
    3. For user-defined tool classes (custom tools), the `name` is the fully
    75+
    qualified path to the tool class and `args` is the arguments for the tool.
    76+
    77+
    ```
    78+
    tools:
    79+
    - name: my_package.my_module.my_tool_class
    80+
    args:
    81+
    my_tool_arg1: value1
    82+
    my_tool_arg2: value2
    83+
    ```
    84+
    85+
    4. For user-defined functions that generate tool instances, the `name` is
    86+
    the fully qualified path to the function and `args` is passed to the
    87+
    function as arguments.
    88+
    89+
    ```
    90+
    tools:
    91+
    - name: my_package.my_module.my_tool_function
    92+
    args:
    93+
    my_function_arg1: value1
    94+
    my_function_arg2: value2
    95+
    ```
    96+
    97+
    The function must have the following signature:
    98+
    ```
    99+
    def my_function(args: ToolArgsConfig) -> BaseTool:
    100+
    ...
    101+
    ```
    102+
    103+
    5. For user-defined function tools, the `name` is the fully qualified path
    104+
    to the function.
    105+
    106+
    ```
    107+
    tools:
    108+
    - name: my_package.my_module.my_function_tool
    109+
    ```
    110+
    111+
    If the above use cases don't suffice, users can define a custom tool config
    112+
    by extending BaseToolConfig and override from_config() in the custom tool.
    113+
    """
    114+
    115+
    model_config = ConfigDict(extra="forbid")
    116+
    117+
    name: str
    118+
    """The name of the tool.
    119+
    120+
    For ADK built-in tools, `name` is the name of the tool, e.g. `google_search`
    121+
    or `AgentTool`.
    122+
    123+
    For user-defined tools, the name is the fully qualified path to the tool, e.g.
    124+
    `my_package.my_module.my_tool`.
    125+
    """
    126+
    127+
    args: Optional[ToolArgsConfig] = None
    128+
    """The args for the tool."""

    tests/unittests/tools/test_tool_config.py

    Lines changed: 1 addition & 1 deletion
    Original file line numberDiff line numberDiff line change
    @@ -13,7 +13,7 @@
    1313
    # limitations under the License.
    1414

    1515
    from google.adk.tools import VertexAiSearchTool
    16-
    from google.adk.tools.base_tool import ToolConfig
    16+
    from google.adk.tools.tool_configs import ToolConfig
    1717
    from google.genai import types
    1818
    import yaml
    1919

    0 commit comments

    Comments
     (0)
    0