|
| 1 | +# GCS Tools Sample |
| 2 | + |
| 3 | +## Introduction |
| 4 | + |
| 5 | +This sample agent demonstrates the Google Cloud Storage (GCS) first-party tools in ADK, |
| 6 | +distributed via the `google.adk.integrations.gcs` module. These tools include: |
| 7 | + |
| 8 | +1. `gcs_get_bucket` |
| 9 | + |
| 10 | +Get metadata information about a GCS bucket. |
| 11 | + |
| 12 | +1. `gcs_list_objects` |
| 13 | + |
| 14 | +List object names in a GCS bucket. |
| 15 | + |
| 16 | +1. `gcs_get_object_metadata` |
| 17 | + |
| 18 | +Get metadata information about a GCS object (blob). |
| 19 | + |
| 20 | +## How to use |
| 21 | + |
| 22 | +Set up environment variables in your `.env` file for using |
| 23 | +[Google AI Studio](https://google.github.io/adk-docs/get-started/quickstart/#gemini---google-ai-studio) |
| 24 | +or |
| 25 | +[Google Cloud Vertex AI](https://google.github.io/adk-docs/get-started/quickstart/#gemini---google-cloud-vertex-ai) |
| 26 | +for the LLM service for your agent. For example, for using Google AI Studio you |
| 27 | +would set: |
| 28 | + |
| 29 | +- GOOGLE_GENAI_USE_ENTERPRISE=FALSE |
| 30 | +- GOOGLE_API_KEY={your api key} |
| 31 | + |
| 32 | +### With Application Default Credentials (gcloud) |
| 33 | + |
| 34 | +This is the easiest way to use your own Google Cloud identity for both the tools AND the LLM. |
| 35 | + |
| 36 | +1. Install the [Google Cloud CLI](https://cloud.google.com/sdk/docs/install). |
| 37 | +1. Run `gcloud auth application-default login` in your terminal. |
| 38 | +1. Configure your environment to use Vertex AI (which supports ADC) instead of AI Studio: |
| 39 | + - `export GOOGLE_GENAI_USE_ENTERPRISE=TRUE` |
| 40 | + - `export GOOGLE_CLOUD_PROJECT={your-project-id}` |
| 41 | +1. Ensure the Vertex AI API is enabled and you have the correct permissions: |
| 42 | + - Enable API: `gcloud services enable aiplatform.googleapis.com` |
| 43 | + - Grant Role: `gcloud projects add-iam-policy-binding {your-project-id} --member="user:{your-email}" --role="roles/aiplatform.user"` |
| 44 | +1. Set `CREDENTIALS_TYPE = None` in `agent.py`. |
| 45 | +1. Run the agent. |
| 46 | + |
| 47 | +### With Service Account Keys |
| 48 | + |
| 49 | +This mode is useful for quick development when the agent builder wants to run |
| 50 | +the agent with service account credentials. The tools are run with these |
| 51 | +credentials. |
| 52 | + |
| 53 | +1. Create service account key by following https://cloud.google.com/iam/docs/service-account-creds#user-managed-keys. |
| 54 | + |
| 55 | +1. Set `CREDENTIALS_TYPE=AuthCredentialTypes.SERVICE_ACCOUNT` in `agent.py` |
| 56 | + |
| 57 | +1. Download the key file and replace `"service_account_key.json"` with the path |
| 58 | + |
| 59 | +1. Run the agent |
| 60 | + |
| 61 | +### With Interactive OAuth |
| 62 | + |
| 63 | +1. Follow |
| 64 | + https://developers.google.com/identity/protocols/oauth2#1.-obtain-oauth-2.0-credentials-from-the-dynamic_data.setvar.console_name. |
| 65 | + to get your client id and client secret. Be sure to choose "web" as your client |
| 66 | + type. |
| 67 | + |
| 68 | +1. Follow https://developers.google.com/workspace/guides/configure-oauth-consent |
| 69 | + to add scope "https://www.googleapis.com/auth/cloud-platform" and |
| 70 | + "https://www.googleapis.com/auth/devstorage.full_control" as a declaration, this is used |
| 71 | + for review purpose. |
| 72 | + |
| 73 | +1. Follow |
| 74 | + https://developers.google.com/identity/protocols/oauth2/web-server#creatingcred |
| 75 | + to add http://localhost/dev-ui/ to "Authorized redirect URIs". |
| 76 | + |
| 77 | + Note: localhost here is just a hostname that you use to access the dev ui, |
| 78 | + replace it with the actual hostname you use to access the dev ui. |
| 79 | + |
| 80 | +1. For 1st run, allow popup for localhost in Chrome. |
| 81 | + |
| 82 | +1. Configure your `.env` file to add two more variables before running the |
| 83 | + agent: |
| 84 | + |
| 85 | + - OAUTH_CLIENT_ID={your client id} |
| 86 | + - OAUTH_CLIENT_SECRET={your client secret} |
| 87 | + |
| 88 | + Note: don't create a separate .env, instead put it to the same .env file that |
| 89 | + stores your Vertex AI or Dev ML credentials |
| 90 | + |
| 91 | +1. Set `CREDENTIALS_TYPE=AuthCredentialTypes.OAUTH2` in `agent.py` and run the |
| 92 | + agent |
| 93 | + |
| 94 | +## Sample prompts |
| 95 | + |
| 96 | +- Show me metadata for the my-bucket bucket. |
| 97 | +- List all objects in the my-bucket bucket. |
| 98 | +- Get metadata for the my-object.txt object in my-bucket. |
| 99 | +- Download the GCS object my-object.txt in my-bucket to a local file ~/Downloads/downloaded.txt. |
| 100 | +- Upload my local file /tmp/local_report.pdf to my-bucket as report.pdf. |
0 commit comments