1
---
2
name: agent-platform-tuning-management
3
metadata:
4
version: "1.0.2"
5
category: AiAndMachineLearning
6
description: >-
7
Manages GenAI tuning jobs in Agent Platform. Use this to list, get, or cancel
8
ongoing model tuning jobs. Don't use for fine-tuning models (use
9
`agent-platform-tuning`), deploying models to endpoints (use
10
`agent-platform-deploy`), or managing serving endpoints (use
11
`agent-platform-endpoint-management`).
12
---
13
14
# Agent Platform Tuning Management
15
16
This skill provides instructions on how to manage GenAI Tuning Jobs using the
17
Agent Platform Python SDK. Use this skill when a user wants to check the status
18
of their tuning runs, find an active tuning job, or cancel a job that is running
19
too long.
20
21
## Attribution
22
23
**MUST READ**: Before executing any `gcloud`, REST API, or MCP command, you MUST
24
read [Usage Attribution](references/attribution.md). For commands executed
25
directly in the terminal (never in generated scripts, Terraform, or user code),
26
prefix `gcloud` with `CLOUDSDK_METRICS_REQUEST_ATTRIBUTION` and append the
27
attribution suffix to `User-Agent` headers:
28
29
```text
30
CLOUDSDK_METRICS_REQUEST_ATTRIBUTION="agent-skills/1.0 (skill:agent-platform-tuning-management)"
31
User-Agent: <existing_user_agent> agent-skills/1.0 (skill:agent-platform-tuning-management)
32
```
33
34
## Safety & Confirmation Tiers (CRITICAL)
35
36
Before executing any commands on behalf of the user, you MUST adhere to the
37
following safety tiers based on the action requested:
38
39
1. **Tier R: Read-only (`list`, `get`)**
40
* **Rule**: No confirmation needed. You may execute these commands
41
immediately to gather information for the user.
42
2. **Tier D: Destructive & Interruptive (`cancel`)**
43
* **Rule**: Cancellation is a Tier D action requiring **explicit typed
44
confirmation** (e.g. "I confirm" or "Yes, cancel it").
45
* **Required Fields in Dry-Run Confirmation Card**: Before cancelling a
46
tuning job, you MUST present a dry-run confirmation preview clearly
47
listing:
48
* **Target Resource**: The full tuning job resource name or ID (e.g.
49
`projects/<PROJECT_ID>/locations/<REGION>/tuningJobs/<JOB_ID>`).
50
* **Command / Script**: The exact cancellation command or Python code
51
to be executed.
52
* **Expected Effect**: Stops the ongoing tuning job; any in-progress
53
training will be halted and cannot be resumed.
54
* Ask the user to explicitly confirm (e.g., "Do you confirm? Please
55
reply with 'I confirm' or 'Yes, cancel it'.").
56
* **Same-turn restriction**: NEVER execute the cancellation in the same
57
turn as presenting the preview card. Stop immediately and wait for the
58
user to confirm in a new turn. Even if the user provided pre-emptive
59
confirmation (e.g. "Yes, I confirm, cancel tuning job ...") or provides
60
a corrected job ID, you MUST present the dry-run preview for that
61
specific job ID and wait for confirmation in a separate turn before
62
issuing the cancellation.
63
64
## Phase 0: Environment Setup
65
66
**CRITICAL**: Before running any of the Python snippets below, you MUST ensure
67
the environment is correctly initialized by following these steps:
68
69
1. **Google Cloud Authentication**: Authenticate with your Google Cloud account
70
and configure active Application Default Credentials (ADC) for Agent
71
Platform access:
72
73
```bash
74
gcloud auth login
75
gcloud auth application-default login
76
```
77
78
2. **Python Dependencies**: This skill needs `google-cloud-aiplatform`. Do
79
**not** create a virtual environment — it starts empty and hides packages
80
the environment already provides, forcing a redundant install. Probe, and
81
install only what is missing:
82
83
```bash
84
python3 -c "import vertexai" || pip install google-cloud-aiplatform
85
```
86
87
3. **Execution**: Run Python snippets with a plain `python3`. There is no
88
environment to activate first.
89
90
## Workflow Decision Tree
91
92
1. **Information Gathering**: Do you have a Project ID and Region?
93
94
* **No** -> You **MUST** ask the user for the missing Project ID and
95
Region in plain text, or advise them to check their gcloud
96
configuration. If neither location has this information, then ask the
97
user to provide it. Do not attempt to search random regions on your own.
98
* **Yes** -> Proceed to Step 2.
99
100
2. **Task Type**: What does the user want to do?
101
102
* **Find or List Jobs** -> Use the Python SDK to list tuning jobs. (Tier
103
R)
104
* **Check Status / Inspect a Specific Job** -> Use the Python SDK to get
105
tuning job details. (Tier R)
106
* **Cancel a Job** -> Ask for confirmation, then use the Python SDK to
107
cancel the tuning job. (Tier D)
108
109
## Using the Python SDK
110
111
> [!NOTE]
112
>
113
> **Resource Verification & Missing Projects/Jobs:** If the execution of the
114
> Python snippet fails because of an invalid filter (e.g., `400 Provided filter
115
> is not valid`), fix or drop the `filter` parameter and re-run. If it fails
116
> with an error indicating a missing or inaccessible project or job ID (`403
117
> Permission Denied`, `404 Not Found`, or invalid resource ID), you **MUST**
118
> inform the user that the project or tuning job does not exist or cannot be
119
> accessed, prompt the user to provide a valid Project ID or Job ID, and stop
120
> tool execution immediately to wait for their response (do **NOT** loop or
121
> assume the resource is valid).
122
123
### 1. Listing Tuning Jobs (Tier R)
124
125
If the user asks "What tuning jobs do I have running?" or wants to find a
126
specific job ID, always execute Python code via `run_command` (do NOT use
127
`curl`). If the user gave a project ID or number, use that **exact** value
128
(otherwise fall back to the configured project). Pass `page_size=20` and read
129
the first page (only page through every job if the user explicitly asks for a
130
total count or the full list). Filter server-side when asked for running jobs
131
(`state="JOB_STATE_RUNNING" OR state="JOB_STATE_PENDING"`) or a specific model
132
display name (`display_name:"NAME"`), print `job.tuned_model_display_name`, and
133
note when `first_page.next_page_token` is set so the 20 most recently updated
134
jobs are not presented as the entire history:
135
136
```python
137
from google.cloud import aiplatform_v1
138
139
project_id = "YOUR_PROJECT_ID" # If the user gave a project ID/number, use it explicitly
140
region = "YOUR_REGION"
141
parent = f"projects/{project_id}/locations/{region}"
142
143
client = aiplatform_v1.GenAiTuningServiceClient(
144
client_options={"api_endpoint": f"{region}-aiplatform.googleapis.com"}
145
)
146
147
request = {
148
"parent": parent,
149
"page_size": 20,
150
# Optional server-side filter, e.g.:
151
# "filter": 'state="JOB_STATE_RUNNING" OR state="JOB_STATE_PENDING"',
152
}
153
response = client.list_tuning_jobs(request=request)
154
first_page = next(iter(response.pages), None)
155
for job in (first_page.tuning_jobs if first_page else []):
156
print(f"Name: {job.name}")
157
print(f"Display Name: {job.tuned_model_display_name}")
158
print(f"Base Model: {job.base_model}")
159
print(f"State: {job.state.name}")
160
if first_page and first_page.next_page_token:
161
print("Note: More jobs exist beyond this first page of 20 most recently updated jobs.")
162
```
163
164
### 2. Getting Details for a Specific Job (Tier R)
165
166
If the user provides a Tuning Job ID and asks for its status, always execute
167
Python code via `run_command` (never use `curl`). If the user gave a project ID
168
or number, use it explicitly:
169
170
```python
171
from google.cloud import aiplatform_v1
172
173
project_id = "YOUR_PROJECT_ID" # If the user gave a project ID/number, use it explicitly
174
region = "YOUR_REGION"
175
job_id = "YOUR_JOB_ID" # 19-digit ID
176
name = f"projects/{project_id}/locations/{region}/tuningJobs/{job_id}"
177
178
client = aiplatform_v1.GenAiTuningServiceClient(
179
client_options={"api_endpoint": f"{region}-aiplatform.googleapis.com"}
180
)
181
182
job = client.get_tuning_job(name=name)
183
print(f"Name: {job.name}")
184
print(f"Base Model: {job.base_model}")
185
print(f"State: {job.state.name}")
186
print(f"Tuning Model: {job.tuned_model_display_name}")
187
```
188
189
### 3. Canceling a Job (Tier D)
190
191
If the user explicitly requests to stop, abort, or cancel a tuning job:
192
193
**Safety Check**: Follow the **Tier D (Destructive / Irreversible)**
194
confirmation rules in the Operation Tiers section above:
195
196
- **Never report an outcome you did not observe**: Never claim a job was
197
canceled or report a backend error without actually observing it from an API
198
call.
199
- Present the confirmation preview with **Expected Effect** conditioned on the
200
job's observed state (for active `PENDING`/`RUNNING` jobs: stops in-progress
201
training, which cannot be resumed, without deleting the base model or
202
dataset; if the job is already in a terminal state `SUCCEEDED`, `FAILED`, or
203
`CANCELLED`, state its current terminal state explicitly and note that no
204
active training is running).
205
- Wait for explicit user confirmation in a new turn before calling
206
`client.cancel_tuning_job(name=name)` via Python (`run_command`), and report
207
the actual API response verbatim.
208
209
```python
210
from google.cloud import aiplatform_v1
211
212
project_id = "YOUR_PROJECT_ID" # Use the EXACT project ID/number the user gave
213
region = "YOUR_REGION"
214
job_id = "YOUR_JOB_ID" # 19-digit ID
215
name = f"projects/{project_id}/locations/{region}/tuningJobs/{job_id}"
216
217
client = aiplatform_v1.GenAiTuningServiceClient(
218
client_options={"api_endpoint": f"{region}-aiplatform.googleapis.com"}
219
)
220
221
client.cancel_tuning_job(name=name)
222
print(f"Successfully requested cancellation for {name}")
223
```
224