feat(examples): add evaluation optimization closed-loop example#130
Open
xyxhhhhh wants to merge 2 commits into
Open
feat(examples): add evaluation optimization closed-loop example#130xyxhhhhh wants to merge 2 commits into
xyxhhhhh wants to merge 2 commits into
Conversation
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #130 +/- ##
==========================================
Coverage ? 87.56135%
==========================================
Files ? 467
Lines ? 44008
Branches ? 0
==========================================
Hits ? 38534
Misses ? 5474
Partials ? 0 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
8e68fcb to
230246e
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
概述
Closes #91.
本次提交实现了一个可复现的 Evaluation + Optimization 自动闭环示例。该示例串联了 baseline 评测、失败归因、prompt 优化、验证集回归、可配置 gate 决策和审计报告生成。
默认支持无 API Key 的 fake / trace 运行模式,同时保留
--mode optimizer路径,可委托AgentOptimizer执行候选 prompt 搜索。主要改动
examples/optimization/eval_optimize_loop/run_pipeline.pyTargetPromptoptimizer.json、case_meta.json、README 和 sample reportsoptimization_report.json和optimization_report.md示例输出tests/evaluation/test_eval_optimize_loop_example.pyPipeline 覆盖范围
本示例实现了 issue 要求的全部阶段:
AgentEvaluator分别对训练集和验证集执行 baseline 评测final_response_mismatchtool_call_errorparameter_errorllm_rubric_not_metknowledge_recall_insufficientformat_violationAgentOptimizer执行 prompt 优化new_passnew_failscore_improvedscore_regressedunchanged输入输出
输入包括:
train.evalset.jsonval.evalset.jsonoptimizer.jsonagent/prompts/router.mdagent/prompts/system.mdagent/prompts/skill.md输出包括:
optimization_report.jsonoptimization_report.mdcandidate_prompts/AgentEvaluator输出目录JSON 报告包含 baseline 分数、candidate 分数、逐 case delta、gate decision、gate reasons、失败归因统计、prompt audit、input audit、成本、token usage 和 optimizer rounds。
无 API Key 运行
本示例支持无 API Key 跑通核心流程:
--mode fake:deterministic fake model + 本地 exact-match fake judge--mode trace:生成eval_mode: "trace"evalset,并回放actual_conversationfake 和 trace 模式均不需要真实 API Key。
运行示例:
cd examples/optimization/eval_optimize_loop PYTHONPATH=../../.. python run_pipeline.py --mode fake PYTHONPATH=../../.. python run_pipeline.py --mode trace另外保留真实优化路径:
--mode optimizer:委托AgentOptimizer.optimize,用于接入真实模型环境;测试中通过 mockAgentOptimizer验证 wiring,不依赖真实 API Key。真实 optimizer 模式示例:
优化场景
fake / trace 路径包含三个 deterministic 场景:
overfit:训练集提升,但验证集没有提升,且关键验证 case 退化,因此 gate 拒绝候选。accepted:训练集和验证集均提升,且没有新增 hard fail,因此 gate 接受候选。cost_exceeded:质量提升,但估算成本超过配置预算,因此 gate 拒绝候选。CI 风格退出码:
开启
--ci-exit-code后,accepted返回0,rejected返回1。Case 覆盖
本示例包含 10 条公开 case:
覆盖以下情况:
超过 issue 要求的最少 6 条 case。
Hidden 样本准备
官方 hidden set 不在仓库内,因此无法在本地直接证明 hidden 接受/拒绝准确率 ≥ 80%。为提高该项可信度,本次实现增加了:
AgentOptimizer的 optimizer-mode wiring 测试其中 hidden-like 测试会使用不在公开 evalset 和
case_meta.json中的 case id,验证 gate 和失败归因逻辑不依赖公开样例名称。测试
当前结果:
同时已验证:
cd examples/optimization/eval_optimize_loop ../../../.venv/bin/python -m py_compile run_pipeline.py agent/agent.py