Optuna
$ optuna 官方出品 低风险Optuna(optuna)是自动化超参数优化框架,其 CLI 支持创建与删除实验研究(optuna create-study)、通过 --format json 查询研究与试验记录(optuna studies、optuna trials),以及借助 optuna ask 与 optuna tell 在外部脚本或 Agent 中驱动调优循环。
pip install optuna optuna ask、optuna tell 与 --format json 让编程 Agent 能够直接通过 Shell 脚本运行无状态超参数优化,无需额外 MCP 封装。
Agent 友好度体检单
当前为静态评估(本机尚未安装或尚未运行探针)。可在本地运行 npm run data:probe 并提交 data/probes/ 升级为实测证据。
FCRS-1.0 六维评分拆解
支持 --format json(及 yaml/csv/value)、-c/--column 字段筛选、--noindent,并提供面向脚本的 ask/tell JSON 子命令。
--format jsonand-c/--columnsupported onstudiesandtrialsoptuna askandoptuna tellenable language-agnostic CLI optimization loops
通过 --storage URL 清晰隔离 SQLite/RDB 存储并区分只读查询,但 delete-study 缺少 --dry-run。
- Read-only
studies,trials, andbest-trialsinspection - Isolated local SQLite or scoped
--storageURL
轻量级纯 Python PyPI 包(pip install optuna),核心依赖极简。
- Fast
pip install optunaacross macOS, Linux, and Windows
覆盖研究生命周期管理、结构化查询与终端原生的 ask/tell 优化闭环。
- Supports
create-study,studies,trials,ask,tell, andbest-trial
Preferred Networks 官方仓库(optuna/optuna),采用 MIT 协议且稳定性极高。
- Official
optuna/optunarepository under MIT license
optuna.readthedocs.io 提供详尽的 CLI 参考手册,清晰说明每个子命令与格式选项。
- Dedicated CLI reference on ReadTheDocs
安全边界、鉴权与放权指南
通过 --storage <url> 或 OPTUNA_STORAGE 环境变量连接 SQLite/RDB/Journal 存储(若使用 Postgres/MySQL 则在连接串中携带数据库凭据)。
MIT 开源 CLI 与框架免费;如选用外部关系型数据库存储则按相应数据库托管成本计费。
# Optuna CLI (optuna) Agent Rules - Always pass `--format json` on `optuna studies`, `optuna trials`, and `optuna best-trials`. - Specify `--storage <url>` (or `OPTUNA_STORAGE`) explicitly so studies do not land in unexpected default paths. - Confirm with the user before calling `optuna delete-study`.
Agent 高频安全命令配方
只读查询(安全推荐)
optuna --storage sqlite:///example.db studies --format json
输出纯净的 JSON 格式研究名称、优化方向与试验计数。
optuna --storage sqlite:///example.db trials --study-name tune-v1 --format json
返回结构化 JSON 格式的试验超参数、目标值与状态。
受控写入与预演
optuna --storage sqlite:///example.db ask --study-name tune-v1 --search-space '{"lr": {"name": "FloatDistribution", "attributes": {"low": 1e-4, "high": 1e-1, "log": true}}}' 创建单次试验并返回建议的 JSON 参数,供外部脚本或 Agent 评估。
核心优势
- +
studies、trials与best-trials原生支持--format json与-c/--column字段过滤。 - +
optuna ask与optuna tell让 Agent 可对任意 Shell 命令或非 Python 脚本执行贝叶斯调优。
注意事项与踩坑点
- ! 未配置
OPTUNA_STORAGE时若省略--storage会直接报错。 - !
optuna delete-study会永久清除试验历史且没有--dry-run预演标志。