1
---
2
name: agent-platform-deploy
3
metadata:
4
version: "1.0.6"
5
category: AiAndMachineLearning
6
description: >-
7
Deploy open models or custom weights from Model Garden to Agent Platform
8
endpoints, check the status of an in-progress deployment operation, or clean
9
up resources by undeploying models and deleting endpoints. Use when asked to
10
actively deploy a model, list the Model Garden CATALOG of available models,
11
check if a specific model is deployable
12
(`gcloud ai model-garden models list-deployment-config`), query deployment
13
cost, troubleshoot deployment errors (like quota limits), or undeploy/clean
14
up endpoints. Also use when copying and deploying a 1P Tuned Model. Don't
15
use for pure listing/discovery questions of the form "is X deployed?",
16
"list my endpoints", or "which regions have models running?" — for those
17
use `agent-platform-endpoint-management`. Don't use for running model evaluations
18
(use `agent-platform-eval-flywheel` skill).
19
---
20
21
# Agent Platform Model Garden Deploy Skill
22
23
This skill provides instructions for deploying Open Models from Agent Platform
24
Model Garden to endpoints, and subsequently undeploying them to clean up
25
resources.
26
27
## Attribution
28
29
**MUST READ**: Before executing any `gcloud`, REST API, or MCP command, you MUST
30
read [Usage Attribution](references/attribution.md). For commands executed
31
directly in the terminal (never in generated scripts, Terraform, or user code),
32
prefix `gcloud` with `CLOUDSDK_METRICS_REQUEST_ATTRIBUTION` and append the
33
attribution suffix to `User-Agent` headers:
34
35
```text
36
CLOUDSDK_METRICS_REQUEST_ATTRIBUTION="agent-skills/1.0 (skill:agent-platform-deploy)"
37
User-Agent: <existing_user_agent> agent-skills/1.0 (skill:agent-platform-deploy)
38
```
39
40
## 1P Tuned Model Copy & Deployment
41
42
If you need to copy a **1P (First-Party) Tuned Model** from a source project to
43
a destination region or project and deploy it to a newly created endpoint, refer
44
to the
45
[1P Tuned Model Copy & Deployment Guide](references/copy_deploy_guide.md).
46
47
## Safety & Confirmation Tiers (CRITICAL)
48
49
Before executing any commands on behalf of the user, you MUST adhere to the
50
following safety tiers based on the action requested:
51
52
1. **Tier R: Read-only (`list`, `describe`, `list-deployment-config`)**
53
* **Rule**: No confirmation needed. You may execute these commands
54
immediately to gather information for the user.
55
2. **Tier M: Mutating & Reversible (`deploy`, `undeploy-model`)**
56
* **Rule**: This requires explicit user confirmation. You MUST present a
57
clear dry-run confirmation card containing:
58
59
1. Exact proposed `gcloud` command code block (`gcloud ai model-garden
60
models deploy ... --asynchronous`).
61
2. Model identifier, destination project ID, and target region.
62
3. Machine type and accelerator configuration.
63
4. Estimated hourly cost ($/hr).
64
5. Endpoint display name.
65
6. Explicit confirmation prompt asking the user to approve before
66
execution.
67
You MUST wait for their explicit confirmation before executing. For
68
`undeploy-model`, you MUST first verify that the endpoint and deployed
69
model exist; if `describe` or `list` returns a 404 or empty result, you
70
MUST halt and inform the user rather than attempting undeployment.
71
* **Same-turn restriction**: Do not run the command in the same turn as
72
presenting the confirmation prompt. End your turn after asking and wait
73
for the user's reply; only execute after explicit approval. Printing a
74
preview and then calling the tool before the user can answer does not
75
count as obtaining confirmation.
76
3. **Tier D: Destructive & Irreversible (`delete`)**
77
* **Rule**: This requires **explicit typed confirmation**. You MUST output
78
a text message explaining the irreversible nature of endpoint or model
79
deletion and asking the user to type "I confirm" or "Yes, delete it"
80
before executing the deletion command.
81
82
> [!IMPORTANT]
83
>
84
> **Always Output Complete Text Response (NEVER Emit Empty Text)**: After
85
> executing any tool call (such as `gcloud ai model-garden models deploy`,
86
> `gcloud ai endpoints delete`, `gcloud ai endpoints list`, or status checks),
87
> you MUST formulate and return a complete, informative textual response to the
88
> user. Explicitly report the operation name, endpoint name/ID, error message,
89
> or list of resources. **NEVER finish a turn with empty text or silence**.
90
91
## 1. Prerequisites
92
93
Before deploying, ensure you have the correct project and region set. The
94
commands below use placeholder variables `PROJECT_ID` and `LOCATION_ID`.
95
96
Ensure you are authenticated:
97
98
```bash
99
gcloud auth login
100
gcloud auth application-default login
101
gcloud config set project $PROJECT_ID
102
```
103
104
## 2. Discovering Deployable Models
105
106
You can list models available in Model Garden and check if they can be
107
self-deployed.
108
109
```bash
110
gcloud ai model-garden models list
111
```
112
113
To see what machine types and accelerators are supported for a specific model,
114
pass a `MODEL_ID` you obtained from the `models list` output above. Substitute
115
`<PUBLISHER>/<FAMILY>@<VERSION-ID>` below with the exact string from the catalog
116
output — the placeholder is deliberately not a real model ID:
117
118
```bash
119
gcloud ai model-garden models list-deployment-config \
120
--model="<PUBLISHER>/<FAMILY>@<VERSION-ID>"
121
```
122
123
> [!NOTE] Some models, especially Hugging Face models, might require a Hugging
124
> Face Access Token for deployment.
125
126
> [!TIP] **Model Recommendation Instructions:** Whenever you are about to name a
127
> specific model version in a response, do NOT recommend from memory. This
128
> applies in all of the following situations — not just direct deploy requests:
129
>
130
> * The user asks to deploy a model without naming one.
131
> * You are volunteering a next-step suggestion after a `list`, `describe`, or
132
> `undeploy` operation (e.g. "Would you like me to deploy `<model>` to this
133
> endpoint?").
134
> * The user asks a general "what should I use?" / "what's a good model for
135
> X?" question.
136
> * You are filling in a `MODEL_ID` value in an example command you are
137
> showing the user (as opposed to a placeholder like
138
> `<PUBLISHER>/<FAMILY>@<VERSION-ID>`).
139
>
140
> New model versions ship frequently and older ones may be deprecated, so
141
> training-corpus knowledge of which models exist is unreliable. Follow this
142
> procedure:
143
>
144
> 1. **Clarify the use case** if it isn't already clear from context (task
145
> type, quality vs. latency vs. cost priorities, hardware/quota constraints,
146
> license constraints). Skip if the user has already given enough signal.
147
> 2. **Query the live catalog** with `gcloud ai model-garden models list`.
148
> Narrow with `--filter` when appropriate (e.g. `--filter="name~gemma"`,
149
> `--filter="name~llama"`, `--filter="name~qwen"`,
150
> `--filter="name~deepseek"`). Never name a specific model version to the
151
> user until you have seen it in the catalog output for this project.
152
> 3. **Pick the latest generally-available version** in the family that fits
153
> the use case. When multiple size variants exist, pick the one that matches
154
> the user's hardware/cost tolerance. Prefer a newer major version over an
155
> older one unless it is marked preview/experimental and the user explicitly
156
> asked for a stable option.
157
> 4. **Verify the exact model ID is deployable** with `gcloud ai model-garden
158
> models list-deployment-config --model="<publisher>/<family>@<version>"`
159
> before naming it in your response.
160
> 5. **Cite the model ID verbatim** in your recommendation, exactly as it
161
> appears in the catalog. Do not paraphrase to a family label ("Gemma",
162
> "Llama").
163
>
164
> The `MODEL_ID` values in the §3 examples below are intentionally
165
> non-substantive placeholders (`<PUBLISHER>/<FAMILY>@<VERSION-ID>`). Do NOT
166
> replace them with a remembered model name for a user-facing recommendation —
167
> always re-run steps 2-4 first, then cite the exact string from the catalog.
168
169
## 2.1 Region Availability Check (Gemini + LoRA only)
170
171
> **Retired model guard**: Legacy `gemini-2.5-*` models (such as
172
> `gemini-2.5-flash`, `gemini-2.5-pro`, and `gemini-2.5-flash-lite`) are
173
> retired. Never probe or recommend them; inform the user that the requested
174
> `gemini-2.5-*` model is retired and suggest active supported models such as
175
> `gemini-3.8-flash` or `gemini-3.5-flash-lite`.
176
>
177
> For active first-party Gemini or LoRA deploys, you must verify region
178
> availability before proceeding. Load the full instructions with
179
> `load_skill_resource(skill_name='agent-platform-deploy',
180
> file_path='references/region_availability.md')`.
181
>
182
> **Skip this** for open-weights models (Gemma, Llama, DeepSeek, Qwen) and for
183
> Gemini-tuned models — they have no per-region publisher endpoint restriction.
184
> Go straight to §3.
185
186
## 3. Deploying a Model
187
188
> [!WARNING] Deploying models, especially large ones, consumes significant
189
> compute resources and incurs costs.
190
>
191
> 1. You **MUST** compute an hourly $ estimate for the requested
192
> `--machine-type` before proposing a deploy. Try each source below in
193
> order, falling through to the next on any failure:
194
>
195
> - Run `scripts/calculate_cost.py`. The accelerator type and count are
196
> fixed per machine type in Model Garden and derived automatically.
197
> Example:
198
>
199
> ```bash
200
> python3 scripts/calculate_cost.py \
201
> --machine-type=g2-standard-48
202
> ```
203
>
204
> If the script exits non-zero (unknown `--machine-type` — a routine
205
> state for machines in the Model Garden catalog but not yet in the
206
> price snapshot, e.g. A4/B200 today), fall through to the next source.
207
> Do NOT invent a number.
208
>
209
> - Fall back to
210
> [Agent Platform prediction pricing](https://cloud.google.com/products/gemini-enterprise-agent-platform/pricing?hl=en#prediction-and-explanation)
211
> if no source above produced a
212
> number. Read the accelerator + hourly rate directly off that page and
213
> cite the URL in the estimate you present to the user.
214
>
215
> 2. You **MUST** present this cost estimation to the user and warn them that
216
> this is the **list price**, which may differ from their actual bill due to
217
> potential discounts, reservations, or non-`us-central1` regions.
218
> 3. You **MUST ALWAYS** request explicit confirmation from the user agreeing
219
> to the estimated cost before executing any `deploy` command.
220
221
To deploy a model, use the `deploy` command. It is highly recommended to use the
222
`--asynchronous` flag for long-running deployments, and then poll the status if
223
necessary.
224
225
> [!IMPORTANT]
226
>
227
> - **Cost Pushback & Hardware Renegotiation**: If the user pushes back on
228
> cost (e.g., "That is too expensive, can you try a smaller
229
> configuration?"), or requests an invalid or unsupported hardware
230
> combination (e.g. `g2-standard-48g` with 4x H100 GPUs), explain the
231
> constraint or invalidity clearly, check `list-deployment-config` to
232
> identify the supported alternative (e.g., `g2-standard-24` with 2x L4 or
233
> `g2-standard-12` with 1x L4), compute its cost estimate with a single
234
> query, and **immediately render a complete Tier M dry-run confirmation
235
> card** for that recommended configuration in the same response.
236
> - **Region Failover & Quota Exhaustion**: When a deployment fails due to
237
> quota or capacity in the requested region (e.g. `QUOTA_EXCEEDED` or
238
> `RESOURCE_EXHAUSTED`), identify an alternative supported region (e.g.
239
> `us-east4` or `us-east1`), compute its cost estimate with a single query,
240
> and **immediately render a complete Tier M dry-run confirmation card with
241
> the new `--region` and exact command in the same response**. State the
242
> alternative region directly without making unverified capacity claims.
243
> - **Efficient Tool Execution (No Redundant Calls)**: Do NOT execute
244
> redundant `models list`, `list-deployment-config`, or `--help` commands if
245
> the model ID, region, or hardware configuration are already known or
246
> resolved. Run each discovery command strictly once.
247
> - **Single Status Check & Response Formatting (CRITICAL)**:
248
> - When initiating an asynchronous deployment (`gcloud ai model-garden
249
> models deploy ... --asynchronous`), the command output immediately
250
> returns the operation name. **Formulate and return your textual
251
> confirmation response with the operation name and endpoint display
252
> name immediately**. Do NOT call `operations describe` in the same turn
253
> as deployment initiation.
254
> - When the user explicitly asks to check deployment status (e.g.,
255
> "Please check to see the status of the deployment" or "Can you check
256
> if the deployment has finished?"):
257
> - **NEVER run `sleep` commands, `while` loops, or repeated polling
258
> calls**.
259
> - Execute `gcloud ai operations describe <OPERATION_NAME>`, the full
260
> operation name the deploy command printed, **strictly ONCE**.
261
> - **ALWAYS output a full textual response** reporting the operation
262
> status (e.g. "The deployment operation
263
> `projects/.../operations/...` is currently in progress / running
264
> (created at `...`). Asynchronous model deployment typically takes
265
> 10–15 minutes to complete").
266
> - Only proceed with sending a test prediction if the status check
267
> confirms the endpoint is already serving and ready.
268
> - **Alphanumeric Project ID**: Always specify the alphanumeric Project ID
269
> (e.g. `my-gcp-project`) for `--project`, NOT the numeric project number
270
> (e.g. `123456789012`). If given a numeric project number and its Project
271
> ID is not available, pass the number inside a fully-qualified resource
272
> name, e.g. `gcloud ai endpoints list
273
> --region=projects/123456789012/locations/us-central1`, or as a positional
274
> resource, `gcloud ai endpoints describe
275
> projects/123456789012/locations/us-central1/endpoints/<ENDPOINT_ID>
276
> --region=us-central1`. If `gcloud ai` still refuses because `core/project`
277
> is set to a project number, ask the user for the Project ID rather than
278
> retrying.
279
> - **Valid User-Specified Hardware Priority**: When the user specifies an
280
> explicit, valid hardware configuration (e.g. `g2-standard-96` with 8
281
> `NVIDIA_L4` GPUs, or `g2-standard-12` with 1 `NVIDIA_L4` GPU), honor that
282
> requested configuration for the dry-run preview and cost estimation rather
283
> than overriding it with default recommendations. However, if the requested
284
> configuration is **invalid or unsupported** (e.g. mismatched GPU count
285
> such as `g2-standard-12` with 2 L4 GPUs, or non-existent machine shapes),
286
> follow the **Cost Pushback & Hardware Renegotiation** rule above: explain
287
> the invalidity clearly, identify the supported alternative (e.g.
288
> `g2-standard-24` with 2 L4 GPUs), calculate its cost, and immediately
289
> present the confirmation card for the valid alternative.
290
> - **Endpoint Display Name**: If the user specifies or requests an endpoint
291
> name or display name (e.g. `'usersim-gemma-eval-...'`), you MUST always
292
> include `--endpoint-display-name="<NAME>"` in the `deploy` command.
293
294
### Example: Deploying an open-weights model from Model Garden
295
296
Here is a typical bash script to deploy a model. You can run this block
297
directly.
298
299
```bash
300
#!/bin/bash
301
# Example script to deploy an open-weights model from Model Garden.
302
#
303
# NOTE: MODEL_ID below is a PLACEHOLDER, not a real model ID. Substitute it
304
# with a value from a live `gcloud ai model-garden models list` (see §2)
305
# before running this script, and do NOT quote the placeholder back to the
306
# user as a recommended model.
307
#
308
# IMPORTANT FOR deploy_config["command"]: when building the curl command for
309
# the deploy confirmation card, inline ALL values as literals — do NOT leave
310
# ${PROJECT_ID}, ${LOCATION_ID}, or ${PUBLISHER_MODEL} as shell variables.
311
# The server rejects commands with unresolved variables at render time.
312
# The only allowed substitution is $(gcloud auth print-access-token).
313
314
PROJECT_ID=$(gcloud config get-value project)
315
# `gcloud ai` needs the alphanumeric Project ID, not the project number.
316
: "${PROJECT_ID:?no project ID is set; ask the user for the Project ID}"
317
LOCATION_ID="us-central1" # Recommended default region
318
# Replace placeholder with exact ID from `gcloud ai model-garden models list`:
319
MODEL_ID="<PUBLISHER>/<FAMILY>@<VERSION-ID>"
320
321
echo "Deploying model $MODEL_ID to project $PROJECT_ID in $LOCATION_ID..."
322
323
# Hardware params can be omitted to select recommended default config.
324
# Comprehensive command with supported parameters:
325
gcloud ai model-garden models deploy \
326
--project=$PROJECT_ID \
327
--region=$LOCATION_ID \
328
--model=$MODEL_ID \
329
--machine-type="g2-standard-12" \
330
--accelerator-type="NVIDIA_L4" \
331
--accelerator-count=1 \
332
--endpoint-display-name="my-open-model-deployment" \
333
--asynchronous
334
335
echo "Deployment initiated asynchronously."
336
```
337
338
With `--asynchronous` the command prints the full operation name,
339
`projects/<PROJECT>/locations/<REGION>/operations/<OP_ID>`. Pass that to §4: a
340
bare `<OP_ID>` works only when gcloud has a project.
341
342
- Include `--hugging-face-access-token="<HF_TOKEN>"` when deploying gated
343
Hugging Face models that require authentication.
344
- Include `--reservation-affinity` (e.g. `none` or
345
`reservation-affinity-type=specific-reservation,...`) if using reserved
346
compute.
347
348
### 1P Tuned Model Cross-Region Copy and Deployment
349
350
> For the detailed tuned model copy and deployment workflow, load
351
> `load_skill_resource(skill_name='agent-platform-deploy',
352
> file_path='references/copy_deploy_guide.md')`. That guide covers the execution
353
> sequence, tier assignments for copy/deploy/delete commands, hardware
354
> renegotiation, test prediction verification, and the in-progress operation
355
> lock.
356
357
## 4. Checking Deployment Status
358
359
When you deploy a model asynchronously using the `--asynchronous` flag, the
360
`deploy` command returns an operation name. Pass the full name to check the
361
ongoing status of the deployment.
362
363
```bash
364
gcloud ai operations describe YOUR_OPERATION_NAME
365
```
366
367
> [!IMPORTANT]
368
>
369
> **Single Status Check Only (No Sleep / Polling Loops)**: Model deployment
370
> operations take 10–30 minutes. NEVER run `sleep` commands (e.g. `sleep 45 &&
371
> ...`) or loop `operations describe` repeatedly in a turn. Run `gcloud ai
372
> operations describe` **strictly ONCE**. If `done` is not true, immediately
373
> return the operation name and in-progress status to the user and explain that
374
> deployment takes 10–15 minutes.
375
376
Note: Large models (roughly 20B+ parameters) may take 15-20 minutes to fully
377
deploy and start serving.
378
379
### Verifying Deployment
380
381
If the model is successfully deployed, verify by making a prediction call to
382
test. Because Model Garden models are often deployed to Dedicated Endpoints, you
383
shouldn't use `gcloud ai endpoints predict`. Instead, you must fetch the
384
endpoint's dedicated DNS name and send a `curl` request.
385
386
> [!TIP] Ask the user to try using their own prompt to see the results.
387
> Otherwise use the default.
388
389
Use the following script:
390
391
```bash
392
#!/bin/bash
393
PROJECT_ID=$(gcloud config get-value project)
394
: "${PROJECT_ID:?no gcloud project is set; ask the user for the Project ID}"
395
LOCATION_ID="us-central1"
396
ENDPOINT_ID="YOUR_ENDPOINT_ID"
397
PROMPT=${1:-"Explain quantum computing in simple terms."}
398
399
echo "Fetching dedicated Endpoint DNS..."
400
ENDPOINT_URL=$(gcloud ai endpoints describe $ENDPOINT_ID \
401
--project=$PROJECT_ID \
402
--region=$LOCATION_ID \
403
--format="value(dedicatedEndpointDns)")
404
405
if [ -z "$ENDPOINT_URL" ]; then
406
echo "Error: Could not retrieve dedicated endpoint URL for $ENDPOINT_ID."
407
exit 1
408
fi
409
410
echo "Sending prediction request to $ENDPOINT_URL..."
411
412
curl -X POST \
413
-H "Authorization: Bearer $(gcloud auth print-access-token)" \
414
-H "Content-Type: application/json" \
415
"https://${ENDPOINT_URL}/v1beta1/projects/${PROJECT_ID}/locations/${LOCATION_ID}/endpoints/${ENDPOINT_ID}/chat/completions" \
416
-d '{
417
"model": "'"$ENDPOINT_ID"'",
418
"messages": [
419
{
420
"role": "user",
421
"content": "'"$PROMPT"'"
422
}
423
]
424
}'
425
426
```
427
428
## 5. Undeploying and Cleaning Up
429
430
> For the full undeploy and cleanup procedure (find endpoint, undeploy model,
431
> delete endpoint, delete model), load
432
> `load_skill_resource(skill_name='agent-platform-deploy',
433
> file_path='references/undeploy_guide.md')`.
434
435
> [!WARNING] Failing to undeploy a model will result in continuous charges for
436
> the allocated compute resources, even if you are not sending prediction
437
> requests. Always clean up after testing.
438
439
## 6. Troubleshooting
440
441
> For troubleshooting quota/resource exhausted errors and hardware fallback,
442
> load `load_skill_resource(skill_name='agent-platform-deploy',
443
> file_path='references/troubleshooting.md')`.
444