* docs: add basic filtering for Integrations Card Catalog * update listing tags and experiment with filters * docs: add Integrations page filter buttons * move and update CSS per feedback * add JS safety improvements
4.3 KiB
catalog_title, catalog_description, catalog_icon, catalog_tags
| catalog_title | catalog_description | catalog_icon | catalog_tags | ||
|---|---|---|---|---|---|
| Apigee API Hub | Turn any documented API from Apigee API hub into a tool | /adk-docs/integrations/assets/apigee.png |
|
Apigee API Hub tool for ADK
ApiHubToolset lets you turn any documented API from Apigee API hub into a tool with a few lines of code. This section shows you the step-by-step instructions including setting up authentication for a secure connection to your APIs.
Prerequisites
- Install ADK
- Install the Google Cloud CLI.
- Apigee API hub instance with documented (i.e. OpenAPI spec) APIs
- Set up your project structure and create required files
project_root_folder
|
`-- my_agent
|-- .env
|-- __init__.py
|-- agent.py
`__ tool.py
Create an API Hub Toolset
Note: This tutorial includes an agent creation. If you already have an agent, you only need to follow a subset of these steps.
-
Get your access token, so that APIHubToolset can fetch spec from API Hub API. In your terminal run the following command
gcloud auth print-access-token # Prints your access token like 'ya29....' -
Ensure that the account used has the required permissions. You can use the pre-defined role
roles/apihub.vieweror assign the following permissions:- apihub.specs.get (required)
- apihub.apis.get (optional)
- apihub.apis.list (optional)
- apihub.versions.get (optional)
- apihub.versions.list (optional)
- apihub.specs.list (optional)
-
Create a tool with
APIHubToolset. Add the below totools.pyIf your API requires authentication, you must configure authentication for the tool. The following code sample demonstrates how to configure an API key. ADK supports token based auth (API Key, Bearer token), service account, and OpenID Connect. We will soon add support for various OAuth2 flows.
from google.adk.tools.openapi_tool.auth.auth_helpers import token_to_scheme_credential from google.adk.tools.apihub_tool.apihub_toolset import APIHubToolset # Provide authentication for your APIs. Not required if your APIs don't required authentication. auth_scheme, auth_credential = token_to_scheme_credential( "apikey", "query", "apikey", apikey_credential_str ) sample_toolset = APIHubToolset( name="apihub-sample-tool", description="Sample Tool", access_token="...", # Copy your access token generated in step 1 apihub_resource_name="...", # API Hub resource name auth_scheme=auth_scheme, auth_credential=auth_credential, )For production deployment we recommend using a service account instead of an access token. In the code snippet above, use
service_account_json=service_account_cred_json_strand provide your security account credentials instead of the token.For apihub_resource_name, if you know the specific ID of the OpenAPI Spec being used for your API, use
`projects/my-project-id/locations/us-west1/apis/my-api-id/versions/version-id/specs/spec-id`. If you would like the Toolset to automatically pull the first available spec from the API, use`projects/my-project-id/locations/us-west1/apis/my-api-id` -
Create your agent file Agent.py and add the created tools to your agent definition:
from google.adk.agents.llm_agent import LlmAgent from .tools import sample_toolset root_agent = LlmAgent( model='gemini-2.0-flash', name='enterprise_assistant', instruction='Help user, leverage the tools you have access to', tools=sample_toolset.get_tools(), ) -
Configure your
__init__.pyto expose your agentfrom . import agent -
Start the Google ADK Web UI and try your agent:
# make sure to run `adk web` from your project_root_folder adk webThen go to http://localhost:8000 to try your agent from the Web UI.