|
| 1 | +# Bigtable Tools Sample |
| 2 | + |
| 3 | +## Introduction |
| 4 | + |
| 5 | +This sample agent demonstrates the Bigtable first-party tools in ADK, |
| 6 | +distributed via the `google.adk.tools.bigtable` module. These tools include: |
| 7 | + |
| 8 | +1. `bigtable_list_instances` |
| 9 | + |
| 10 | + Fetches Bigtable instance ids in a Google Cloud project. |
| 11 | + |
| 12 | +1. `bigtable_get_instance_info` |
| 13 | + |
| 14 | + Fetches metadata information about a Bigtable instance. |
| 15 | + |
| 16 | +1. `bigtable_list_tables` |
| 17 | + |
| 18 | + Fetches table ids in a Bigtable instance. |
| 19 | + |
| 20 | +1. `bigtable_get_table_info` |
| 21 | + |
| 22 | + Fetches metadata information about a Bigtable table. |
| 23 | + |
| 24 | +1. `bigtable_execute_sql` |
| 25 | + |
| 26 | + Runs a DQL SQL query in Bigtable database. |
| 27 | + |
| 28 | +## How to use |
| 29 | + |
| 30 | +Set up environment variables in your `.env` file for using |
| 31 | +[Google AI Studio](https://google.github.io/adk-docs/get-started/quickstart/#gemini---google-ai-studio) |
| 32 | +or |
| 33 | +[Google Cloud Vertex AI](https://google.github.io/adk-docs/get-started/quickstart/#gemini---google-cloud-vertex-ai) |
| 34 | +for the LLM service for your agent. For example, for using Google AI Studio you |
| 35 | +would set: |
| 36 | + |
| 37 | +* GOOGLE_GENAI_USE_VERTEXAI=FALSE |
| 38 | +* GOOGLE_API_KEY={your api key} |
| 39 | + |
| 40 | +### With Application Default Credentials |
| 41 | + |
| 42 | +This mode is useful for quick development when the agent builder is the only |
| 43 | +user interacting with the agent. The tools are run with these credentials. |
| 44 | + |
| 45 | +1. Create application default credentials on the machine where the agent would |
| 46 | +be running by following https://cloud.google.com/docs/authentication/provide-credentials-adc. |
| 47 | + |
| 48 | +1. Set `CREDENTIALS_TYPE=None` in `agent.py` |
| 49 | + |
| 50 | +1. Run the agent |
| 51 | + |
| 52 | +### With Service Account Keys |
| 53 | + |
| 54 | +This mode is useful for quick development when the agent builder wants to run |
| 55 | +the agent with service account credentials. The tools are run with these |
| 56 | +credentials. |
| 57 | + |
| 58 | +1. Create service account key by following https://cloud.google.com/iam/docs/service-account-creds#user-managed-keys. |
| 59 | + |
| 60 | +1. Set `CREDENTIALS_TYPE=AuthCredentialTypes.SERVICE_ACCOUNT` in `agent.py` |
| 61 | + |
| 62 | +1. Download the key file and replace `"service_account_key.json"` with the path |
| 63 | + |
| 64 | +1. Run the agent |
| 65 | + |
| 66 | +### With Interactive OAuth |
| 67 | + |
| 68 | +1. Follow |
| 69 | +https://developers.google.com/identity/protocols/oauth2#1.-obtain-oauth-2.0-credentials-from-the-dynamic_data.setvar.console_name. |
| 70 | +to get your client id and client secret. Be sure to choose "web" as your client |
| 71 | +type. |
| 72 | + |
| 73 | +1. Follow https://developers.google.com/workspace/guides/configure-oauth-consent |
| 74 | + to add scope "https://www.googleapis.com/auth/bigtable.admin" and |
| 75 | + "https://www.googleapis.com/auth/bigtable.data" as declaration, this is used |
| 76 | + for review purpose. |
| 77 | + |
| 78 | +1. Follow |
| 79 | + https://developers.google.com/identity/protocols/oauth2/web-server#creatingcred |
| 80 | + to add http://localhost/dev-ui/ to "Authorized redirect URIs". |
| 81 | + |
| 82 | + Note: localhost here is just a hostname that you use to access the dev ui, |
| 83 | + replace it with the actual hostname you use to access the dev ui. |
| 84 | + |
| 85 | +1. For 1st run, allow popup for localhost in Chrome. |
| 86 | + |
| 87 | +1. Configure your `.env` file to add two more variables before running the |
| 88 | + agent: |
| 89 | + |
| 90 | + * OAUTH_CLIENT_ID={your client id} |
| 91 | + * OAUTH_CLIENT_SECRET={your client secret} |
| 92 | + |
| 93 | + Note: don't create a separate .env, instead put it to the same .env file that |
| 94 | + stores your Vertex AI or Dev ML credentials |
| 95 | + |
| 96 | +1. Set `CREDENTIALS_TYPE=AuthCredentialTypes.OAUTH2` in `agent.py` and run the |
| 97 | + agent |
| 98 | + |
| 99 | +## Sample prompts |
| 100 | + |
| 101 | +* Show me all instances in the my-project. |
| 102 | +* Show me all tables in the my-instance instance in my-project. |
| 103 | +* Describe the schema of the my-table table in the my-instance instance in my-project. |
| 104 | +* Show me the first 10 rows of data from the my-table table in the my-instance instance in my-project. |
0 commit comments