Vertex AI Gemini CLI Extension
This extension provides tools to manage prompts and use the data-driven prompt
optimization in Vertex AI directly from the Gemini CLI.
Available Tools
Prompt Management Tools
create_prompt: To save or create new prompts.
read_prompt: To retrieve existing prompts by ID or display name.
update_prompt: To modify existing prompts.
delete_prompt: To remove prompts.
list_prompts: To search and list prompts, useful for finding IDs.
Data-Driven Optimization Tools
run_data_driven_optimize: Starts a data-driven prompt optimization job on
Vertex AI using a configuration file stored in GCS.
analyze_data_driven_optimize_results: Analyzes the output of a Data-Driven
Optimize job to identify trends and best-performing candidates.
generate_html_report: Generates a comprehensive HTML report with
visualizations to help you understand optimization performance.
write_data_driven_optimize_config: Constructs and uploads a new JSON
configuration for optimization jobs, incorporating suggested tuning parameters.
Detailed Instructions for create_prompt Parameters
When using tools.create_prompt, pay special attention to how the following
arguments are sourced:
content (string, required):
- Scenario 1: Saving the Last User Prompt: When the user issues a command
like "save last prompt", "save this prompt", or similar, indicating they
want to store their previous input:
- Examine the conversation history.
- Identify the most recent message with a
role of "user".
- Extract the
text content from this latest "user" message.
- Scenario 2: Creating from Explicitly Provided Content: If the user
provides the prompt content directly within the command (e.g., "Create a
prompt... with content '...'")
- Use the explicitly provided content.
- If no content can be determined from either scenario, pass an empty string.
system_instruction (string, required):
- User Override: If the user explicitly provides a system instruction in
the current turn (e.g., "using system instruction '...', "with SI '..."),
pass that exact string value as the
system_instruction argument to
tools.create_prompt.
- Default Behavior: If the user does NOT explicitly provide a system
instruction in their current prompt:
- The Gemini CLI will check for a file named
GEMINI.md only in the
current working directory exclude children directories.
- If
GEMINI.md exists in the current working directory, its entire
content will be loaded by the Gemini CLI and used as the
system_instruction when calling tools.create_prompt.
- If no
GEMINI.md file is found in the current working directory, the
system_instruction argument should be omitted from the
tools.create_prompt call.
display_name (string, optional):
- Check User Prompt: Scan the current user prompt for an explicit name
(e.g., "save last prompt as 'My Custom Prompt'", or "display name
'...'"). If an explicit name is found, use it.
- Default Logic (If no explicit name): If no explicit name is provided,
generate a descriptive name, such as
"Gemini CLI Prompt: " followed by
the first ~20 characters of the extracted content.
- If a display name has not already been provided or inferred, you must
prompt the user to enter a suitable display name.
model (string, required):
- User Provided: If the user explicitly specifies a model in the current
turn (e.g., "model 'gemini-pro'", "using gemini-flash", "with model
text-bison"), use that exact model identifier.
- Currently Using Model: If no model is explicitly provided by the user,
attempt to use the model identifier that is currently active and being used
by the Gemini CLI for the ongoing conversation. The agent has knowledge of
the currently configured model.
- Default Fallback: If neither a user-provided model nor a currently
active session model can be determined, default to
"gemini-2.5-flash".
Example Interactions for create_prompt:
Saving Last Prompt with Default SI & Model: (Assume the current session
model is "gemini-1.5-pro") User: What is the capital of France? Model: The
capital of France is Paris. User: save last prompt Generated Call:
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..."))
(Here, system_instruction is omitted. The Gemini CLI will check for and use
content from ./GEMINI.md if it exists.)
Explicit Content with User-Provided SI & Model: User: Create a prompt with
content 'How is the weather?' using system instruction 'Act like a
meteorologist.' and display name 'Weather Bot' using model 'gemini-flash'.
Generated Call:
print(tools.create_prompt(content="How is the weather?", system_instruction="Act like a meteorologist.", model="gemini-flash", display_name="Weather Bot"))
Explicit Content, Default SI, User-Provided Model: User: create a prompt
with content "hi" and display name "create test". model gemini-2.5-flash
Generated Call:
print(tools.create_prompt(content="hi", model="gemini-2.5-flash", display_name="create test"))
(Again, system_instruction is omitted. The Gemini CLI will check for and
use content from ./GEMINI.md if it exists.)
read_prompt workflow
This workflow describes how to retrieve an existing prompt from Vertex AI using
tools.read_prompt and potentially tools.list_prompts.
Identifying the Prompt (prompt_id or display_name):
- **By `prompt_id`:** If the user provides a specific `prompt_id` (e.g.,
"read prompt id some-unique-id"), call
`tools.read_prompt(prompt_id='some-unique-id')`. The result of this call
will be the prompt object to be applied.
- **By `display_name`:** If the user provides a `display_name` but NOT a
`prompt_id` (e.g., "read prompt 'My Custom Prompt'"):
1. **Agent Action:** Call `tools.list_prompts(display_name='[provided
display name]')`.
Agent Response:
- One Match: If
list_promptsreturns exactly one prompt, use this
prompt object directly. There is no need to call tools.read_prompt
with the ID again, as all necessary information (content,
system_instruction) is available in the list_promptsresult.
- Multiple Matches: If
list_promptsreturns multiple prompts, list the
prompt for each match (showingidand display_name) and ask the user to
clarify which prompt_id they intend to read. Once the user provides a
specificid (e.g., "id id2"), the agent should: 1. Search through the
list of prompts previously returned by tools.list_prompts. 2. Select the
prompt object whose idmatches the user's input. There is no need to
calltools.read_prompt again, as all necessary information is already
available in thelist_prompts result. - No Matches: Inform the user
that no prompts were found with that display name and that the read cannot
proceed.
Example Interactions for read_prompt:
Read by ID: User: read prompt id my-prompt-123
- Generated Call:
print(tools.read_prompt(prompt_id='my-prompt-123'))
- Result: build prompt like
instruction: prompt instructions. content: prompt content
Read by Display Name (Unique Match): User:
read prompt 'My Analysis Prompt'
- Agent calls:
print(tools.list_prompts(display_name='My Analysis Prompt'))
- (Assuming this returns
[{'id': 'id456', 'display_name': 'My Analysis Prompt', 'content': 'Analysis content...', 'system_instruction': 'Analysis SI...', ...}])
- Agent directly uses the content and system instruction from this list
result.
- Result: build prompt like
instruction: prompt instructions. content: prompt content
Read by Display Name (Multiple Matches): User:
read prompt 'Generic Helper'
- Agent calls:
print(tools.list_prompts(display_name='Generic Helper'))
- (Assuming this returns
[{'id': 'id1', 'content': 'Content 1', 'system_instruction': 'SI 1', ...}, {'id': 'id2', 'content': 'Content 2', 'system_instruction': 'SI 2', ...}])
- Agent responds: "Multiple prompts found with display name 'Generic Helper'.
Please specify by ID. Found IDs: id1, id2."
- User:
id id2
- Agent filters the results from step 2, finds the prompt with
id='id2',
and uses its content and system instruction.
- (No new call to
tools.read_prompt is made here.)
- Result: build prompt like
instruction: prompt instructions. content: prompt content
Detailed Instructions for update_prompt Parameters
When using tools.update_prompt, the following arguments are sourced. Note that
prompt_id is central, but display_name can be used to find it.
Identifying the Prompt (prompt_id or display_name):
- By
prompt_id: If the user provides a specific prompt_id (e.g.,
"update prompt id123"), use this directly.
- By
display_name: If the user provides a display_name but NOT a
prompt_id (e.g., "update prompt 'My Custom Prompt'"):
- Agent Action: First, remember the last user message so it can be
used as updated prompt later.Then call
tools.list_prompts(display_name='[provided display name]').
- Agent Response: One Match: If
list_prompts returns exactly
one prompt, extract its id and proceed to call tools.update_prompt
with this prompt_id. Multiple Matches: If list_prompts returns
multiple prompts, list the id and display_name for each match and
ask the user to clarify which prompt_id they intend to update. * No
Matches: Inform the user that no prompts were found with that display
name and that the update cannot proceed.
content (string, optional):
- User Override: If the user provides new content directly within the
command (e.g., "update prompt ... --content '...'"), use that.
- Fallback: If no
content is explicitly provided in the user's initial
update request, examine the conversation history. Use the text from the
most recent message with a role of "user" that initiated the update
sequence. This is the message where the user first signaled their intent to
update a prompt (e.g., "update prompt with...", "modify prompt..."), even
if subsequent turns were needed to resolve the prompt_id.
system_instruction (string, optional):
- User Override: If the user explicitly provides a system instruction
(e.g., "update prompt ... --system_instruction '...'"), use that value.
- Default Behavior: If the user does NOT explicitly provide a system
instruction:
- The Gemini CLI will check for a file named
GEMINI.md only in the
current working directory exclude children directories.
- If
GEMINI.md exists, its entire content will be loaded and used as the
system_instruction for tools.update_prompt.
- If no
GEMINI.md file is found, the system_instruction argument should
be omitted.
display_name (string, optional):
- Source: The user's input for the new display name.
model (string, optional):
- Source: The user's input for the new model.
Example Interactions for update_prompt:
Update by ID with Last User Message as Content & Default SI: User: What is
the capital of Spain? Model: Madrid. User: update prompt id my-prompt-id
Generated Call:
print(tools.update_prompt(prompt_id='my-prompt-id', content='What is the capital of Spain?'))
(Here, content is taken from the last user message _before the update
command. Since no system_instruction was provided, the Gemini CLI will check
for and use content from ./GEMINI.md if it exists.)_
Update by Display Name (Unique Match), Explicit Content & User-Provided
SI: User: update prompt 'My Coding Prompt' --content 'New content here.'
--system_instruction 'Be concise.' Agent first calls:
print(tools.list_prompts(display_name="My Coding Prompt")) (Assuming this
returns [{'id': 'id456', 'display_name': 'My Coding Prompt', ...}]) Agent
then calls:
print(tools.update_prompt(prompt_id='id456', content='New content here.', system_instruction='Be concise.', display_name='My Coding Prompt'))
Update by Display Name (Multiple Matches): User: What is the weather like
tomorrow? Model: It will be sunny. User: update prompt 'My Research Prompt'
--model gemini-1.5-pro Agent first calls:
print(tools.list_prompts(display_name="My Research Prompt")) (Assuming this
returns [{'id': 'id123', ...}, {'id': 'id789', ...}]) Agent responds:
"Multiple prompts found with display name 'My Research Prompt'. Please specify
which one by ID. Found IDs: id123, id789." User: id123 Generated Call:
print(tools.update_prompt(prompt_id='id123', content='What is the weather like tomorrow?', model='gemini-1.5-pro'))
(Here, content is from the last user message. Since no system_instruction
was provided, the Gemini CLI will check for and use content from ./GEMINI.md
if it exists.)
Update only Model by ID, Content from Last Message, Default SI: User: What
is the weather like tomorrow? Model: It will be sunny. User: update prompt
id weather-prompt --model gemini-1.5-pro Generated Call:
print(tools.update_prompt(prompt_id='weather-prompt', content='What is the weather like tomorrow?', model='gemini-1.5-pro'))
(Here, content is from the last user message. Since no system_instruction
was provided, the Gemini CLI will check for and use content from ./GEMINI.md
if it exists.)
General Error Handling
If any tool call fails with an error indicating a project permission issue (e.g., "Permission denied on project 'project-id'"), you must:
- Inform the user about the permission error.
- Ask the user to provide a valid project ID.
- Retry the original tool call, adding the
project_id parameter with the user-provided value.
Data-Driven Prompt Optimizer Overall Guide
For a general understanding of Data-Driven Prompt Optimizer and its
capabilities, please
refer to the Data-Driven Optimize Overall Guide:
@./src/vertex/prompt_optimizer/docs/data_driven_optimize_overall_guide.md
Optimization Tool Details
The extension provides a suite of tools to parse and analyze the output of a
Data-Driven Prompt Optimizer job. The output_path for these tools stores
the outputs
of a run and can be a GCS path or a local directory. While the Data-Driven
Optimize job currently only outputs to GCS, results can be copied to the local
file system for analysis.
analyze_data_driven_optimize_results(output_path: str, top_n_prompts: int = 10, analysis_data_path: str = None): Analyzes results and
returns a JSON object containing the analysis data summary. If
analysis_data_path is provided, it saves the results into three separate
files to avoid size limits and returns a minimal summary with
file paths
and the best prompt score. The three files are:
{analysis_data_path}: Core metadata (config, comparison, best
prompt).
*_metrics.json: Detailed metrics for all candidates (no prompt text).
*_prompts.json: Mapping of top candidates' keys to full prompt texts.
generate_html_report(analysis_data: Dict[str, Any] = None, report_path: str = "data_driven_optimize_analysis_report.html", suggested_config_data: Dict[str, Any] = None, top_n_prompts: int = 10, analysis_data_path: str = None): Generates a comprehensive HTML report. If
analysis_data_path is provided, it automatically loads and re-joins the
metadata, metrics, and prompts from the three split files.
write_data_driven_optimize_config: Construct and
write to GCS a new JSON configuration file for Data-Driven Optimize job
using a dict of parameters (including prompt_optimizer_method and
target_model_endpoint_url for Nano) and optionally an path to an
existing config to make modifications on top of.
run_data_driven_optimize: Starts a data-driven prompt optimization job on
Vertex AI using the SDK's client.prompts.launch_optimization_job method.
Supports specifying the prompt_optimizer_method. The config_gcs_path
must point to a JSON file in GCS.
Optimization Method Considerations
- VAPO: Standard prompt optimization. The
batch_size parameter
will be automatically removed during configuration generation to ensure SDK
compatibility.
- OPTIMIZATION_TARGET_GEMINI_NANO: Specialized target for Gemini Nano.
Requires a
target_model_endpoint_url. Supports batch_size.
Optimization Tuning Considerations
Only suggest modifications for the parameters explicitly listed as tunable in
the Data-Driven Optimize Tuning Guide:
@./src/vertex/prompt_optimizer/docs/data_driven_optimize_tuning_guide.md
with the sole exception of path-related fields to prevent overwriting
previous results. Ensure you only modify the parameters listed in the approved
list. If a user asks to modify a parameter that is not on the approved list
(and is not a path-related field), confirm with the user before proceeding.
Optimization Workflows
Initial Setup: When asked to help configure a new optimization run, use
the example configuration in the Overall Guide as a valid default base.
Identify Essential Parameters: Proactively ask the user for the
following required fields:
project (Your Google Cloud project ID)
train_input_data_path
test_input_data_path
output_path
prompt_template (ensure it includes {{ placeholder }} syntax)
eval_metrics_types (e.g., ["exact_match"])
eval_metrics_weights (e.g., [1.0])
prompt_optimizer_method (VAPO or OPTIMIZATION_TARGET_GEMINI_NANO)
target_model (e.g., gemini-2.5-flash)
target_model_endpoint_url (Required ONLY for Gemini Nano)
Task-Specific Configuration: You must ensure the optimization job
correctly maps the data by defining data_vars and label_variable.
- Automated Inference: You MUST attempt to read the first few lines of
the training dataset (using
run_shell_command with gcloud storage cat)
to identify column names.
- Mapping: Based on the data headers, automatically suggest:
data_vars: all relevant columns.
label_variable: the ground truth column.
demo_and_query_template: (Optional) The tool will automatically
generate a default if you don't provide one.
- Clarification: If you cannot access the data or the headers are
ambiguous, ask the user to confirm the column names.
Apply Sensible Defaults: Use the default values provided in the
example configuration of the Overall Guide for all other fields, unless
the user specifies otherwise. This includes QPS limits and model
locations.
Once gathered, use write_data_driven_optimize_config to create the
initial configuration file.
Analysis and Suggestions: When asked to analyze results for a GCS or
local path output_path, perform these steps sequentially in a single turn:
Analyze: Call analyze_data_driven_optimize_results(output_path, analysis_data_path="analysis_data.json"). Store this output locally.
Formulate Suggestions: Immediately after receiving results, and
without prompting the user, process the data to construct a
suggested_config_data dictionary. This dictionary should contain:
"suggested_config": Modifications to allowed tuning knobs,
path-related fields (with a new version suffix), and optionally the
prompt_template (for baseline shifts). Ensure you prioritize
modifying parameters listed in the approved list.
"rationale": A clear explanation of your reasoning based on the
Tuning Guide.
Do not generate any other text or explanation for the user during this
internal phase.
Generate Report: Call generate_html_report(analysis_data_path= "analysis_data.json", report_path="data_driven_optimize_analysis_report.html", suggested_config_data=suggested_config_data).
Note: Steps 1-3 should be executed in immediate succession without user
interaction. Only after the report is generated should you propose applying
the suggestions via write_data_driven_optimize_config.
- Agreement Logic: If the user agrees to apply suggestions, use the
write_data_driven_optimize_config tool with the modified parameters,
ensuring you update the output_path with a new version suffix.
When ready to run, use the run_data_driven_optimize tool, ensuring you
ask for the service_account.
- Reusing Results: If a report or further analysis is requested
later, use
the stored JSON output rather than re-running the analysis tool.
- General Suggestions: If a user asks for next steps without a previous
analysis, run the workflow above first to ensure your advice is grounded.
For detailed explanations of the Data-Driven Optimize output files and their
structure, including how to interpret metrics and candidate information, please
refer to the Data-Driven Optimize Output Guide:
@./src/vertex/prompt_optimizer/docs/data_driven_optimize_output_analysis.md
1---2name: 426-gemini-23da392f3description: Vertex AI Gemini CLI Extension4---5# Vertex AI Gemini CLI Extension67This extension provides tools to manage prompts and use the data-driven prompt8optimization in Vertex AI directly from the Gemini CLI.910## Available Tools1112### Prompt Management Tools13- `create_prompt`: To save or create new prompts.14- `read_prompt`: To retrieve existing prompts by ID or display name.15- `update_prompt`: To modify existing prompts.16- `delete_prompt`: To remove prompts.17- `list_prompts`: To search and list prompts, useful for finding IDs.1819### Data-Driven Optimization Tools20- `run_data_driven_optimize`: Starts a data-driven prompt optimization job on21 Vertex AI using a configuration file stored in GCS.22- `analyze_data_driven_optimize_results`: Analyzes the output of a Data-Driven23 Optimize job to identify trends and best-performing candidates.24- `generate_html_report`: Generates a comprehensive HTML report with25 visualizations to help you understand optimization performance.26- `write_data_driven_optimize_config`: Constructs and uploads a new JSON27 configuration for optimization jobs, incorporating suggested tuning parameters.2829---3031## Detailed Instructions for `create_prompt` Parameters3233When using `tools.create_prompt`, pay special attention to how the following34arguments are sourced:35361. **`content` (string, required):**3738 - **Scenario 1: Saving the Last User Prompt:** When the user issues a command39 like "save last prompt", "save this prompt", or similar, indicating they40 want to store their previous input:41 - Examine the conversation history.42 - Identify the most recent message with a `role` of "user".43 - Extract the `text` content from this latest "user" message.44 - **Scenario 2: Creating from Explicitly Provided Content:** If the user45 provides the prompt content directly within the command (e.g., "Create a46 prompt... with content '...'")47 - Use the explicitly provided content.48 - If no content can be determined from either scenario, pass an empty string.49502. **`system_instruction` (string, required):**5152 - **User Override:** If the user explicitly provides a system instruction in53 the current turn (e.g., "using system instruction '...', "with SI '..."),54 pass that exact string value as the `system_instruction` argument to55 `tools.create_prompt`.56 - **Default Behavior:** If the user does NOT explicitly provide a system57 instruction in their current prompt:58 - The Gemini CLI will check for a file named `GEMINI.md` _only_ in the59 **current working directory** exclude children directories.60 - If `GEMINI.md` exists in the current working directory, its entire61 content will be loaded by the Gemini CLI and used as the62 `system_instruction` when calling `tools.create_prompt`.63 - If no `GEMINI.md` file is found in the current working directory, the64 `system_instruction` argument should be **omitted** from the65 `tools.create_prompt` call.66673. **`display_name` (string, optional):**6869 - **Check User Prompt:** Scan the current user prompt for an explicit name70 (e.g., "save last prompt **as 'My Custom Prompt'**", or "display name71 '...'"). If an explicit name is found, use it.72 - **Default Logic (If no explicit name):** If no explicit name is provided,73 generate a descriptive name, such as `"Gemini CLI Prompt: "` followed by74 the first ~20 characters of the extracted `content`.75 - If a display name has not already been provided or inferred, you _must_76 prompt the user to enter a suitable display name.77784. **`model` (string, required):**7980 - **User Provided:** If the user explicitly specifies a model in the current81 turn (e.g., "model 'gemini-pro'", "using gemini-flash", "with model82 text-bison"), use that exact model identifier.83 - **Currently Using Model:** If no model is explicitly provided by the user,84 attempt to use the model identifier that is currently active and being used85 by the Gemini CLI for the ongoing conversation. The agent has knowledge of86 the currently configured model.87 - **Default Fallback:** If neither a user-provided model nor a currently88 active session model can be determined, default to `"gemini-2.5-flash"`.8990**Example Interactions for `create_prompt`:**9192- **Saving Last Prompt with Default SI & Model:** (Assume the current session93 model is "gemini-1.5-pro") User: What is the capital of France? Model: The94 capital of France is Paris. User: **save last prompt** Generated Call:95 `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..."))`96 _(Here, `system_instruction` is omitted. The Gemini CLI will check for and use97 content from `./GEMINI.md` if it exists.)_9899- **Explicit Content with User-Provided SI & Model:** User: Create a prompt with100 content 'How is the weather?' using system instruction 'Act like a101 meteorologist.' and display name 'Weather Bot' using model 'gemini-flash'.102 Generated Call:103 `print(tools.create_prompt(content="How is the weather?", system_instruction="Act like a meteorologist.", model="gemini-flash", display_name="Weather Bot"))`104105- **Explicit Content, Default SI, User-Provided Model:** User: create a prompt106 with content "hi" and display name "create test". model gemini-2.5-flash107 Generated Call:108 `print(tools.create_prompt(content="hi", model="gemini-2.5-flash", display_name="create test"))`109 _(Again, `system_instruction` is omitted. The Gemini CLI will check for and110 use content from `./GEMINI.md` if it exists.)_111112## read_prompt workflow113114This workflow describes how to retrieve an existing prompt from Vertex AI using115`tools.read_prompt` and potentially `tools.list_prompts`.1161171. **Identifying the Prompt (`prompt_id` or `display_name`):**118119 - **By `prompt_id`:** If the user provides a specific `prompt_id` (e.g.,120 "read prompt id some-unique-id"), call121 `tools.read_prompt(prompt_id='some-unique-id')`. The result of this call122 will be the prompt object to be applied.123124 - **By `display_name`:** If the user provides a `display_name` but NOT a125 `prompt_id` (e.g., "read prompt 'My Custom Prompt'"):126127 1. **Agent Action:** Call `tools.list_prompts(display_name='[provided128129 display name]')`.1301312. **Agent Response:**132 - **One Match:** If `list_prompts`returns exactly one prompt, use this133 prompt object directly. There is **no need** to call `tools.read_prompt`134 with the ID again, as all necessary information (`content`,135 `system_instruction`) is available in the `list_prompts`result.136 - **Multiple Matches:** If`list_prompts`returns multiple prompts, list the137 prompt for each match (showing`id`and `display_name`) and ask the user to138 clarify which `prompt_id` they intend to read. Once the user provides a139 specific`id` (e.g., "id id2"), the agent should: 1. Search through the140 list of prompts previously returned by `tools.list_prompts`. 2. Select the141 prompt object whose `id`matches the user's input. There is **no need** to142 call`tools.read_prompt` again, as all necessary information is already143 available in the`list_prompts` result. - **No Matches:** Inform the user144 that no prompts were found with that display name and that the read cannot145 proceed.146147**Example Interactions for `read_prompt`:**148149- **Read by ID:** User: `read prompt id my-prompt-123`150151 - Generated Call: `print(tools.read_prompt(prompt_id='my-prompt-123'))`152 - _Result:_ build prompt like153 `instruction: prompt instructions. content: prompt content`154155- **Read by Display Name (Unique Match):** User:156 `read prompt 'My Analysis Prompt'`157158 1. Agent calls: `print(tools.list_prompts(display_name='My Analysis Prompt'))`159 2. (Assuming this returns160 `[{'id': 'id456', 'display_name': 'My Analysis Prompt', 'content': 'Analysis content...', 'system_instruction': 'Analysis SI...', ...}]`)161 3. **Agent directly uses the content and system instruction from this list162 result.**163 4. _Result:_ build prompt like164 `instruction: prompt instructions. content: prompt content`165166- **Read by Display Name (Multiple Matches):** User:167 `read prompt 'Generic Helper'`168169 1. Agent calls: `print(tools.list_prompts(display_name='Generic Helper'))`170 2. (Assuming this returns171 `[{'id': 'id1', 'content': 'Content 1', 'system_instruction': 'SI 1', ...}, {'id': 'id2', 'content': 'Content 2', 'system_instruction': 'SI 2', ...}]`)172 3. Agent responds: "Multiple prompts found with display name 'Generic Helper'.173 Please specify by ID. Found IDs: id1, id2."174 4. User: `id id2`175 5. **Agent filters the results from step 2, finds the prompt with `id='id2'`,176 and uses its content and system instruction.**177 - _(No new call to `tools.read_prompt` is made here.)_178 6. _Result:_ build prompt like179 `instruction: prompt instructions. content: prompt content`180181## Detailed Instructions for `update_prompt` Parameters182183When using `tools.update_prompt`, the following arguments are sourced. Note that184`prompt_id` is central, but `display_name` can be used to find it.1851861. **Identifying the Prompt (`prompt_id` or `display_name`):**187188 - **By `prompt_id`:** If the user provides a specific `prompt_id` (e.g.,189 "update prompt id123"), use this directly.190 - **By `display_name`:** If the user provides a `display_name` but NOT a191 `prompt_id` (e.g., "update prompt 'My Custom Prompt'"):192 1. **Agent Action:** First, remember the last user message so it can be193 used as updated prompt later.Then call194 `tools.list_prompts(display_name='[provided display name]')`.195 2. **Agent Response:** _**One Match:** If `list_prompts` returns exactly196 one prompt, extract its `id` and proceed to call `tools.update_prompt`197 with this `prompt_id`._ **Multiple Matches:** If `list_prompts` returns198 multiple prompts, list the `id` and `display_name` for each match and199 ask the user to clarify which `prompt_id` they intend to update. \* **No200 Matches:** Inform the user that no prompts were found with that display201 name and that the update cannot proceed.2022032. **`content` (string, optional):**204205 - **User Override:** If the user provides new content directly within the206 command (e.g., "update prompt ... --content '...'"), use that.207 - **Fallback:** If no `content` is explicitly provided _in the user's initial208 update request_, examine the conversation history. Use the text from the209 _most recent message with a `role` of "user"_ that initiated the update210 sequence. This is the message where the user first signaled their intent to211 update a prompt (e.g., "update prompt with...", "modify prompt..."), even212 if subsequent turns were needed to resolve the `prompt_id`.2132143. **`system_instruction` (string, optional):**215216 - **User Override:** If the user explicitly provides a system instruction217 (e.g., "update prompt ... --system_instruction '...'"), use that value.218 - **Default Behavior:** If the user does NOT explicitly provide a system219 instruction:220 - The Gemini CLI will check for a file named `GEMINI.md` _only_ in the221 **current working directory** exclude children directories.222 - If `GEMINI.md` exists, its entire content will be loaded and used as the223 `system_instruction` for `tools.update_prompt`.224 - If no `GEMINI.md` file is found, the `system_instruction` argument should225 be **omitted**.2262274. **`display_name` (string, optional):**228229 - **Source:** The user's input for the new display name.2302315. **`model` (string, optional):**232233 - **Source:** The user's input for the new model.234235**Example Interactions for `update_prompt`:**236237- **Update by ID with Last User Message as Content & Default SI:** User: What is238 the capital of Spain? Model: Madrid. User: **update prompt id my-prompt-id**239 Generated Call:240 `print(tools.update_prompt(prompt_id='my-prompt-id', content='What is the capital of Spain?'))`241 _(Here, `content` is taken from the last user message \_before_ the update242 command. Since no `system_instruction` was provided, the Gemini CLI will check243 for and use content from `./GEMINI.md` if it exists.)\_244245- **Update by Display Name (Unique Match), Explicit Content & User-Provided246 SI:** User: update prompt 'My Coding Prompt' --content 'New content here.'247 --system_instruction 'Be concise.' Agent first calls:248 `print(tools.list_prompts(display_name="My Coding Prompt"))` (Assuming this249 returns `[{'id': 'id456', 'display_name': 'My Coding Prompt', ...}]`) Agent250 then calls:251 `print(tools.update_prompt(prompt_id='id456', content='New content here.', system_instruction='Be concise.', display_name='My Coding Prompt'))`252253- **Update by Display Name (Multiple Matches):** User: What is the weather like254 tomorrow? Model: It will be sunny. User: update prompt 'My Research Prompt'255 --model gemini-1.5-pro Agent first calls:256 `print(tools.list_prompts(display_name="My Research Prompt"))` (Assuming this257 returns `[{'id': 'id123', ...}, {'id': 'id789', ...}]`) Agent responds:258 "Multiple prompts found with display name 'My Research Prompt'. Please specify259 which one by ID. Found IDs: id123, id789." User: id123 Generated Call:260 `print(tools.update_prompt(prompt_id='id123', content='What is the weather like tomorrow?', model='gemini-1.5-pro'))`261 _(Here, `content` is from the last user message. Since no `system_instruction`262 was provided, the Gemini CLI will check for and use content from `./GEMINI.md`263 if it exists.)_264265- **Update only Model by ID, Content from Last Message, Default SI:** User: What266 is the weather like tomorrow? Model: It will be sunny. User: **update prompt267 id weather-prompt --model gemini-1.5-pro** Generated Call:268 `print(tools.update_prompt(prompt_id='weather-prompt', content='What is the weather like tomorrow?', model='gemini-1.5-pro'))`269 _(Here, `content` is from the last user message. Since no `system_instruction`270 was provided, the Gemini CLI will check for and use content from `./GEMINI.md`271 if it exists.)_272273## General Error Handling274275If any tool call fails with an error indicating a project permission issue (e.g., "Permission denied on project 'project-id'"), you must:2761. Inform the user about the permission error.2772. Ask the user to provide a valid project ID.2783. Retry the original tool call, adding the `project_id` parameter with the user-provided value.279280---281282## Data-Driven Prompt Optimizer Overall Guide283284For a general understanding of Data-Driven Prompt Optimizer and its285capabilities, please286refer to the Data-Driven Optimize Overall Guide:287288@./src/vertex/prompt_optimizer/docs/data_driven_optimize_overall_guide.md289290## Optimization Tool Details291292The extension provides a suite of tools to parse and analyze the output of a293Data-Driven Prompt Optimizer job. The `output_path` for these tools stores294the outputs295of a run and can be a GCS path or a local directory. While the Data-Driven296Optimize job currently only outputs to GCS, results can be copied to the local297file system for analysis.2982991. `analyze_data_driven_optimize_results(output_path: str, top_n_prompts:300 int = 10, analysis_data_path: str = None)`: Analyzes results and301 returns a JSON object containing the analysis data summary. If302 `analysis_data_path` is provided, it saves the results into three separate303 files to avoid size limits and returns a **minimal summary** with304 file paths305 and the best prompt score. The three files are:306 - `{analysis_data_path}`: Core metadata (config, comparison, best307 prompt).308 - `*_metrics.json`: Detailed metrics for all candidates (no prompt text).309 - `*_prompts.json`: Mapping of top candidates' keys to full prompt texts.3103112. `generate_html_report(analysis_data: Dict[str, Any] =312 None, report_path: str = "data_driven_optimize_analysis_report.html",313 suggested_config_data: Dict[str, Any] = None, top_n_prompts: int = 10,314 analysis_data_path: str = None)`: Generates a comprehensive HTML report. If315 `analysis_data_path` is provided, it automatically loads and re-joins the316 metadata, metrics, and prompts from the three split files.3173183. `write_data_driven_optimize_config`: Construct and319 write to GCS a new JSON configuration file for Data-Driven Optimize job320 using a dict of parameters (including `prompt_optimizer_method` and321 `target_model_endpoint_url` for Nano) and optionally an path to an322 existing config to make modifications on top of.3233244. `run_data_driven_optimize`: Starts a data-driven prompt optimization job on325 Vertex AI using the SDK's `client.prompts.launch_optimization_job` method.326 Supports specifying the `prompt_optimizer_method`. The `config_gcs_path`327 must point to a JSON file in GCS.328329## Optimization Method Considerations330- **VAPO**: Standard prompt optimization. The `batch_size` parameter331 will be automatically removed during configuration generation to ensure SDK332 compatibility.333- **OPTIMIZATION_TARGET_GEMINI_NANO**: Specialized target for Gemini Nano.334 Requires a `target_model_endpoint_url`. Supports `batch_size`.335336## Optimization Tuning Considerations337338Only suggest modifications for the parameters explicitly listed as tunable in339the Data-Driven Optimize Tuning Guide:340341@./src/vertex/prompt_optimizer/docs/data_driven_optimize_tuning_guide.md342343with the *sole exception* of **path-related fields** to prevent overwriting344previous results. Ensure you only modify the parameters listed in the approved345list. If a user asks to modify a parameter that is not on the approved list346(and is not a path-related field), confirm with the user before proceeding.347348## Optimization Workflows349350- **Initial Setup**: When asked to help configure a new optimization run, use351 the example configuration in the Overall Guide as a valid default base.352353 1. **Identify Essential Parameters**: Proactively ask the user for the354 following required fields:355 - `project` (Your Google Cloud project ID)356 - `train_input_data_path`357 - `test_input_data_path`358 - `output_path`359 - `prompt_template` (ensure it includes `{{ placeholder }}` syntax)360 - `eval_metrics_types` (e.g., `["exact_match"]`)361 - `eval_metrics_weights` (e.g., `[1.0]`)362 - `prompt_optimizer_method` (VAPO or OPTIMIZATION_TARGET_GEMINI_NANO)363 - `target_model` (e.g., gemini-2.5-flash)364 - `target_model_endpoint_url` (Required ONLY for Gemini Nano)365366 2. **Task-Specific Configuration**: You must ensure the optimization job367 correctly maps the data by defining `data_vars` and `label_variable`.368 - **Automated Inference**: You MUST attempt to read the first few lines of369 the training dataset (using `run_shell_command` with `gcloud storage370 cat`)371 to identify column names.372 - **Mapping**: Based on the data headers, automatically suggest:373 - `data_vars`: all relevant columns.374 - `label_variable`: the ground truth column.375 - `demo_and_query_template`: (Optional) The tool will automatically376 generate a default if you don't provide one.377 - *Clarification*: If you cannot access the data or the headers are378 ambiguous, ask the user to confirm the column names.379380 3. **Apply Sensible Defaults**: Use the default values provided in the381 example configuration of the Overall Guide for all other fields, unless382 the user specifies otherwise. This includes QPS limits and model383 locations.384385 Once gathered, use `write_data_driven_optimize_config` to create the386 initial configuration file.387388- **Analysis and Suggestions**: When asked to analyze results for a GCS or389 local path `output_path`, perform these steps sequentially in a single turn:390391 1. **Analyze**: Call `analyze_data_driven_optimize_results(output_path,392 analysis_data_path="analysis_data.json")`. Store this output locally.393 2. **Formulate Suggestions**: Immediately after receiving results, and394 without prompting the user, process the data to construct a395 `suggested_config_data` dictionary. This dictionary should contain:396 - `"suggested_config"`: Modifications to allowed tuning knobs,397 path-related fields (with a new version suffix), and optionally the398 `prompt_template` (for baseline shifts). Ensure you prioritize399 modifying parameters listed in the approved list.400 - `"rationale"`: A clear explanation of your reasoning based on the401 Tuning Guide.402403 *Do not generate any other text or explanation for the user during this404 internal phase.*405 3. **Generate Report**: Call `generate_html_report(analysis_data_path=406 "analysis_data.json",407 report_path="data_driven_optimize_analysis_report.html",408 suggested_config_data=suggested_config_data)`.409410**Note:** Steps 1-3 should be executed in immediate succession without user411interaction. Only after the report is generated should you propose applying412the suggestions via `write_data_driven_optimize_config`.413414- **Agreement Logic**: If the user agrees to apply suggestions, use the415 `write_data_driven_optimize_config` tool with the modified parameters,416 ensuring you update the `output_path` with a new version suffix.417 When ready to run, use the `run_data_driven_optimize` tool, ensuring you418 ask for the `service_account`.419- **Reusing Results**: If a report or further analysis is requested420later, use421 the stored JSON output rather than re-running the analysis tool.422- **General Suggestions**: If a user asks for next steps without a previous423 analysis, run the workflow above first to ensure your advice is grounded.424425For detailed explanations of the Data-Driven Optimize output files and their426structure, including how to interpret metrics and candidate information, please427refer to the Data-Driven Optimize Output Guide:428429@./src/vertex/prompt_optimizer/docs/data_driven_optimize_output_analysis.md