Repository navigation
Description
What happened?
agents-cli eval optimize has two bugs in src/google/agents/cli/eval/cmd_optimize.py (_load_configs_and_datasets and cmd_optimize):
-
Inline dataset dicts in
--configcrash withTypeError:
The--confighelp text explicitly documents thattrain_datasetandvalidation_datasetmay be either a file path or an inline dictionary:- train_dataset (Path to EvaluationDataset JSON file or dict in EvaluationDataset format) - validation_dataset (Path to EvaluationDataset JSON file or dict in EvaluationDataset format)However,
_load_configs_and_datasets()unconditionally passes both values toopen(...)(cmd_optimize.pylines 72–78):if train_dataset_path is not None: with open(train_dataset_path, encoding="utf-8") as f_in: train_dataset = json.load(f_in)
When an inline
dictis provided in the JSON config,open(dict)raisesTypeError: expected str, bytes or os.PathLike object, not dict. -
Relative
--config/--datasetpaths break when invoked from a subdirectory:
Neither--datasetnor--configusesclick.Path(exists=True, dir_okay=False, resolve_path=True). Becausecmd_optimize()callschdir_project_root()before calling_load_configs_and_datasets(), relative paths passed from a subdirectory (e.g.,tests/eval/) are resolved against the project root instead of the caller's working directory and fail with an unhandledFileNotFoundError.
Steps to Reproduce
1. Inline dict in config (TypeError):
agents-cli create my-agent -y
cd my-agent
cat <<'EOF' > tests/eval/inline_config.json
{
"eval_config": {"criteria": {"final_response_quality": 0.8}},
"train_dataset": {
"eval_cases": [
{"eval_case_id": "case_1", "prompt": "Hello", "reference": "Hi there!"}
]
}
}
EOF
agents-cli eval optimize --config tests/eval/inline_config.json2. Relative --config / --dataset from a subdirectory (FileNotFoundError):
cd tests/eval
echo '{"eval_config": {"criteria": {"final_response_quality": 0.8}}}' > file_config.json
echo '{"eval_cases": [{"eval_case_id": "case_1", "prompt": "Hello", "reference": "Hi there!"}]}' > my_dataset.json
agents-cli eval optimize --config file_config.json --dataset my_dataset.jsonWhat did you expect to happen?
- Inline
train_datasetandvalidation_datasetdicts in the optimization config JSON should be accepted directly (as documented inagents-cli eval optimize --help), and non-string/non-dict values should raise a cleanClickException. - Relative
--configand--datasetpaths passed from any subdirectory inside a project should resolve relative to the caller's working directory beforechdir_project_root()runs (and missing files should fail cleanly via Click validation).
Client information
Client Information
CLI version: 1.13.0
OS info: macOS-26.5.2-arm64-arm-64bit
Command Output / Logs
Repro 1 (TypeError on inline dataset dict):
⚠️ Warning: `eval optimize` is experimental and may change.
agents-cli v1.13.0
Traceback (most recent call last):
...
File ".../google/agents/cli/eval/cmd_optimize.py", line 246, in cmd_optimize
opt_data = _load_configs_and_datasets(config_path, dataset_file, target_metric)
File ".../google/agents/cli/eval/cmd_optimize.py", line 73, in _load_configs_and_datasets
with open(train_dataset_path, encoding="utf-8") as f_in:
TypeError: expected str, bytes or os.PathLike object, not dict
Repro 2 (FileNotFoundError from subdirectory):
⚠️ Warning: `eval optimize` is experimental and may change.
Using project root directory: .../my-agent
agents-cli v1.13.0
Traceback (most recent call last):
...
File ".../google/agents/cli/eval/cmd_optimize.py", line 246, in cmd_optimize
opt_data = _load_configs_and_datasets(config_path, dataset_file, target_metric)
File ".../google/agents/cli/eval/cmd_optimize.py", line 63, in _load_configs_and_datasets
with open(config_path, encoding="utf-8") as f:
FileNotFoundError: [Errno 2] No such file or directory: 'file_config.json'
Anything else we need to know?
Root cause & verified fix in src/google/agents/cli/eval/cmd_optimize.py:
- Add a helper to load dataset entries uniformly from either
dictorstrpaths (raisingclick.ClickExceptionon invalid types) and only load config datasets when--datasetis not overriding them:(Also guarddef _load_dataset_entry(value: Any, field_name: str) -> dict | None: """Load a dataset entry from an inline dict or a JSON file path.""" if value is None: return None if isinstance(value, dict): return value if isinstance(value, str): with open(value, encoding="utf-8") as f_in: return json.load(f_in) raise click.ClickException( f"'{field_name}' in optimization config must be a file path or JSON object, " f"got {type(value).__name__}." )
(eval_config.get("criteria") or {}).get(target_metric)in casecriteriaisnull.) - Add
type=click.Path(exists=True, dir_okay=False, resolve_path=True)to both--datasetand--configso Click resolves paths relative to the caller's cwd beforechdir_project_root()runs.
Activity
asrujana-44 commentedon Nov 11, 2026
Hello @halcyon-past Thanks for reporting this issue. We will look into it and provide you an update.
asrujana-44 commentedon Nov 24, 2026
Fixed in v1.16.0