Optimizes the root agent instructions using the GEPA optimizer. AGENT_MODULE_FILE_PATH: The path to the __init__.py file that contains a module by the name "agent". "agent" module contains a root_agent. SAMPLER_CONFIG_FILE_PATH: The path to the config for the LocalEvalSampler, which contai
(
agent_module_file_path: str,
sampler_config_file_path: str,
optimizer_config_file_path: str,
print_detailed_results: bool,
log_level: str = "INFO",
)
| 1224 | help="Optional. Set the logging level", |
| 1225 | ) |
| 1226 | def cli_optimize( |
| 1227 | agent_module_file_path: str, |
| 1228 | sampler_config_file_path: str, |
| 1229 | optimizer_config_file_path: str, |
| 1230 | print_detailed_results: bool, |
| 1231 | log_level: str = "INFO", |
| 1232 | ): |
| 1233 | """Optimizes the root agent instructions using the GEPA optimizer. |
| 1234 | |
| 1235 | AGENT_MODULE_FILE_PATH: The path to the __init__.py file that contains a |
| 1236 | module by the name "agent". "agent" module contains a root_agent. |
| 1237 | |
| 1238 | SAMPLER_CONFIG_FILE_PATH: The path to the config for the LocalEvalSampler, |
| 1239 | which contains the eval config and the eval sets to use for training and |
| 1240 | validation during optimization. |
| 1241 | |
| 1242 | OPTIMIZER_CONFIG_FILE_PATH: Optional. The path to the config for the |
| 1243 | GEPARootAgentPromptOptimizer. If not provided, the default config will be |
| 1244 | used. |
| 1245 | |
| 1246 | PRINT_DETAILED_RESULTS: Optional. Enables printing detailed results exposed by |
| 1247 | the GEPA optimizer to the console. |
| 1248 | |
| 1249 | LOG_LEVEL: Optional. Set the logging level. |
| 1250 | """ |
| 1251 | envs.load_dotenv_for_agent(agent_module_file_path, ".") |
| 1252 | logs.setup_adk_logger(getattr(logging, log_level.upper())) |
| 1253 | |
| 1254 | try: |
| 1255 | from ..evaluation.custom_metric_evaluator import _CustomMetricEvaluator # noqa: F401 |
| 1256 | from ..evaluation.local_eval_sets_manager import LocalEvalSetsManager |
| 1257 | from ..optimization.gepa_root_agent_prompt_optimizer import GEPARootAgentPromptOptimizer |
| 1258 | from ..optimization.gepa_root_agent_prompt_optimizer import GEPARootAgentPromptOptimizerConfig |
| 1259 | from ..optimization.local_eval_sampler import LocalEvalSampler |
| 1260 | from ..optimization.local_eval_sampler import LocalEvalSamplerConfig |
| 1261 | from .cli_eval import _collect_eval_results # noqa: F401 |
| 1262 | from .cli_eval import _collect_inferences # noqa: F401 |
| 1263 | from .cli_eval import get_root_agent |
| 1264 | |
| 1265 | except ModuleNotFoundError as mnf: |
| 1266 | raise click.ClickException(MISSING_EVAL_DEPENDENCIES_MESSAGE) from mnf |
| 1267 | |
| 1268 | with open(sampler_config_file_path, "r", encoding="utf-8") as f: |
| 1269 | content = f.read() |
| 1270 | sampler_config = LocalEvalSamplerConfig.model_validate_json(content) |
| 1271 | |
| 1272 | if optimizer_config_file_path: |
| 1273 | with open(optimizer_config_file_path, "r", encoding="utf-8") as f: |
| 1274 | content = f.read() |
| 1275 | optimizer_config = GEPARootAgentPromptOptimizerConfig.model_validate_json( |
| 1276 | content |
| 1277 | ) |
| 1278 | else: |
| 1279 | optimizer_config = GEPARootAgentPromptOptimizerConfig() |
| 1280 | |
| 1281 | root_agent = get_root_agent(agent_module_file_path) |
| 1282 | app_name = os.path.basename(agent_module_file_path) |
| 1283 | agents_dir = os.path.dirname(agent_module_file_path) |
nothing calls this directly
no test coverage detected