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
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# Vertex AI Gemini CLI Extension
|
| 2 |
+
|
| 3 |
+
This extension provides tools to manage prompts and use prompt
|
| 4 |
+
optimization in Vertex AI directly from the Gemini CLI.
|
| 5 |
+
|
| 6 |
+
## Available Tools
|
| 7 |
+
|
| 8 |
+
### Prompt Management Tools
|
| 9 |
+
- `create_prompt`: To save or create new prompts.
|
| 10 |
+
- `read_prompt`: To retrieve existing prompts by ID or display name.
|
| 11 |
+
- `update_prompt`: To modify existing prompts.
|
| 12 |
+
- `delete_prompt`: To remove prompts.
|
| 13 |
+
- `list_prompts`: To search and list prompts, useful for finding IDs.
|
| 14 |
+
|
| 15 |
+
### Prompt Optimization Tools
|
| 16 |
+
- `run_few_shot_optimization`: optimize user prompt based on examples provided
|
| 17 |
+
in the CSV file stored in the GCS bucket.
|
| 18 |
+
- `run_data_driven_optimize`: Starts a data-driven prompt optimization job on
|
| 19 |
+
Vertex AI using a configuration file stored in GCS.
|
| 20 |
+
- `analyze_data_driven_optimize_results`: Analyzes the output of a Data-Driven
|
| 21 |
+
Optimize job to identify trends and best-performing candidates.
|
| 22 |
+
- `generate_html_report`: Generates a comprehensive HTML report with
|
| 23 |
+
visualizations to help you understand optimization performance.
|
| 24 |
+
- `write_data_driven_optimize_config`: Constructs and uploads a new JSON
|
| 25 |
+
configuration for optimization jobs, incorporating suggested tuning parameters.
|
| 26 |
+
|
| 27 |
+
---
|
| 28 |
+
|
| 29 |
+
## Detailed Instructions for `create_prompt` Parameters
|
| 30 |
+
|
| 31 |
+
When using `tools.create_prompt`, pay special attention to how the following
|
| 32 |
+
arguments are sourced:
|
| 33 |
+
|
| 34 |
+
1. **`content` (string, required):**
|
| 35 |
+
|
| 36 |
+
- **Scenario 1: Saving the Last User Prompt:** When the user issues a command
|
| 37 |
+
like "save last prompt", "save this prompt", or similar, indicating they
|
| 38 |
+
want to store their previous input:
|
| 39 |
+
- Examine the conversation history.
|
| 40 |
+
- Identify the most recent message with a `role` of "user".
|
| 41 |
+
- Extract the `text` content from this latest "user" message.
|
| 42 |
+
- **Scenario 2: Creating from Explicitly Provided Content:** If the user
|
| 43 |
+
provides the prompt content directly within the command (e.g., "Create a
|
| 44 |
+
prompt... with content '...'")
|
| 45 |
+
- Use the explicitly provided content.
|
| 46 |
+
- If no content can be determined from either scenario, pass an empty string.
|
| 47 |
+
|
| 48 |
+
2. **`system_instruction` (string, required):**
|
| 49 |
+
|
| 50 |
+
- **User Override:** If the user explicitly provides a system instruction in
|
| 51 |
+
the current turn (e.g., "using system instruction '...', "with SI '..."),
|
| 52 |
+
pass that exact string value as the `system_instruction` argument to
|
| 53 |
+
`tools.create_prompt`.
|
| 54 |
+
- **Default Behavior:** If the user does NOT explicitly provide a system
|
| 55 |
+
instruction in their current prompt:
|
| 56 |
+
- The Gemini CLI will check for a file named `GEMINI.md` _only_ in the
|
| 57 |
+
**current working directory** exclude children directories.
|
| 58 |
+
- If `GEMINI.md` exists in the current working directory, its entire
|
| 59 |
+
content will be loaded by the Gemini CLI and used as the
|
| 60 |
+
`system_instruction` when calling `tools.create_prompt`.
|
| 61 |
+
- If no `GEMINI.md` file is found in the current working directory, the
|
| 62 |
+
`system_instruction` argument should be **omitted** from the
|
| 63 |
+
`tools.create_prompt` call.
|
| 64 |
+
|
| 65 |
+
3. **`display_name` (string, optional):**
|
| 66 |
+
|
| 67 |
+
- **Check User Prompt:** Scan the current user prompt for an explicit name
|
| 68 |
+
(e.g., "save last prompt **as 'My Custom Prompt'**", or "display name
|
| 69 |
+
'...'"). If an explicit name is found, use it.
|
| 70 |
+
- **Default Logic (If no explicit name):** If no explicit name is provided,
|
| 71 |
+
generate a descriptive name, such as `"Gemini CLI Prompt: "` followed by
|
| 72 |
+
the first ~20 characters of the extracted `content`.
|
| 73 |
+
- If a display name has not already been provided or inferred, you _must_
|
| 74 |
+
prompt the user to enter a suitable display name.
|
| 75 |
+
|
| 76 |
+
4. **`model` (string, required):**
|
| 77 |
+
|
| 78 |
+
- **User Provided:** If the user explicitly specifies a model in the current
|
| 79 |
+
turn (e.g., "model 'gemini-pro'", "using gemini-flash", "with model
|
| 80 |
+
text-bison"), use that exact model identifier.
|
| 81 |
+
- **Currently Using Model:** If no model is explicitly provided by the user,
|
| 82 |
+
attempt to use the model identifier that is currently active and being used
|
| 83 |
+
by the Gemini CLI for the ongoing conversation. The agent has knowledge of
|
| 84 |
+
the currently configured model.
|
| 85 |
+
- **Default Fallback:** If neither a user-provided model nor a currently
|
| 86 |
+
active session model can be determined, default to `"gemini-2.5-flash"`.
|
| 87 |
+
|
| 88 |
+
**Example Interactions for `create_prompt`:**
|
| 89 |
+
|
| 90 |
+
- **Saving Last Prompt with Default SI & Model:** (Assume the current session
|
| 91 |
+
model is "gemini-1.5-pro") User: What is the capital of France? Model: The
|
| 92 |
+
capital of France is Paris. User: **save last prompt** Generated Call:
|
| 93 |
+
`print(tools.create_prompt(content="What is the capital of France?", model="gemini-1.5-pro", display_name="Gemini CLI Prompt: What is the cap..."))`
|
| 94 |
+
_(Here, `system_instruction` is omitted. The Gemini CLI will check for and use
|
| 95 |
+
content from `./GEMINI.md` if it exists.)_
|
| 96 |
+
|
| 97 |
+
- **Explicit Content with User-Provided SI & Model:** User: Create a prompt with
|
| 98 |
+
content 'How is the weather?' using system instruction 'Act like a
|
| 99 |
+
meteorologist.' and display name 'Weather Bot' using model 'gemini-flash'.
|
| 100 |
+
Generated Call:
|
| 101 |
+
`print(tools.create_prompt(content="How is the weather?", system_instruction="Act like a meteorologist.", model="gemini-flash", display_name="Weather Bot"))`
|
| 102 |
+
|
| 103 |
+
- **Explicit Content, Default SI, User-Provided Model:** User: create a prompt
|
| 104 |
+
with content "hi" and display name "create test". model gemini-2.5-flash
|
| 105 |
+
Generated Call:
|
| 106 |
+
`print(tools.create_prompt(content="hi", model="gemini-2.5-flash", display_name="create test"))`
|
| 107 |
+
_(Again, `system_instruction` is omitted. The Gemini CLI will check for and
|
| 108 |
+
use content from `./GEMINI.md` if it exists.)_
|
| 109 |
+
|
| 110 |
+
## read_prompt workflow
|
| 111 |
+
|
| 112 |
+
This workflow describes how to retrieve an existing prompt from Vertex AI using
|
| 113 |
+
`tools.read_prompt` and potentially `tools.list_prompts`.
|
| 114 |
+
|
| 115 |
+
1. **Identifying the Prompt (`prompt_id` or `display_name`):**
|
| 116 |
+
|
| 117 |
+
- **By `prompt_id`:** If the user provides a specific `prompt_id` (e.g.,
|
| 118 |
+
"read prompt id some-unique-id"), call
|
| 119 |
+
`tools.read_prompt(prompt_id='some-unique-id')`. The result of this call
|
| 120 |
+
will be the prompt object to be applied.
|
| 121 |
+
|
| 122 |
+
- **By `display_name`:** If the user provides a `display_name` but NOT a
|
| 123 |
+
`prompt_id` (e.g., "read prompt 'My Custom Prompt'"):
|
| 124 |
+
|
| 125 |
+
1. **Agent Action:** Call `tools.list_prompts(display_name='[provided
|
| 126 |
+
|
| 127 |
+
display name]')`.
|
| 128 |
+
|
| 129 |
+
2. **Agent Response:**
|
| 130 |
+
- **One Match:** If `list_prompts`returns exactly one prompt, use this
|
| 131 |
+
prompt object directly. There is **no need** to call `tools.read_prompt`
|
| 132 |
+
with the ID again, as all necessary information (`content`,
|
| 133 |
+
`system_instruction`) is available in the `list_prompts`result.
|
| 134 |
+
- **Multiple Matches:** If`list_prompts`returns multiple prompts, list the
|
| 135 |
+
prompt for each match (showing`id`and `display_name`) and ask the user to
|
| 136 |
+
clarify which `prompt_id` they intend to read. Once the user provides a
|
| 137 |
+
specific`id` (e.g., "id id2"), the agent should: 1. Search through the
|
| 138 |
+
list of prompts previously returned by `tools.list_prompts`. 2. Select the
|
| 139 |
+
prompt object whose `id`matches the user's input. There is **no need** to
|
| 140 |
+
call`tools.read_prompt` again, as all necessary information is already
|
| 141 |
+
available in the`list_prompts` result. - **No Matches:** Inform the user
|
| 142 |
+
that no prompts were found with that display name and that the read cannot
|
| 143 |
+
proceed.
|
| 144 |
+
|
| 145 |
+
**Example Interactions for `read_prompt`:**
|
| 146 |
+
|
| 147 |
+
- **Read by ID:** User: `read prompt id my-prompt-123`
|
| 148 |
+
|
| 149 |
+
- Generated Call: `print(tools.read_prompt(prompt_id='my-prompt-123'))`
|
| 150 |
+
- _Result:_ build prompt like
|
| 151 |
+
`instruction: prompt instructions. content: prompt content`
|
| 152 |
+
|
| 153 |
+
- **Read by Display Name (Unique Match):** User:
|
| 154 |
+
`read prompt 'My Analysis Prompt'`
|
| 155 |
+
|
| 156 |
+
1. Agent calls: `print(tools.list_prompts(display_name='My Analysis Prompt'))`
|
| 157 |
+
2. (Assuming this returns
|
| 158 |
+
`[{'id': 'id456', 'display_name': 'My Analysis Prompt', 'content': 'Analysis content...', 'system_instruction': 'Analysis SI...', ...}]`)
|
| 159 |
+
3. **Agent directly uses the content and system instruction from this list
|
| 160 |
+
result.**
|
| 161 |
+
4. _Result:_ build prompt like
|
| 162 |
+
`instruction: prompt instructions. content: prompt content`
|
| 163 |
+
|
| 164 |
+
- **Read by Display Name (Multiple Matches):** User:
|
| 165 |
+
`read prompt 'Generic Helper'`
|
| 166 |
+
|
| 167 |
+
1. Agent calls: `print(tools.list_prompts(display_name='Generic Helper'))`
|
| 168 |
+
2. (Assuming this returns
|
| 169 |
+
`[{'id': 'id1', 'content': 'Content 1', 'system_instruction': 'SI 1', ...}, {'id': 'id2', 'content': 'Content 2', 'system_instruction': 'SI 2', ...}]`)
|
| 170 |
+
3. Agent responds: "Multiple prompts found with display name 'Generic Helper'.
|
| 171 |
+
Please specify by ID. Found IDs: id1, id2."
|
| 172 |
+
4. User: `id id2`
|
| 173 |
+
5. **Agent filters the results from step 2, finds the prompt with `id='id2'`,
|
| 174 |
+
and uses its content and system instruction.**
|
| 175 |
+
- _(No new call to `tools.read_prompt` is made here.)_
|
| 176 |
+
6. _Result:_ build prompt like
|
| 177 |
+
`instruction: prompt instructions. content: prompt content`
|
| 178 |
+
|
| 179 |
+
## Detailed Instructions for `update_prompt` Parameters
|
| 180 |
+
|
| 181 |
+
When using `tools.update_prompt`, the following arguments are sourced. Note that
|
| 182 |
+
`prompt_id` is central, but `display_name` can be used to find it.
|
| 183 |
+
|
| 184 |
+
1. **Identifying the Prompt (`prompt_id` or `display_name`):**
|
| 185 |
+
|
| 186 |
+
- **By `prompt_id`:** If the user provides a specific `prompt_id` (e.g.,
|
| 187 |
+
"update prompt id123"), use this directly.
|
| 188 |
+
- **By `display_name`:** If the user provides a `display_name` but NOT a
|
| 189 |
+
`prompt_id` (e.g., "update prompt 'My Custom Prompt'"):
|
| 190 |
+
1. **Agent Action:** First, remember the last user message so it can be
|
| 191 |
+
used as updated prompt later.Then call
|
| 192 |
+
`tools.list_prompts(display_name='[provided display name]')`.
|
| 193 |
+
2. **Agent Response:** _**One Match:** If `list_prompts` returns exactly
|
| 194 |
+
one prompt, extract its `id` and proceed to call `tools.update_prompt`
|
| 195 |
+
with this `prompt_id`._ **Multiple Matches:** If `list_prompts` returns
|
| 196 |
+
multiple prompts, list the `id` and `display_name` for each match and
|
| 197 |
+
ask the user to clarify which `prompt_id` they intend to update. \* **No
|
| 198 |
+
Matches:** Inform the user that no prompts were found with that display
|
| 199 |
+
name and that the update cannot proceed.
|
| 200 |
+
|
| 201 |
+
2. **`content` (string, optional):**
|
| 202 |
+
|
| 203 |
+
- **User Override:** If the user provides new content directly within the
|
| 204 |
+
command (e.g., "update prompt ... --content '...'"), use that.
|
| 205 |
+
- **Fallback:** If no `content` is explicitly provided _in the user's initial
|
| 206 |
+
update request_, examine the conversation history. Use the text from the
|
| 207 |
+
_most recent message with a `role` of "user"_ that initiated the update
|
| 208 |
+
sequence. This is the message where the user first signaled their intent to
|
| 209 |
+
update a prompt (e.g., "update prompt with...", "modify prompt..."), even
|
| 210 |
+
if subsequent turns were needed to resolve the `prompt_id`.
|
| 211 |
+
|
| 212 |
+
3. **`system_instruction` (string, optional):**
|
| 213 |
+
|
| 214 |
+
- **User Override:** If the user explicitly provides a system instruction
|
| 215 |
+
(e.g., "update prompt ... --system_instruction '...'"), use that value.
|
| 216 |
+
- **Default Behavior:** If the user does NOT explicitly provide a system
|
| 217 |
+
instruction:
|
| 218 |
+
- The Gemini CLI will check for a file named `GEMINI.md` _only_ in the
|
| 219 |
+
**current working directory** exclude children directories.
|
| 220 |
+
- If `GEMINI.md` exists, its entire content will be loaded and used as the
|
| 221 |
+
`system_instruction` for `tools.update_prompt`.
|
| 222 |
+
- If no `GEMINI.md` file is found, the `system_instruction` argument should
|
| 223 |
+
be **omitted**.
|
| 224 |
+
|
| 225 |
+
4. **`display_name` (string, optional):**
|
| 226 |
+
|
| 227 |
+
- **Source:** The user's input for the new display name.
|
| 228 |
+
|
| 229 |
+
5. **`model` (string, optional):**
|
| 230 |
+
|
| 231 |
+
- **Source:** The user's input for the new model.
|
| 232 |
+
|
| 233 |
+
**Example Interactions for `update_prompt`:**
|
| 234 |
+
|
| 235 |
+
- **Update by ID with Last User Message as Content & Default SI:** User: What is
|
| 236 |
+
the capital of Spain? Model: Madrid. User: **update prompt id my-prompt-id**
|
| 237 |
+
Generated Call:
|
| 238 |
+
`print(tools.update_prompt(prompt_id='my-prompt-id', content='What is the capital of Spain?'))`
|
| 239 |
+
_(Here, `content` is taken from the last user message \_before_ the update
|
| 240 |
+
command. Since no `system_instruction` was provided, the Gemini CLI will check
|
| 241 |
+
for and use content from `./GEMINI.md` if it exists.)\_
|
| 242 |
+
|
| 243 |
+
- **Update by Display Name (Unique Match), Explicit Content & User-Provided
|
| 244 |
+
SI:** User: update prompt 'My Coding Prompt' --content 'New content here.'
|
| 245 |
+
--system_instruction 'Be concise.' Agent first calls:
|
| 246 |
+
`print(tools.list_prompts(display_name="My Coding Prompt"))` (Assuming this
|
| 247 |
+
returns `[{'id': 'id456', 'display_name': 'My Coding Prompt', ...}]`) Agent
|
| 248 |
+
then calls:
|
| 249 |
+
`print(tools.update_prompt(prompt_id='id456', content='New content here.', system_instruction='Be concise.', display_name='My Coding Prompt'))`
|
| 250 |
+
|
| 251 |
+
- **Update by Display Name (Multiple Matches):** User: What is the weather like
|
| 252 |
+
tomorrow? Model: It will be sunny. User: update prompt 'My Research Prompt'
|
| 253 |
+
--model gemini-1.5-pro Agent first calls:
|
| 254 |
+
`print(tools.list_prompts(display_name="My Research Prompt"))` (Assuming this
|
| 255 |
+
returns `[{'id': 'id123', ...}, {'id': 'id789', ...}]`) Agent responds:
|
| 256 |
+
"Multiple prompts found with display name 'My Research Prompt'. Please specify
|
| 257 |
+
which one by ID. Found IDs: id123, id789." User: id123 Generated Call:
|
| 258 |
+
`print(tools.update_prompt(prompt_id='id123', content='What is the weather like tomorrow?', model='gemini-1.5-pro'))`
|
| 259 |
+
_(Here, `content` is from the last user message. Since no `system_instruction`
|
| 260 |
+
was provided, the Gemini CLI will check for and use content from `./GEMINI.md`
|
| 261 |
+
if it exists.)_
|
| 262 |
+
|
| 263 |
+
- **Update only Model by ID, Content from Last Message, Default SI:** User: What
|
| 264 |
+
is the weather like tomorrow? Model: It will be sunny. User: **update prompt
|
| 265 |
+
id weather-prompt --model gemini-1.5-pro** Generated Call:
|
| 266 |
+
`print(tools.update_prompt(prompt_id='weather-prompt', content='What is the weather like tomorrow?', model='gemini-1.5-pro'))`
|
| 267 |
+
_(Here, `content` is from the last user message. Since no `system_instruction`
|
| 268 |
+
was provided, the Gemini CLI will check for and use content from `./GEMINI.md`
|
| 269 |
+
if it exists.)_
|
| 270 |
+
|
| 271 |
+
## General Error Handling
|
| 272 |
+
|
| 273 |
+
If any tool call fails with an error indicating a project permission issue (e.g., "Permission denied on project 'project-id'"), you must:
|
| 274 |
+
1. Inform the user about the permission error.
|
| 275 |
+
2. Ask the user to provide a valid project ID.
|
| 276 |
+
3. Retry the original tool call, adding the `project_id` parameter with the user-provided value.
|
| 277 |
+
|
| 278 |
+
---
|
| 279 |
+
|
| 280 |
+
## Few-Shot Prompt Optimization Guide
|
| 281 |
+
Few-shot prompt optimization is a tool used to refine a prompt (or system instructions) based on user-provided examples. These examples are stored in a CSV file and user must provide a GCS path to this data. The examples must follow one of two formats:
|
| 282 |
+
`("prompt", "model_response", "target_response")` or
|
| 283 |
+
`("prompt", "model_response", "rubrics", "rubrics_evaluations")`.
|
| 284 |
+
Depending on the format of the examples provided in the user's CSV file, the optimization uses one of the following methods:
|
| 285 |
+
`TARGET_RESPONSE`: The prompt is tuned to generate outputs that closely align with a provided ground-truth answer.
|
| 286 |
+
`RUBRICS`: The model analyzes rubric rules and evaluation scores to tune the prompt and address specific failures.
|
| 287 |
+
For more details, please refer to this guide: @./src/vertex/prompt_optimizer/docs/few_shot_prompt_optimization_guide.md
|
| 288 |
+
The tool is accessed through `run_few_shot_prompt_optimization(prompt_to_optimize: str,
|
| 289 |
+
example_path: str, method: str)`. This tool should be called directly on the raw prompt without invoking create_prompt or any other tool first.
|
| 290 |
+
|
| 291 |
+
## Few-shot Optimization Workflows
|
| 292 |
+
|
| 293 |
+
- When asked to run few-shot prompt optimization, identify if all required parameters are passed.
|
| 294 |
+
1. **Identify Essential Parameters**: Proactively ask the user for the
|
| 295 |
+
following required fields:
|
| 296 |
+
- `prompt_to_optimize`
|
| 297 |
+
- `example_path`
|
| 298 |
+
- `method`
|
| 299 |
+
|
| 300 |
+
2. Once the parameters are set, call the `run_few_shot_prompt_optimization` with those params.
|
| 301 |
+
|
| 302 |
+
## Data-Driven Prompt Optimizer Overall Guide
|
| 303 |
+
|
| 304 |
+
For a general understanding of Data-Driven Prompt Optimizer and its
|
| 305 |
+
capabilities, please
|
| 306 |
+
refer to the Data-Driven Optimize Overall Guide:
|
| 307 |
+
|
| 308 |
+
@./src/vertex/prompt_optimizer/docs/data_driven_optimize_overall_guide.md
|
| 309 |
+
|
| 310 |
+
## Data-Driven Optimization Tool Details
|
| 311 |
+
|
| 312 |
+
The extension provides a suite of tools to parse and analyze the output of a
|
| 313 |
+
Data-Driven Prompt Optimizer job. The `output_path` for these tools stores
|
| 314 |
+
the outputs
|
| 315 |
+
of a run and can be a GCS path or a local directory. While the Data-Driven
|
| 316 |
+
Optimize job currently only outputs to GCS, results can be copied to the local
|
| 317 |
+
file system for analysis.
|
| 318 |
+
|
| 319 |
+
1. `analyze_data_driven_optimize_results(output_path: str, top_n_prompts:
|
| 320 |
+
int = 10, analysis_data_path: str = None)`: Analyzes results and
|
| 321 |
+
returns a JSON object containing the analysis data summary. If
|
| 322 |
+
`analysis_data_path` is provided, it saves the results into three separate
|
| 323 |
+
files to avoid size limits and returns a **minimal summary** with
|
| 324 |
+
file paths
|
| 325 |
+
and the best prompt score. The three files are:
|
| 326 |
+
- `{analysis_data_path}`: Core metadata (config, comparison, best
|
| 327 |
+
prompt).
|
| 328 |
+
- `*_metrics.json`: Detailed metrics for all candidates (no prompt text).
|
| 329 |
+
- `*_prompts.json`: Mapping of top candidates' keys to full prompt texts.
|
| 330 |
+
|
| 331 |
+
2. `generate_html_report(analysis_data: Dict[str, Any] =
|
| 332 |
+
None, report_path: str = "data_driven_optimize_analysis_report.html",
|
| 333 |
+
suggested_config_data: Dict[str, Any] = None, top_n_prompts: int = 10,
|
| 334 |
+
analysis_data_path: str = None)`: Generates a comprehensive HTML report. If
|
| 335 |
+
`analysis_data_path` is provided, it automatically loads and re-joins the
|
| 336 |
+
metadata, metrics, and prompts from the three split files.
|
| 337 |
+
|
| 338 |
+
3. `write_data_driven_optimize_config`: Construct and
|
| 339 |
+
write to GCS a new JSON configuration file for Data-Driven Optimize job
|
| 340 |
+
using a dict of parameters (including `prompt_optimizer_method` and
|
| 341 |
+
`target_model_endpoint_url` for Nano) and optionally an path to an
|
| 342 |
+
existing config to make modifications on top of.
|
| 343 |
+
|
| 344 |
+
4. `run_data_driven_optimize`: Starts a data-driven prompt optimization job on
|
| 345 |
+
Vertex AI using the SDK's `client.prompts.launch_optimization_job` method.
|
| 346 |
+
Supports specifying the `prompt_optimizer_method`. The `config_gcs_path`
|
| 347 |
+
must point to a JSON file in GCS.
|
| 348 |
+
|
| 349 |
+
## Data-Driven Optimization Method Considerations
|
| 350 |
+
- **VAPO**: Standard prompt optimization. The `batch_size` parameter
|
| 351 |
+
will be automatically removed during configuration generation to ensure SDK
|
| 352 |
+
compatibility.
|
| 353 |
+
- **OPTIMIZATION_TARGET_GEMINI_NANO**: Specialized target for Gemini Nano.
|
| 354 |
+
Requires a `target_model_endpoint_url`. Supports `batch_size`.
|
| 355 |
+
|
| 356 |
+
## Data-Driven Optimization Tuning Considerations
|
| 357 |
+
|
| 358 |
+
Only suggest modifications for the parameters explicitly listed as tunable in
|
| 359 |
+
the Data-Driven Optimize Tuning Guide:
|
| 360 |
+
|
| 361 |
+
@./src/vertex/prompt_optimizer/docs/data_driven_optimize_tuning_guide.md
|
| 362 |
+
|
| 363 |
+
with the *sole exception* of **path-related fields** to prevent overwriting
|
| 364 |
+
previous results. Ensure you only modify the parameters listed in the approved
|
| 365 |
+
list. If a user asks to modify a parameter that is not on the approved list
|
| 366 |
+
(and is not a path-related field), confirm with the user before proceeding.
|
| 367 |
+
|
| 368 |
+
## Data-Driven Optimization Workflows
|
| 369 |
+
|
| 370 |
+
- **Initial Setup**: When asked to help configure a new optimization run, use
|
| 371 |
+
the example configuration in the Overall Guide as a valid default base.
|
| 372 |
+
|
| 373 |
+
1. **Identify Essential Parameters**: Proactively ask the user for the
|
| 374 |
+
following required fields:
|
| 375 |
+
- `project` (Your Google Cloud project ID)
|
| 376 |
+
- `train_input_data_path`
|
| 377 |
+
- `test_input_data_path`
|
| 378 |
+
- `output_path`
|
| 379 |
+
- `prompt_template` (ensure it includes `{{ placeholder }}` syntax)
|
| 380 |
+
- `eval_metrics_types` (e.g., `["exact_match"]`)
|
| 381 |
+
- `eval_metrics_weights` (e.g., `[1.0]`)
|
| 382 |
+
- `prompt_optimizer_method` (VAPO or OPTIMIZATION_TARGET_GEMINI_NANO)
|
| 383 |
+
- `target_model` (e.g., gemini-2.5-flash)
|
| 384 |
+
- `target_model_endpoint_url` (Required ONLY for Gemini Nano)
|
| 385 |
+
|
| 386 |
+
2. **Task-Specific Configuration**: You must ensure the optimization job
|
| 387 |
+
correctly maps the data by defining `data_vars` and `label_variable`.
|
| 388 |
+
- **Automated Inference**: You MUST attempt to read the first few lines of
|
| 389 |
+
the training dataset (using `run_shell_command` with `gcloud storage
|
| 390 |
+
cat`)
|
| 391 |
+
to identify column names.
|
| 392 |
+
- **Mapping**: Based on the data headers, automatically suggest:
|
| 393 |
+
- `data_vars`: all relevant columns.
|
| 394 |
+
- `label_variable`: the ground truth column.
|
| 395 |
+
- `demo_and_query_template`: (Optional) The tool will automatically
|
| 396 |
+
generate a default if you don't provide one.
|
| 397 |
+
- *Clarification*: If you cannot access the data or the headers are
|
| 398 |
+
ambiguous, ask the user to confirm the column names.
|
| 399 |
+
|
| 400 |
+
3. **Apply Sensible Defaults**: Use the default values provided in the
|
| 401 |
+
example configuration of the Overall Guide for all other fields, unless
|
| 402 |
+
the user specifies otherwise. This includes QPS limits and model
|
| 403 |
+
locations.
|
| 404 |
+
|
| 405 |
+
Once gathered, use `write_data_driven_optimize_config` to create the
|
| 406 |
+
initial configuration file.
|
| 407 |
+
|
| 408 |
+
- **Analysis and Suggestions**: When asked to analyze results for a GCS or
|
| 409 |
+
local path `output_path`, perform these steps sequentially in a single turn:
|
| 410 |
+
|
| 411 |
+
1. **Analyze**: Call `analyze_data_driven_optimize_results(output_path,
|
| 412 |
+
analysis_data_path="analysis_data.json")`. Store this output locally.
|
| 413 |
+
2. **Formulate Suggestions**: Immediately after receiving results, and
|
| 414 |
+
without prompting the user, process the data to construct a
|
| 415 |
+
`suggested_config_data` dictionary. This dictionary should contain:
|
| 416 |
+
- `"suggested_config"`: Modifications to allowed tuning knobs,
|
| 417 |
+
path-related fields (with a new version suffix), and optionally the
|
| 418 |
+
`prompt_template` (for baseline shifts). Ensure you prioritize
|
| 419 |
+
modifying parameters listed in the approved list.
|
| 420 |
+
- `"rationale"`: A clear explanation of your reasoning based on the
|
| 421 |
+
Tuning Guide.
|
| 422 |
+
|
| 423 |
+
*Do not generate any other text or explanation for the user during this
|
| 424 |
+
internal phase.*
|
| 425 |
+
3. **Generate Report**: Call `generate_html_report(analysis_data_path=
|
| 426 |
+
"analysis_data.json",
|
| 427 |
+
report_path="data_driven_optimize_analysis_report.html",
|
| 428 |
+
suggested_config_data=suggested_config_data)`.
|
| 429 |
+
|
| 430 |
+
**Note:** Steps 1-3 should be executed in immediate succession without user
|
| 431 |
+
interaction. Only after the report is generated should you propose applying
|
| 432 |
+
the suggestions via `write_data_driven_optimize_config`.
|
| 433 |
+
|
| 434 |
+
- **Agreement Logic**: If the user agrees to apply suggestions, use the
|
| 435 |
+
`write_data_driven_optimize_config` tool with the modified parameters,
|
| 436 |
+
ensuring you update the `output_path` with a new version suffix.
|
| 437 |
+
When ready to run, use the `run_data_driven_optimize` tool, ensuring you
|
| 438 |
+
ask for the `service_account`.
|
| 439 |
+
- **Reusing Results**: If a report or further analysis is requested
|
| 440 |
+
later, use
|
| 441 |
+
the stored JSON output rather than re-running the analysis tool.
|
| 442 |
+
- **General Suggestions**: If a user asks for next steps without a previous
|
| 443 |
+
analysis, run the workflow above first to ensure your advice is grounded.
|
| 444 |
+
|
| 445 |
+
For detailed explanations of the Data-Driven Optimize output files and their
|
| 446 |
+
structure, including how to interpret metrics and candidate information, please
|
| 447 |
+
refer to the Data-Driven Optimize Output Guide:
|
| 448 |
+
|
| 449 |
+
@./src/vertex/prompt_optimizer/docs/data_driven_optimize_output_analysis.md
|