$npx -y skills add VeerMuchandi/rad-skills --skill adk_ge_datastore_connectorSkill for connecting ADK agents to Gemini Enterprise connected data sources with secure user-level access control.
| 1 | # Instructions |
| 2 | |
| 3 | This skill provides guidelines and patterns for connecting ADK agents to Gemini Enterprise connected data sources. The primary focus is on secure user-level access control (ACLs) by propagating the user's OAuth token. |
| 4 | |
| 5 | ## Core Concepts |
| 6 | |
| 7 | ### 1. User Identity Propagation |
| 8 | When searching an enterprise datastore (e.g., Google Drive, Jira), the agent must respect the calling user's permissions. This is achieved by passing the user's OAuth token directly to the Datastore API (Discovery Engine API). |
| 9 | |
| 10 | ### 2. Token Retrieval |
| 11 | In the Gemini Enterprise runtime, the user's access token is injected into the agent's session state. |
| 12 | Retrieve the token from the `ToolContext` using the key defined by the environment variable `AUTH_NAME`: |
| 13 | |
| 14 | ```python |
| 15 | from google.adk.tools import ToolContext |
| 16 | |
| 17 | def my_tool(query: str, tool_context: ToolContext): |
| 18 | auth_name = os.getenv("AUTH_NAME") |
| 19 | access_token = tool_context.state.get(auth_name) |
| 20 | # Use access_token in API calls |
| 21 | ``` |
| 22 | |
| 23 | ### 3. Local Development Fallback |
| 24 | For local testing where the Gemini Enterprise runtime is not available, fall back to **Application Default Credentials (ADC)**. |
| 25 | |
| 26 | ```python |
| 27 | from google.auth import default |
| 28 | from google.auth import transport |
| 29 | |
| 30 | if access_token: |
| 31 | # Use retrieved token |
| 32 | else: |
| 33 | # Fallback to ADC |
| 34 | creds, project_id = default() |
| 35 | auth_req = transport.requests.Request() |
| 36 | creds.refresh(auth_req) |
| 37 | access_token = creds.token |
| 38 | ``` |
| 39 | |
| 40 | ## Implementation Patterns |
| 41 | |
| 42 | ### Generic Datastore Client |
| 43 | Use a generic client to handle API communication. Do not hardcode specific datastore IDs or project IDs; use environment variables. |
| 44 | |
| 45 | See [examples/tools_template.py](./examples/tools_template.py) for a reusable template. |
| 46 | |
| 47 | ### Agent Integration |
| 48 | Focus this skill on *integrating* the datastore tool. Use the `ADK Developer` skill for general agent building and orchestration. |
| 49 | |
| 50 | See [examples/agent_usage.py](./examples/agent_usage.py) for a minimal usage example. |
| 51 | |
| 52 | ## Design Considerations |
| 53 | |
| 54 | ### Documenting Testing Differences |
| 55 | When designing an agent that uses this skill, the architect **MUST** include a section in the architecture document detailing the differences between local testing and testing on Gemini Enterprise. This is crucial because the authentication mechanisms differ significantly (ADC vs. Session-injected OAuth tokens), affecting how user permissions (ACLs) are enforced. |
| 56 | |
| 57 | Include a table or summary similar to the following in the design: |
| 58 | |
| 59 | | Feature | Local Testing | Gemini Enterprise | |
| 60 | | :--- | :--- | :--- | |
| 61 | | **Auth Method** | Application Default Credentials (ADC) | User OAuth Token (Session Injected) | |
| 62 | | **Identity Used** | Developer's identity | Calling End-User's identity | |
| 63 | | **ACL Enforcement** | Based on Developer's access | Based on End-User's access | |
| 64 | |
| 65 | ### Environment Variables Fallbacks |
| 66 | When retrieving configuration like `PROJECT_ID` and `LOCATION` in your tools, use fallbacks to support both local development and Agent Engine runtime: |
| 67 | ```python |
| 68 | project_id = os.getenv("PROJECT_ID") or os.getenv("GOOGLE_CLOUD_PROJECT") |
| 69 | location = os.getenv("LOCATION") or os.getenv("GOOGLE_CLOUD_LOCATION") |
| 70 | ``` |
| 71 | Note that `GOOGLE_CLOUD_PROJECT` is reserved in Agent Engine and cannot be set manually in the environment variables block of the deployment config. |
| 72 | |
| 73 | ### Prompt Engineering for Search |
| 74 | When instructing the agent to use the datastore search tool, ensure it handles relative or temporal queries (like 'last', 'latest', 'recent') gracefully. Keyword search engines might not understand these terms directly. Instruct the agent to: |
| 75 | 1. Try searching with a broad query or keywords related to the topic instead of refusing to answer immediately. |
| 76 | 2. Analyze the results to identify the most relevant or recent documents if date information is available. |
| 77 | 3. Avoid early refusal when specific keywords are not provided. |
| 78 | |
| 79 | ## Deployment Considerations |
| 80 | |
| 81 | ### Terraform Deployment (Preferred) |
| 82 | For production deployments, it is recommended to use the generalized Terraform approach documented in the `Agent Engine Terraform Deployer` skill. This ensures reproducible deployments and proper management of infrastructure state. |
| 83 | |
| 84 | ### Gemini Enterprise Registration |
| 85 | Use the `Gemini Enterprise Agent Registrar` skill to perform the registration and handle OAuth setup. When constructing the registration payload, ensure that: |
| 86 | 1. An Authorization Resource is created for the OAuth flow to propagate the user's token. |
| 87 | 2. The `authorizationConfig` in the registration payload uses the numeric `PROJECT_NUMBER` instead of the `PROJECT_ID`. |
| 88 | 3. Verify if the data source requires additional OAuth scopes beyond `cloud-platform` (e.g., for real-time federation to third-party systems like Jira or Workspace apps like Google Drive). |