Skip to content

Commit 7dc6adf

Browse files
google-genai-botcopybara-github
authored andcommitted
feat: migrate ToolboxToolset to use toolbox-adk and align validation
### Description of Change **Problem:** The `ToolboxToolset` was relying on the legacy `toolbox-core` package. Users wanting to use the Toolbox features were forced to install the heavy `[extensions]` group, lacking a granular installation option. Additionally, `ToolboxToolset` had a validation check enforcing either `toolset_name` or `tool_names` to be present, preventing the default behavior of loading all tools (which `toolbox-adk` supports). **Solution:** * Refactored `ToolboxToolset` to delegate to `toolbox-adk`. * Added a new `toolbox` optional dependency group in `pyproject.toml`. * Users can now run `pip install google-adk[toolbox]` to install only the necessary dependencies. * Updated the `extensions` dependency group to replace `toolbox-core` with `toolbox-adk`. * This ensures existing users of `[extensions]` are not broken upon upgrade. * Removed the restrictive validation check to allow default loading of all tools. * Updated the `ImportError` message to guide users toward the new granular installation command. ### Testing Plan **Unit Tests:** - [x] I have added or updated unit tests for my change. - [x] All unit tests pass locally. **Manual End-to-End (E2E) Tests:** - Verified that the sample agent runs correctly with `toolbox-adk` locally. - Verified that `ToolboxToolset` can now be instantiated without arguments to load all tools. ### Checklist - [x] I have read the [CONTRIBUTING.md](https://github.com/google/adk-python/blob/main/CONTRIBUTING.md) document. - [x] I have performed a self-review of my own code. - [x] I have commented my code, particularly in hard-to-understand areas. - [x] I have added tests that prove my fix is effective or that my feature works. - [x] New and existing unit tests pass locally with my changes. - [x] I have manually tested my changes end-to-end. - [x] Any dependent changes have been merged and published in downstream modules. PiperOrigin-RevId: 857171811
1 parent d0aef8a commit 7dc6adf

File tree

3 files changed

+32
-33
lines changed

3 files changed

+32
-33
lines changed

contributing/samples/toolbox_agent/README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,10 +26,10 @@ Install SQLite from [https://sqlite.org/](https://sqlite.org/)
2626

2727
### 3. Install Required Python Dependencies
2828

29-
**Important**: The ADK's `ToolboxToolset` class requires the `toolbox-core` package, which is not automatically installed with the ADK. Install it using:
29+
**Important**: The ADK's `ToolboxToolset` class requires the `toolbox-adk` package, which is not automatically installed with the ADK. Install it using:
3030

3131
```bash
32-
pip install toolbox-core
32+
pip install google-adk[toolbox]
3333
```
3434

3535
### 4. Create Database (Optional)

pyproject.toml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -157,11 +157,12 @@ extensions = [
157157
"llama-index-readers-file>=0.4.0", # For retrieval using LlamaIndex.
158158
"llama-index-embeddings-google-genai>=0.3.0", # For files retrieval using LlamaIndex.
159159
"lxml>=5.3.0", # For load_web_page tool.
160-
"toolbox-adk>=0.1.0", # For tools.toolbox_toolset.ToolboxToolset
160+
"toolbox-adk>=0.5.7, <0.6.0", # For tools.toolbox_toolset.ToolboxToolset
161161
]
162162

163163
otel-gcp = ["opentelemetry-instrumentation-google-genai>=0.3b0, <1.0.0"]
164164

165+
toolbox = ["toolbox-adk>=0.5.7, <0.6.0"]
165166

166167
[tool.pyink]
167168
# Format py files following Google style-guide

src/google/adk/tools/toolbox_toolset.py

Lines changed: 28 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -35,19 +35,9 @@
3535
class ToolboxToolset(BaseToolset):
3636
"""A class that provides access to toolbox toolsets.
3737
38-
This class acts as a bridge to the `toolbox-adk` package.
39-
You must install `toolbox-adk` to use this class.
40-
4138
Example:
4239
```python
43-
from toolbox_adk import CredentialStrategy
44-
45-
toolbox_toolset = ToolboxToolset(
46-
server_url="http://127.0.0.1:5000",
47-
# toolset_name and tool_names are optional. If omitted, all tools are
48-
loaded.
49-
credentials=CredentialStrategy.toolbox_identity()
50-
)
40+
toolbox_toolset = ToolboxToolset("http://127.0.0.1:5000")
5141
```
5242
"""
5343

@@ -64,29 +54,37 @@ def __init__(
6454
additional_headers: Optional[Mapping[str, str]] = None,
6555
**kwargs,
6656
):
67-
"""Args:
68-
69-
server_url: The URL of the toolbox server.
70-
toolset_name: The name of the toolbox toolset to load.
71-
tool_names: The names of the tools to load.
72-
auth_token_getters: (Deprecated) Map of auth token getters.
73-
bound_params: Parameters to bind to the tools.
74-
credentials: (Optional) toolbox_adk.CredentialConfig object.
75-
additional_headers: (Optional) Static headers dictionary.
76-
**kwargs: Additional arguments passed to the underlying
77-
toolbox_adk.ToolboxToolset.
57+
"""Initializes the ToolboxToolset.
58+
59+
Args:
60+
server_url: The URL of the toolbox server.
61+
toolset_name: (Optional) The name of the toolbox toolset to load.
62+
tool_names: (Optional) The names of the tools to load.
63+
auth_token_getters: (Optional) A mapping of authentication service names
64+
to callables that return the corresponding authentication token. see:
65+
https://github.com/googleapis/mcp-toolbox-sdk-python/tree/main/packages/toolbox-core#authenticating-tools
66+
for details.
67+
bound_params: (Optional) A mapping of parameter names to bind to specific
68+
values or callables that are called to produce values as needed. see:
69+
https://github.com/googleapis/mcp-toolbox-sdk-python/tree/main/packages/toolbox-core#binding-parameter-values
70+
for details.
71+
credentials: (Optional) toolbox_adk.CredentialConfig object.
72+
additional_headers: (Optional) Static headers mapping.
73+
**kwargs: Additional arguments passed to the underlying
74+
toolbox_adk.ToolboxToolset.
75+
76+
The resulting ToolboxToolset will contain both tools loaded by tool_names
77+
and toolset_name.
78+
79+
Note: toolset_name and tool_names are optional.
80+
If both are omitted, all tools are loaded.
7881
"""
79-
if not toolset_name and not tool_names:
80-
raise ValueError(
81-
"Either 'toolset_name' or 'tool_names' must be provided."
82-
)
83-
8482
try:
8583
from toolbox_adk import ToolboxToolset as RealToolboxToolset # pylint: disable=import-outside-toplevel
8684
except ImportError as exc:
8785
raise ImportError(
8886
"ToolboxToolset requires the 'toolbox-adk' package. "
89-
"Please install it using `pip install toolbox-adk`."
87+
"Please install it using `pip install google-adk[toolbox]`."
9088
) from exc
9189

9290
super().__init__()
@@ -95,10 +93,10 @@ def __init__(
9593
server_url=server_url,
9694
toolset_name=toolset_name,
9795
tool_names=tool_names,
96+
auth_token_getters=auth_token_getters,
97+
bound_params=bound_params,
9898
credentials=credentials,
9999
additional_headers=additional_headers,
100-
bound_params=bound_params,
101-
auth_token_getters=auth_token_getters,
102100
**kwargs,
103101
)
104102

0 commit comments

Comments
 (0)