2.7 KiB
Prompt optimization pipeline
This directory contains the infrastructure for optimizing Gemini CLI system instructions and tool descriptions. The pipeline uses a manifest-driven approach to isolate, mask, and refine instructions to achieve high tool-call accuracy with minimalist token usage.
Overview
The pipeline automates the "Success Density" strategy, which aims for 100% functional correctness while minimizing prompt length. It achieves this through multi-objective optimization using the Genetic-Pareto Algorithm (GEPA).
Architecture
The optimization infrastructure consists of three primary components that handle data extraction, variable protection, and evolutionary refinement.
extract.ts: The pre-processing engine. It uses character-aware parsing to isolate prompt strings from TypeScript source files based on the targets defined indata/manifest.json.masking.ts: A security and integrity utility. It identifies and replaces TypeScript template variables (for example,${FILE_PATH}) with indexed tokens (for example,[[GCLI_VAR_0]]). This prevents the LLM from corrupting program logic during the optimization phase.optimize.ts: The core evolution engine. It runs the GEPA loop to find the Pareto frontier between functional alignment and instruction brevity.
Metrics
The pipeline evaluates every prompt candidate using two primary objectives. Both metrics return a score between 0.0 and 1.0, where 1.0 represents a perfect result.
- Functional alignment: Measures how accurately the model selects the
correct tool for a given user query. It uses the 113 high-signal scenarios
in
data/tool_alignment.jsonlto verify behavioral correctness. - Brevity: A 4-tier step function that rewards concise model responses. It
measures the word count of the model's output text (excluding tool calls) to
penalize unnecessary verbosity.
- 1.0: 10 words or fewer.
- 0.7: 25 words or fewer.
- 0.4: 50 words or fewer.
- 0.1: More than 50 words.
Workflow
Follow these steps to run the optimization pipeline.
- Extraction: Run
npm run optimize:extractto pull instructions from the source code and generate thedata/optimization/targets.jsonartifact. - Configuration: Update
scripts/optimization/optimization.config.jsonto specify the student and teacher models and the number of trials. - Optimization: Run
npm run optimizeto start the GEPA evolution. This process produces a refined prompt that maintains accuracy while reducing tokens.
Next steps
After a successful optimization run, use the generated Pareto-optimal instructions to update the core snippets and tool definitions.