$npx -y skills add VeerMuchandi/rad-skills --skill agent_engine_python_deployerDeploys ADK agents to Vertex AI Agent Engine using the Python SDK and registers them with Gemini Enterprise.
| 1 | # Agent Engine Python Deployer Skill |
| 2 | |
| 3 | This skill documents the Python SDK method for deploying ADK agents to Vertex AI Agent Engine (`client.agent_engines.create`) and registering them with Gemini Enterprise using the `DiscoveryEngine` HTTP API. This is an alternative to the Terraform-based deployment workflow. |
| 4 | |
| 5 | ## 1. Prerequisites |
| 6 | |
| 7 | - **Python 3.10+**: Active environment with dependencies. |
| 8 | - **Google Cloud Project**: With billing enabled. |
| 9 | - **Dependencies**: |
| 10 | ```text |
| 11 | google-cloud-aiplatform[agent_engines,adk] |
| 12 | a2a-sdk >= 0.3.4 |
| 13 | cloudpickle >= 3.1.2 |
| 14 | pydantic |
| 15 | python-dotenv |
| 16 | ``` |
| 17 | |
| 18 | ## 2. Configuration (`.env`) |
| 19 | |
| 20 | Ensure your environment variables are configured correctly: |
| 21 | |
| 22 | ```bash |
| 23 | # GCP Project Config |
| 24 | PROJECT_ID="your-project-id" |
| 25 | LOCATION="us-central1" |
| 26 | STORAGE_BUCKET="gs://your-staging-bucket" |
| 27 | |
| 28 | # Gemini Enterprise Config |
| 29 | GEMINI_ENTERPRISE_APP_ID="your-app-id" |
| 30 | |
| 31 | # Authorization Config (obtained from Discovery Engine authorizations API if needed) |
| 32 | AGENT_AUTHORIZATION="projects/PROJECT_NUMBER/locations/global/authorizations/AUTH_ID" |
| 33 | |
| 34 | # Logging & Telemetry flags |
| 35 | GOOGLE_CLOUD_AGENT_ENGINE_ENABLE_TELEMETRY=true |
| 36 | OTEL_INSTRUMENTATION_GENAI_CAPTURE_MESSAGE_CONTENT=true |
| 37 | ``` |
| 38 | |
| 39 | ## 3. Core Workflow |
| 40 | |
| 41 | The workflow involves using the Python SDK to deploy and then post-processing the endpoint for Gemini Enterprise. |
| 42 | |
| 43 | ### 2.B Create Authorization Resource (If Required) |
| 44 | |
| 45 | When deploying A2A agents (including A2UI and non-A2UI A2A agents on Agent Engine), you must create an `AGENT_AUTHORIZATION` resource in Gemini Enterprise. |
| 46 | |
| 47 | #### 2.B.1 Prerequisite: Create Web OAuth Client |
| 48 | |
| 49 | Before creating the authorization resource, you must create a Web OAuth Client in the Google Cloud Console for the project. |
| 50 | |
| 51 | 1. Navigate to **APIs & Services > Credentials** in the Cloud Console. |
| 52 | 2. Click **Create Credentials > OAuth client ID**. |
| 53 | 3. Select Application type: **Web application**. |
| 54 | 4. Add the following **Authorized redirect URIs**: |
| 55 | * `https://vertexaisearch.cloud.google.com/oauth-redirect` |
| 56 | * `https://vertexaisearch.cloud.google.com/static/oauth/oauth.html` |
| 57 | 5. Save the Client ID and Client Secret. |
| 58 | |
| 59 | #### 2.B.2 Construct authorizationUri |
| 60 | |
| 61 | Construct the `authorizationUri` using the Client ID and the encoded redirect URI: |
| 62 | |
| 63 | ```text |
| 64 | https://accounts.google.com/o/oauth2/v2/auth?client_id=<YOUR_CLIENT_ID>&redirect_uri=https%3A%2F%2Fvertexaisearch.cloud.google.com%2Fstatic%2Foauth%2Foauth.html&scope=https%3A%2F%2Fwww.googleapis.com%2Fauth%2Fcloud-platform&include_granted_scopes=true&response_type=code&access_type=offline&prompt=consent |
| 65 | ``` |
| 66 | |
| 67 | #### 2.B.3 Create Authorization Resource via cURL |
| 68 | |
| 69 | ```bash |
| 70 | curl -X POST \ |
| 71 | -H "Authorization: Bearer \$(gcloud auth application-default print-access-token)" \ |
| 72 | -H "Content-Type: application/json" \ |
| 73 | -H "X-Goog-User-Project: <PROJECT_ID>" \ |
| 74 | "https://global-discoveryengine.googleapis.com/v1alpha/projects/<PROJECT_ID>/locations/global/authorizations?authorizationId=<AUTH_ID>" \ |
| 75 | -d '{ |
| 76 | "name": "projects/<PROJECT_ID>/locations/global/authorizations/<AUTH_ID>", |
| 77 | "serverSideOauth2": { |
| 78 | "clientId": "<CLIENT_ID>", |
| 79 | "clientSecret": "<CLIENT_SECRET>", |
| 80 | "authorizationUri": "<AUTH_URI>", |
| 81 | "tokenUri": "<TOKEN_URI>" |
| 82 | } |
| 83 | }' |
| 84 | ``` |
| 85 | |
| 86 | Replace `<PROJECT_ID>`, `<AUTH_ID>`, `<CLIENT_ID>`, `<CLIENT_SECRET>`, `<AUTH_URI>`, and `<TOKEN_URI>`. |
| 87 | |
| 88 | ### 3.A Initialize Vertex AI |
| 89 | ```python |
| 90 | import os |
| 91 | import vertexai |
| 92 | from dotenv import load_dotenv |
| 93 | |
| 94 | load_dotenv() |
| 95 | |
| 96 | vertexai.init( |
| 97 | project=os.environ["PROJECT_ID"], |
| 98 | location=os.environ["LOCATION"], |
| 99 | staging_bucket=os.environ["STORAGE_BUCKET"], |
| 100 | ) |
| 101 | ``` |
| 102 | |
| 103 | ### B. Define `AgentSkill` and Create Card |
| 104 | ```python |
| 105 | from a2a.types import AgentSkill |
| 106 | from vertexai.preview.reasoning_engines.templates.a2a import create_agent_card |
| 107 | |
| 108 | agent_skill = AgentSkill( |
| 109 | id="contact_lookup", |
| 110 | name="Contact Lookup Agent", |
| 111 | description="A helpful assistant agent that can find contact card.", |
| 112 | tags=["Contact-Lookup"], |
| 113 | examples=["Find John Doe"], |
| 114 | ) |
| 115 | |
| 116 | agent_card = create_agent_card( |
| 117 | agent_name="Test Contact Card Agent", |
| 118 | description="A helpful assistant agent that can find contact card.", |
| 119 | skills=[agent_skill], |
| 120 | ) |
| 121 | ``` |
| 122 | |
| 123 | ### C. Instantiate A2aAgent with Custom Executor |
| 124 | Override the default executor to intercept the stream and parse A2UI payloads, or simply yield standard A2A messages for non-A2UI agents. |
| 125 | ```python |
| 126 | from vertexai.preview.reasoning_engines import A2aAgent |
| 127 | import agent_executor # Your custom executor file |
| 128 | |
| 129 | a2a_agent = A2aAgent( |
| 130 | agent_card=agent_card, |
| 131 | agent_executor_builder=agent_executor.AdkAgentToA2AExecutor, |
| 132 | ) |
| 133 | ``` |
| 134 | |
| 135 | ### D. Deploy New Instance with Extra Packages |
| 136 | Use `extra_packages` to bundle non-module dependencies (like external scripts or templates). |
| 137 | ```python |
| 138 | from google.genai import types |
| 139 | |
| 140 | client = vertexai.Client( |
| 141 | project=o |