|
1 | | -# Vertex Prompt Management Extension |
| 1 | +# Vertex AI Gemini CLI Extension |
2 | 2 |
|
3 | | -This extension provides tools to manage prompts in Vertex AI. |
| 3 | +This extension provides tools to manage prompts and use the data-driven prompt |
| 4 | +optimization in Vertex AI directly from the Gemini CLI. |
4 | 5 |
|
5 | | -Whenever anyone wants to read or write vertex prompts, you must use the vertex |
6 | | -management tools. |
7 | | - |
8 | | -The available tools are: |
| 6 | +## Available Tools |
9 | 7 |
|
| 8 | +### Prompt Management Tools |
10 | 9 | - `create_prompt`: To save or create new prompts. |
11 | 10 | - `read_prompt`: To retrieve existing prompts by ID or display name. |
12 | 11 | - `update_prompt`: To modify existing prompts. |
13 | 12 | - `delete_prompt`: To remove prompts. |
14 | 13 | - `list_prompts`: To search and list prompts, useful for finding IDs. |
15 | 14 |
|
| 15 | +### Data-Driven Optimization Tools |
| 16 | +- `run_data_driven_optimize`: Starts a data-driven prompt optimization job on |
| 17 | + Vertex AI using a configuration file stored in GCS. |
| 18 | +- `analyze_data_driven_optimize_results`: Analyzes the output of a Data-Driven |
| 19 | + Optimize job to identify trends and best-performing candidates. |
| 20 | +- `generate_html_report`: Generates a comprehensive HTML report with |
| 21 | + visualizations to help you understand optimization performance. |
| 22 | +- `write_data_driven_optimize_config`: Constructs and uploads a new JSON |
| 23 | + configuration for optimization jobs, incorporating suggested tuning parameters. |
| 24 | + |
| 25 | +--- |
| 26 | + |
16 | 27 | ## Detailed Instructions for `create_prompt` Parameters |
17 | 28 |
|
18 | 29 | When using `tools.create_prompt`, pay special attention to how the following |
@@ -260,4 +271,155 @@ When using `tools.update_prompt`, the following arguments are sourced. Note that |
260 | 271 | If any tool call fails with an error indicating a project permission issue (e.g., "Permission denied on project 'project-id'"), you must: |
261 | 272 | 1. Inform the user about the permission error. |
262 | 273 | 2. Ask the user to provide a valid project ID. |
263 | | -3. Retry the original tool call, adding the `project_id` parameter with the user-provided value. |
| 274 | +3. Retry the original tool call, adding the `project_id` parameter with the user-provided value. |
| 275 | + |
| 276 | +--- |
| 277 | + |
| 278 | +## Data-Driven Prompt Optimizer Overall Guide |
| 279 | + |
| 280 | +For a general understanding of Data-Driven Prompt Optimizer and its |
| 281 | +capabilities, please |
| 282 | +refer to the Data-Driven Optimize Overall Guide: |
| 283 | + |
| 284 | +@./src/vertex/prompt_optimizer/docs/data_driven_optimize_overall_guide.md |
| 285 | + |
| 286 | +## Optimization Tool Details |
| 287 | + |
| 288 | +The extension provides a suite of tools to parse and analyze the output of a |
| 289 | +Data-Driven Prompt Optimizer job. The `output_path` for these tools stores |
| 290 | +the outputs |
| 291 | +of a run and can be a GCS path or a local directory. While the Data-Driven |
| 292 | +Optimize job currently only outputs to GCS, results can be copied to the local |
| 293 | +file system for analysis. |
| 294 | + |
| 295 | +1. `analyze_data_driven_optimize_results(output_path: str, top_n_prompts: |
| 296 | + int = 10, analysis_data_path: str = None)`: Analyzes results and |
| 297 | + returns a JSON object containing the analysis data summary. If |
| 298 | + `analysis_data_path` is provided, it saves the results into three separate |
| 299 | + files to avoid size limits and returns a **minimal summary** with |
| 300 | + file paths |
| 301 | + and the best prompt score. The three files are: |
| 302 | + - `{analysis_data_path}`: Core metadata (config, comparison, best |
| 303 | + prompt). |
| 304 | + - `*_metrics.json`: Detailed metrics for all candidates (no prompt text). |
| 305 | + - `*_prompts.json`: Mapping of top candidates' keys to full prompt texts. |
| 306 | + |
| 307 | +2. `generate_html_report(analysis_data: Dict[str, Any] = |
| 308 | + None, report_path: str = "data_driven_optimize_analysis_report.html", |
| 309 | + suggested_config_data: Dict[str, Any] = None, top_n_prompts: int = 10, |
| 310 | + analysis_data_path: str = None)`: Generates a comprehensive HTML report. If |
| 311 | + `analysis_data_path` is provided, it automatically loads and re-joins the |
| 312 | + metadata, metrics, and prompts from the three split files. |
| 313 | + |
| 314 | +3. `write_data_driven_optimize_config`: Construct and |
| 315 | + write to GCS a new JSON configuration file for Data-Driven Optimize job |
| 316 | + using a dict of parameters (including `prompt_optimizer_method` and |
| 317 | + `target_model_endpoint_url` for Nano) and optionally an path to an |
| 318 | + existing config to make modifications on top of. |
| 319 | + |
| 320 | +4. `run_data_driven_optimize`: Starts a data-driven prompt optimization job on |
| 321 | + Vertex AI using the SDK's `client.prompts.launch_optimization_job` method. |
| 322 | + Supports specifying the `prompt_optimizer_method`. The `config_gcs_path` |
| 323 | + must point to a JSON file in GCS. |
| 324 | + |
| 325 | +## Optimization Method Considerations |
| 326 | +- **VAPO**: Standard prompt optimization. The `batch_size` parameter |
| 327 | + will be automatically removed during configuration generation to ensure SDK |
| 328 | + compatibility. |
| 329 | +- **OPTIMIZATION_TARGET_GEMINI_NANO**: Specialized target for Gemini Nano. |
| 330 | + Requires a `target_model_endpoint_url`. Supports `batch_size`. |
| 331 | + |
| 332 | +## Optimization Tuning Considerations |
| 333 | + |
| 334 | +Only suggest modifications for the parameters explicitly listed as tunable in |
| 335 | +the Data-Driven Optimize Tuning Guide: |
| 336 | + |
| 337 | +@./src/vertex/prompt_optimizer/docs/data_driven_optimize_tuning_guide.md |
| 338 | + |
| 339 | +with the *sole exception* of **path-related fields** to prevent overwriting |
| 340 | +previous results. Ensure you only modify the parameters listed in the approved |
| 341 | +list. If a user asks to modify a parameter that is not on the approved list |
| 342 | +(and is not a path-related field), confirm with the user before proceeding. |
| 343 | + |
| 344 | +## Optimization Workflows |
| 345 | + |
| 346 | +- **Initial Setup**: When asked to help configure a new optimization run, use |
| 347 | + the example configuration in the Overall Guide as a valid default base. |
| 348 | + |
| 349 | + 1. **Identify Essential Parameters**: Proactively ask the user for the |
| 350 | + following required fields: |
| 351 | + - `project` (Your Google Cloud project ID) |
| 352 | + - `train_input_data_path` |
| 353 | + - `test_input_data_path` |
| 354 | + - `output_path` |
| 355 | + - `prompt_template` (ensure it includes `{{ placeholder }}` syntax) |
| 356 | + - `eval_metrics_types` (e.g., `["exact_match"]`) |
| 357 | + - `eval_metrics_weights` (e.g., `[1.0]`) |
| 358 | + - `prompt_optimizer_method` (VAPO or OPTIMIZATION_TARGET_GEMINI_NANO) |
| 359 | + - `target_model` (e.g., gemini-2.5-flash) |
| 360 | + - `target_model_endpoint_url` (Required ONLY for Gemini Nano) |
| 361 | + |
| 362 | + 2. **Task-Specific Configuration**: You must ensure the optimization job |
| 363 | + correctly maps the data by defining `data_vars` and `label_variable`. |
| 364 | + - **Automated Inference**: You MUST attempt to read the first few lines of |
| 365 | + the training dataset (using `run_shell_command` with `gcloud storage |
| 366 | + cat`) |
| 367 | + to identify column names. |
| 368 | + - **Mapping**: Based on the data headers, automatically suggest: |
| 369 | + - `data_vars`: all relevant columns. |
| 370 | + - `label_variable`: the ground truth column. |
| 371 | + - `demo_and_query_template`: (Optional) The tool will automatically |
| 372 | + generate a default if you don't provide one. |
| 373 | + - *Clarification*: If you cannot access the data or the headers are |
| 374 | + ambiguous, ask the user to confirm the column names. |
| 375 | + |
| 376 | + 3. **Apply Sensible Defaults**: Use the default values provided in the |
| 377 | + example configuration of the Overall Guide for all other fields, unless |
| 378 | + the user specifies otherwise. This includes QPS limits and model |
| 379 | + locations. |
| 380 | + |
| 381 | + Once gathered, use `write_data_driven_optimize_config` to create the |
| 382 | + initial configuration file. |
| 383 | + |
| 384 | +- **Analysis and Suggestions**: When asked to analyze results for a GCS or |
| 385 | + local path `output_path`, perform these steps sequentially in a single turn: |
| 386 | + |
| 387 | + 1. **Analyze**: Call `analyze_data_driven_optimize_results(output_path, |
| 388 | + analysis_data_path="analysis_data.json")`. Store this output locally. |
| 389 | + 2. **Formulate Suggestions**: Immediately after receiving results, and |
| 390 | + without prompting the user, process the data to construct a |
| 391 | + `suggested_config_data` dictionary. This dictionary should contain: |
| 392 | + - `"suggested_config"`: Modifications to allowed tuning knobs, |
| 393 | + path-related fields (with a new version suffix), and optionally the |
| 394 | + `prompt_template` (for baseline shifts). Ensure you prioritize |
| 395 | + modifying parameters listed in the approved list. |
| 396 | + - `"rationale"`: A clear explanation of your reasoning based on the |
| 397 | + Tuning Guide. |
| 398 | + |
| 399 | + *Do not generate any other text or explanation for the user during this |
| 400 | + internal phase.* |
| 401 | + 3. **Generate Report**: Call `generate_html_report(analysis_data_path= |
| 402 | + "analysis_data.json", |
| 403 | + report_path="data_driven_optimize_analysis_report.html", |
| 404 | + suggested_config_data=suggested_config_data)`. |
| 405 | + |
| 406 | +**Note:** Steps 1-3 should be executed in immediate succession without user |
| 407 | +interaction. Only after the report is generated should you propose applying |
| 408 | +the suggestions via `write_data_driven_optimize_config`. |
| 409 | + |
| 410 | +- **Agreement Logic**: If the user agrees to apply suggestions, use the |
| 411 | + `write_data_driven_optimize_config` tool with the modified parameters, |
| 412 | + ensuring you update the `output_path` with a new version suffix. |
| 413 | + When ready to run, use the `run_data_driven_optimize` tool, ensuring you |
| 414 | + ask for the `service_account`. |
| 415 | +- **Reusing Results**: If a report or further analysis is requested |
| 416 | +later, use |
| 417 | + the stored JSON output rather than re-running the analysis tool. |
| 418 | +- **General Suggestions**: If a user asks for next steps without a previous |
| 419 | + analysis, run the workflow above first to ensure your advice is grounded. |
| 420 | + |
| 421 | +For detailed explanations of the Data-Driven Optimize output files and their |
| 422 | +structure, including how to interpret metrics and candidate information, please |
| 423 | +refer to the Data-Driven Optimize Output Guide: |
| 424 | + |
| 425 | +@./src/vertex/prompt_optimizer/docs/data_driven_optimize_output_analysis.md |
0 commit comments