From 931fb338f8e71e29df351c643750b5bbf384ad30 Mon Sep 17 00:00:00 2001 From: "Xiang (Sean) Zhou" Date: Tue, 13 May 2025 16:33:53 -0700 Subject: [PATCH] rename tool_set to toolset to uniform the naming PiperOrigin-RevId: 758422703 --- contributing/samples/bigquery_agent/agent.py | 8 +- .../samples/oauth_calendar_agent/agent.py | 18 ++-- .../adk/tools/google_api_tool/__init__.py | 100 +++++++++--------- ..._api_tool_set.py => google_api_toolset.py} | 0 ...pi_tool_sets.py => google_api_toolsets.py} | 76 ++++++------- 5 files changed, 101 insertions(+), 101 deletions(-) rename src/google/adk/tools/google_api_tool/{google_api_tool_set.py => google_api_toolset.py} (100%) rename src/google/adk/tools/google_api_tool/{google_api_tool_sets.py => google_api_toolsets.py} (53%) diff --git a/contributing/samples/bigquery_agent/agent.py b/contributing/samples/bigquery_agent/agent.py index af23841..adf1193 100644 --- a/contributing/samples/bigquery_agent/agent.py +++ b/contributing/samples/bigquery_agent/agent.py @@ -16,7 +16,7 @@ import os from dotenv import load_dotenv from google.adk import Agent -from google.adk.tools.google_api_tool import bigquery_tool_set +from google.adk.tools.google_api_tool import bigquery_toolset # Load environment variables from .env file load_dotenv() @@ -24,7 +24,7 @@ load_dotenv() # Access the variable oauth_client_id = os.getenv("OAUTH_CLIENT_ID") oauth_client_secret = os.getenv("OAUTH_CLIENT_SECRET") -bigquery_tool_set.configure_auth(oauth_client_id, oauth_client_secret) +bigquery_toolset.configure_auth(oauth_client_id, oauth_client_secret) tools_to_expose = [ "bigquery_datasets_list", @@ -34,7 +34,7 @@ tools_to_expose = [ "bigquery_tables_get", "bigquery_tables_insert", ] -bigquery_tool_set.set_tool_filter( +bigquery_toolset.set_tool_filter( lambda tool, ctx=None: tool.name in tools_to_expose ) @@ -74,5 +74,5 @@ root_agent = Agent( {userInfo?} """, - tools=[bigquery_tool_set], + tools=[bigquery_toolset], ) diff --git a/contributing/samples/oauth_calendar_agent/agent.py b/contributing/samples/oauth_calendar_agent/agent.py index 554ddcf..e11153b 100644 --- a/contributing/samples/oauth_calendar_agent/agent.py +++ b/contributing/samples/oauth_calendar_agent/agent.py @@ -27,7 +27,7 @@ from google.adk.auth import AuthCredential from google.adk.auth import AuthCredentialTypes from google.adk.auth import OAuth2Auth from google.adk.tools import ToolContext -from google.adk.tools.google_api_tool import calendar_tool_set +from google.adk.tools.google_api_tool import calendar_toolset from google.auth.transport.requests import Request from google.oauth2.credentials import Credentials from googleapiclient.discovery import build @@ -42,15 +42,15 @@ oauth_client_secret = os.getenv("OAUTH_CLIENT_SECRET") SCOPES = ["https://www.googleapis.com/auth/calendar"] -calendar_tool_set.configure_auth( +calendar_toolset.configure_auth( client_id=oauth_client_id, client_secret=oauth_client_secret ) -calendar_tool_set.set_tool_filter( - # you can also replace below customized `list_calendar_events` with build-in - # google calendar tool by adding `calendar_events_list` in the filter list - lambda tool, ctx=None: tool.name - in ["calendar_events_get"] -) + +get_calendar_events = calendar_toolset.get_tool("calendar_events_get") +# list_calendar_events = calendar_toolset.get_tool("calendar_events_list") +# you can replace below customized list_calendar_events tool with above ADK +# build-in google calendar tool which is commented for now to acheive same +# effect. def list_calendar_events( @@ -210,6 +210,6 @@ root_agent = Agent( Currnet time: {_time} """, - tools=[list_calendar_events, calendar_tool_set], + tools=[list_calendar_events, get_calendar_events], before_agent_callback=update_time, ) diff --git a/src/google/adk/tools/google_api_tool/__init__.py b/src/google/adk/tools/google_api_tool/__init__.py index 7721225..ce1c85d 100644 --- a/src/google/adk/tools/google_api_tool/__init__.py +++ b/src/google/adk/tools/google_api_tool/__init__.py @@ -12,76 +12,76 @@ # See the License for the specific language governing permissions and # limitations under the License. __all__ = [ - 'bigquery_tool_set', - 'calendar_tool_set', - 'gmail_tool_set', - 'youtube_tool_set', - 'slides_tool_set', - 'sheets_tool_set', - 'docs_tool_set', + 'bigquery_toolset', + 'calendar_toolset', + 'gmail_toolset', + 'youtube_toolset', + 'slides_toolset', + 'sheets_toolset', + 'docs_toolset', ] # Nothing is imported here automatically # Each tool set will only be imported when accessed -_bigquery_tool_set = None -_calendar_tool_set = None -_gmail_tool_set = None -_youtube_tool_set = None -_slides_tool_set = None -_sheets_tool_set = None -_docs_tool_set = None +_bigquery_toolset = None +_calendar_toolset = None +_gmail_toolset = None +_youtube_toolset = None +_slides_toolset = None +_sheets_toolset = None +_docs_toolset = None def __getattr__(name): - global _bigquery_tool_set, _calendar_tool_set, _gmail_tool_set, _youtube_tool_set, _slides_tool_set, _sheets_tool_set, _docs_tool_set + global _bigquery_toolset, _calendar_toolset, _gmail_toolset, _youtube_toolset, _slides_toolset, _sheets_toolset, _docs_toolset match name: - case 'bigquery_tool_set': - if _bigquery_tool_set is None: - from .google_api_tool_sets import bigquery_tool_set as bigquery + case 'bigquery_toolset': + if _bigquery_toolset is None: + from .google_api_toolsets import bigquery_toolset as bigquery - _bigquery_tool_set = bigquery - return _bigquery_tool_set + _bigquery_toolset = bigquery + return _bigquery_toolset - case 'calendar_tool_set': - if _calendar_tool_set is None: - from .google_api_tool_sets import calendar_tool_set as calendar + case 'calendar_toolset': + if _calendar_toolset is None: + from .google_api_toolsets import calendar_toolset as calendar - _calendar_tool_set = calendar - return _calendar_tool_set + _calendar_toolset = calendar + return _calendar_toolset - case 'gmail_tool_set': - if _gmail_tool_set is None: - from .google_api_tool_sets import gmail_tool_set as gmail + case 'gmail_toolset': + if _gmail_toolset is None: + from .google_api_toolsets import gmail_toolset as gmail - _gmail_tool_set = gmail - return _gmail_tool_set + _gmail_toolset = gmail + return _gmail_toolset - case 'youtube_tool_set': - if _youtube_tool_set is None: - from .google_api_tool_sets import youtube_tool_set as youtube + case 'youtube_toolset': + if _youtube_toolset is None: + from .google_api_toolsets import youtube_toolset as youtube - _youtube_tool_set = youtube - return _youtube_tool_set + _youtube_toolset = youtube + return _youtube_toolset - case 'slides_tool_set': - if _slides_tool_set is None: - from .google_api_tool_sets import slides_tool_set as slides + case 'slides_toolset': + if _slides_toolset is None: + from .google_api_toolsets import slides_toolset as slides - _slides_tool_set = slides - return _slides_tool_set + _slides_toolset = slides + return _slides_toolset - case 'sheets_tool_set': - if _sheets_tool_set is None: - from .google_api_tool_sets import sheets_tool_set as sheets + case 'sheets_toolset': + if _sheets_toolset is None: + from .google_api_toolsets import sheets_toolset as sheets - _sheets_tool_set = sheets - return _sheets_tool_set + _sheets_toolset = sheets + return _sheets_toolset - case 'docs_tool_set': - if _docs_tool_set is None: - from .google_api_tool_sets import docs_tool_set as docs + case 'docs_toolset': + if _docs_toolset is None: + from .google_api_toolsets import docs_toolset as docs - _docs_tool_set = docs - return _docs_tool_set + _docs_toolset = docs + return _docs_toolset diff --git a/src/google/adk/tools/google_api_tool/google_api_tool_set.py b/src/google/adk/tools/google_api_tool/google_api_toolset.py similarity index 100% rename from src/google/adk/tools/google_api_tool/google_api_tool_set.py rename to src/google/adk/tools/google_api_tool/google_api_toolset.py diff --git a/src/google/adk/tools/google_api_tool/google_api_tool_sets.py b/src/google/adk/tools/google_api_tool/google_api_toolsets.py similarity index 53% rename from src/google/adk/tools/google_api_tool/google_api_tool_sets.py rename to src/google/adk/tools/google_api_tool/google_api_toolsets.py index 6835b02..a8b3545 100644 --- a/src/google/adk/tools/google_api_tool/google_api_tool_sets.py +++ b/src/google/adk/tools/google_api_tool/google_api_toolsets.py @@ -15,17 +15,17 @@ import logging -from .google_api_tool_set import GoogleApiToolset +from .google_api_toolset import GoogleApiToolset logger = logging.getLogger(__name__) -_bigquery_tool_set = None -_calendar_tool_set = None -_gmail_tool_set = None -_youtube_tool_set = None -_slides_tool_set = None -_sheets_tool_set = None -_docs_tool_set = None +_bigquery_toolset = None +_calendar_toolset = None +_gmail_toolset = None +_youtube_toolset = None +_slides_toolset = None +_sheets_toolset = None +_docs_toolset = None def __getattr__(name): @@ -37,7 +37,7 @@ def __getattr__(name): Args: name (str): The name of the tool set to retrieve (e.g., - "bigquery_tool_set"). + "bigquery_toolset"). Returns: GoogleApiToolSet: The requested tool set instance. @@ -45,68 +45,68 @@ def __getattr__(name): Raises: AttributeError: If the requested tool set name is not recognized. """ - global _bigquery_tool_set, _calendar_tool_set, _gmail_tool_set, _youtube_tool_set, _slides_tool_set, _sheets_tool_set, _docs_tool_set + global _bigquery_toolset, _calendar_toolset, _gmail_toolset, _youtube_toolset, _slides_toolset, _sheets_toolset, _docs_toolset match name: - case "bigquery_tool_set": - if _bigquery_tool_set is None: - _bigquery_tool_set = GoogleApiToolset.load_toolset( + case "bigquery_toolset": + if _bigquery_toolset is None: + _bigquery_toolset = GoogleApiToolset.load_toolset( api_name="bigquery", api_version="v2", ) - return _bigquery_tool_set + return _bigquery_toolset - case "calendar_tool_set": - if _calendar_tool_set is None: - _calendar_tool_set = GoogleApiToolset.load_toolset( + case "calendar_toolset": + if _calendar_toolset is None: + _calendar_toolset = GoogleApiToolset.load_toolset( api_name="calendar", api_version="v3", ) - return _calendar_tool_set + return _calendar_toolset - case "gmail_tool_set": - if _gmail_tool_set is None: - _gmail_tool_set = GoogleApiToolset.load_toolset( + case "gmail_toolset": + if _gmail_toolset is None: + _gmail_toolset = GoogleApiToolset.load_toolset( api_name="gmail", api_version="v1", ) - return _gmail_tool_set + return _gmail_toolset - case "youtube_tool_set": - if _youtube_tool_set is None: - _youtube_tool_set = GoogleApiToolset.load_toolset( + case "youtube_toolset": + if _youtube_toolset is None: + _youtube_toolset = GoogleApiToolset.load_toolset( api_name="youtube", api_version="v3", ) - return _youtube_tool_set + return _youtube_toolset - case "slides_tool_set": - if _slides_tool_set is None: - _slides_tool_set = GoogleApiToolset.load_toolset( + case "slides_toolset": + if _slides_toolset is None: + _slides_toolset = GoogleApiToolset.load_toolset( api_name="slides", api_version="v1", ) - return _slides_tool_set + return _slides_toolset - case "sheets_tool_set": - if _sheets_tool_set is None: - _sheets_tool_set = GoogleApiToolset.load_toolset( + case "sheets_toolset": + if _sheets_toolset is None: + _sheets_toolset = GoogleApiToolset.load_toolset( api_name="sheets", api_version="v4", ) - return _sheets_tool_set + return _sheets_toolset - case "docs_tool_set": - if _docs_tool_set is None: - _docs_tool_set = GoogleApiToolset.load_toolset( + case "docs_toolset": + if _docs_toolset is None: + _docs_toolset = GoogleApiToolset.load_toolset( api_name="docs", api_version="v1", ) - return _docs_tool_set + return _docs_toolset