Skip to content

构建 Evaluation + Optimization 的自动回归与提示词优化闭环 #91

Closed

Description

@raychen911

背景和价值
tRPC-Agent 已提供 AgentEvaluator 和 AgentOptimizer 两类关键能力:前者负责把 Agent 行为固化成可回归的评测信号,后者基于评测结果自动搜索更优 prompt、skill 描述或 sub-agent 指令。真实业务中,评测和优化不能割裂:如果评测集质量差,优化器会过拟合;如果优化过程不可审计,改出来的 prompt 即使分数变高也很难进入生产。
该题要求构建一个“评测 - 失败归因 - prompt 优化 - 回归验证 - 产物审计”的自动闭环。它不是简单跑一次 AgentOptimizer,而是要判断优化是否真的提升、是否牺牲其他指标、是否出现过拟合、是否值得回写源 prompt。
任务描述
设计并实现一个可复现的 Evaluation + Optimization pipeline。输入 baseline prompt、训练评测集、验证评测集和优化配置,系统自动运行 baseline 评测、定位失败 case、执行若干轮优化、对候选 prompt 做验证集回归,并输出结构化优化报告和是否接受候选的决策。
具体要求
pipeline 至少需要包含以下阶段:
1.Baseline 评测:使用 AgentEvaluator 对训练集和验证集分别打分,记录每条 case 的 metric 分、pass/fail、失败原因和关键轨迹。
2.失败归因:按失败类型聚类,例如最终回复不匹配、工具调用错误、参数错误、LLM rubric 不达标、知识召回不足、格式不符合要求。
3.优化执行:使用 AgentOptimizer 或等价扩展机制优化至少一个 TargetPrompt,支持 system prompt、skill prompt、router prompt 中的一种或多种。
4.候选验证:优化后必须重新跑验证集,并和 baseline 做逐 case 对比,区分新增通过、新增失败、分数提升、分数下降。
5.接受策略:实现可配置 gate,例如验证集总分提升 ≥ 指定阈值、不能新增 hard fail、关键 case 不能退化、成本不能超过预算。
6.审计落盘:保存每轮候选 prompt、评测结果、接受/拒绝理由、运行成本、耗时、随机种子或复现实验配置。
输入输出要求:
●输入包含 train.evalset.json、val.evalset.json、optimizer.json 和 prompt 源文件。
●输出 optimization_report.json,包含 baseline、candidate、delta、gate decision、失败归因统计。
●输出 optimization_report.md,用人能读懂的方式说明优化是否值得接受。
●支持 fake judge / fake model / trace mode,保证没有真实 API Key 时也能跑通核心流程。
交付物
●新增示例目录,例如 examples/optimization/eval_optimize_loop/。
●pipeline 入口脚本、样例 evalset、样例 prompt、优化配置和 README。
●至少 6 条评测 case:3 条训练、3 条验证,其中需要包含可优化成功、优化无效、优化后退化三类情况。
●optimization_report.json 示例输出。
●一份 300 – 500 字方案设计说明,解释失败归因方法、接受策略、防过拟合策略和产物审计方式。
验收标准
1.公开提供的 6 条样例 case 必须全部可运行,并生成完整优化报告。
2.在隐藏样本上,优化接受/拒绝决策准确率 ≥ 80%。
3.对“验证集退化但训练集提升”的过拟合场景,必须能拒绝候选 prompt。
4.失败归因分类准确率 ≥ 75%,且每个失败 case 至少能给出一个可解释原因。
5.fake model / trace mode 下完整 pipeline 耗时 ≤ 3 分钟。
6.报告必须包含 baseline 分数、candidate 分数、逐 case delta、gate 决策、拒绝或接受理由。

本issue为2026犀牛鸟开源人才培养活动专属issue,仅供已报名参与犀牛鸟活动的同学认领
【认领时间】7月1日~7月31日(7月1日前认领视为无效❗)
【认领方式】在本issue评论区回复“已认领本任务”,即视为认领成功
【活动报名】需提前完成犀牛鸟报名问卷,问卷将用于活动登记和奖励发放:https://wj.qq.com/s2/26888567/gh2q

Activity

  1. Adonis-a233 commented on Jun 30, 2026

    @Adonis-a233

    已认领本任务

  2. ha0924 commented on Jun 30, 2026

    @ha0924

    已认领本任务

  3. Spock12138 commented on Jun 30, 2026

    @Spock12138

    已认领本任务

  4. xuleiball-lab commented on Jul 1, 2026

    @xuleiball-lab

    已认领本任务

  5. eternity2026 commented on Jul 1, 2026

    @eternity2026

    已认领本任务

  6. woshidage77 commented on Jul 1, 2026

    @woshidage77

    已认领本任务

  7. tianyouyiwang commented on Jul 1, 2026

    @tianyouyiwang

    已认领本任务

  8. Luwhi commented on Jul 1, 2026

    @Luwhi

    已认领本任务

  9. MuGuang-L commented on Jul 1, 2026

    @MuGuang-L

    已认领本任务

  10. han12580 commented on Jul 1, 2026

    @han12580

    已认领本任务

  11. rhljj commented on Jul 1, 2026

    @rhljj

    已认领本任务

  12. Leoluis0705 commented on Jul 1, 2026

    @Leoluis0705

    已认领该任务

  13. neutronstar238 commented on Jul 1, 2026

    @neutronstar238

    已认领本任务

  14. 51 remaining items

  15. AsyncKurisu commented on Aug 2, 2026

    @AsyncKurisu

    @raychen911
    I would like to kindly ask for some clarification regarding the closure of PR #255 .
    I noticed that PR #255 was closed with the note "Closed as related to #92," while both the PR title and description indicate that it "Resolves #91." Additionally, the implementation appears to have addressed the requirements described in #91, and the AI review did not identify any critical issues.
    Could you please help clarify the reason for closing PR #255 ? I would also appreciate knowing whether there is a possibility of reopening it or if any further changes are needed from my side before it can proceed with the review process.
    Thank you very much for your time and guidance.

  16. raychen911 commented on Aug 3, 2026

    @raychen911
    ContributorAuthor

    @raychen911 I would like to kindly ask for some clarification regarding the closure of PR #255 . I noticed that PR #255 was closed with the note "Closed as related to #92," while both the PR title and description indicate that it "Resolves #91." Additionally, the implementation appears to have addressed the requirements described in #91, and the AI review did not identify any critical issues. Could you please help clarify the reason for closing PR #255 ? I would also appreciate knowing whether there is a possibility of reopening it or if any further changes are needed from my side before it can proceed with the review process. Thank you very much for your time and guidance.

    这边重新打开了

  17. coder-mtj commented on Aug 3, 2026

    @coder-mtj

    交付摘要 — trpc-agent-python PR #139

    Evaluation + Optimization 闭环流水线(犀牛鸟 issue #91)

    1. 任务概述

    2. 需求与目标

    实现可复现的 Evaluation + Optimization 闭环流水线:
    baseline 评估 → 失败归因 → 提示词优化 → 验证集对比(防过拟合)→ 多维 gate 判定 → 带审计追踪的报告输出。全部放在
    examples/optimization/eval_optimize_loop/ 下,不触碰 SDK 代码。

    3. 交付内容(51 个文件,+12,121 行)

    模块 职责
    run_pipeline.py CLI 入口,fake / trace / live 三模式端到端编排
    baseline.py + comparator.py TraceMatcher 逐 case 评估(pass / score / 失败原因),支持 fake(离线无 LLM)、trace(SDK 回放)、live(真实 LLM)

    |
    | attribution.py | 10 类失败归因,每条带 confidence + detail + evidence |
    | optimize.py | AgentOptimizer 集成,带超时保护与候选策略记录 |
    | validate.py | 验证集重评、逐 case delta(new_pass / new_fail / unchanged)、过拟合检测 |
    | gate.py | 质量 / 成本 / 预算 / 时间 / 场景多维检查,输出 accept / reject / needs review |
    | report.py | JSON + Markdown 报告,含 audit trail(seed、耗时、成本、复现命令) |
    | tracing.py / config.py / _paths.py | 追踪埋点、统一配置、路径引导 |
    | tests/(24 个文件) | 368 个测试全绿 |
    | data/ + sample_output/ | 训练 / 验证集 + 端到端生成好的示例报告 |

    4. 验收标准达成情况

    验收标准 结果
    失败归因准确率 ≥ 90%(要求 ≥ 75%,对照 gold 表) ✅ 通过(test_attribution_accuracy.py)
    gate 多维判定正确(accept / reject) ✅ 通过(test_gate.py、test_decision_accuracy.py)
    过拟合检测:train 提升 + val 退化 → 拒绝 ✅ 通过(test_pipeline_overfit.py)
    三模式运行(fake / trace / live) ✅ fake 端到端出报告;live 含成本豁免与超时保护
    报告可复现、含审计追踪 ✅ sample_output/optimization_report.{json,md}

    5. 测试与 CI

    • 本地:python -m pytest tests/ -q → 368 passed
    • CI:8/8 全绿(build / test / lint / review / codecov / scan / external / CLA)
    • 覆盖:baseline、comparator、attribution、gate、validate、optimize、config、report、tracing、edge
      cases、regression、large-scale、performance、live-mode 等

    6. 迭代过程

    共约 10 轮 helloopenworld AI review,全部 Critical / Warning 已修复并逐轮重推,主要修复点:

    • % 期望值误判、千分位数字提取、否定语境误判(窗口扩展 + 不回退被否定值)
    • 过拟合场景"扰动假成功"(无 parts 显式报错、自动选择可扰动且 baseline 通过的 val case)
    • live 模式成本豁免脱钩(budget 键 + checks 判定)、优化超时保护
    • 报告误导性信息修正(场景错误 vs 真实过拟合区分、sample_output 同步)
    • I/O 容错、异常收窄、路径引导、output_dir 默认值统一

    7. 使用方式

    cd examples/optimization/eval_optimize_loop               
                                                                                                                                                          
    # fake 模式(离线、确定性、零成本)
    python run_pipeline.py --mode fake \                                                                                                                  
      --train-evalset data/train.evalset.json \                                                                                                           
      --val-evalset data/val.evalset.json \                                                                                                               
      --output-dir sample_output                                                                                                                          
                                                                                                                                                          
    # 全量测试                                                                                                                                            
    python -m pytest tests/ -q                                                                                                                            
                                                                                                                                                          
    8. 待办                                                                                                                                               
                                                                                                                                                          
    - PR body 更新完成                                                                                                                                    
    - 维护者人工 APPROVE → 合入
  18. coder-mtj commented on Aug 4, 2026

    @coder-mtj

    更新交付 — 实现已重投为 PR #284

    原 PR #139 因历史重写被 GitHub 永久禁用(无法 reopen),完整实现已重投至 PR #284:

    • PR:feat(examples): add evaluation + optimization closed-loop pipeline #284 feat(examples): add evaluation + optimization closed-loop pipeline
    • 状态:✅ CI 8/8 全绿 · 419 tests pass · 最新 AI review 0 Critical / 1 Warning / 1 Suggestion
    • 改动:51 文件 / +13,094 行,全部落在 examples/optimization/eval_optimize_loop/,不触碰 SDK 代码

    方案设计说明(300–500 字)

    失败归因:基于 TraceMatcher 的逐 case 评估,按最终回复不匹配、工具调用错误、参数错误、LLM rubric 不达标、知识召回不足、格式不符等 10 类聚类,每条带 confidence / detail / evidence;对照 gold 表准确率 ≥ 90%。

    接受策略:多维 gate(质量 / 成本 / 预算 / 时间 / 场景)输出 accept / reject / needs review,验证集总分提升达阈值且无新增 hard fail 才接受;best_score 口径(SDK vs 模拟)随结果携带,杜绝不可比误判。

    防过拟合:优化后必须重跑验证集并逐 case 对比(new_pass / new_fail / unchanged),train 提升 + val 退化显式判定为 overfit 并拒绝;overfit 场景与真实过拟合在报告/审计中区分标注。

    产物审计:每轮候选 prompt、评测结果、接受/拒绝理由、运行成本、耗时、随机种子与复现命令全部落盘 optimization_report.{json,md},可复现、可审计。

    迭代:多轮 AI review 已全部处理,修复涵盖 SDK None 字段归一、路径锚定(holdout/prompt/train/val/output)、比较运算符 = 误判、repo-root 含 SDK 校验、live 降级兜底、防过拟合守卫、CI 默认入口冒烟等。

    请 @raychen911 审阅,谢谢!

  19. coder-mtj commented on Aug 4, 2026

    @coder-mtj

    @raychen911 更新:实现最终在 PR #285(https://github.com/trpc-group/trpc-agent-python/pull/285)。此前 #284 因历史累赘(89 commits)已关闭,重投为 #285 干净单 commit(head bae2544)。交付状态:CI 8/8 全绿、422 tests pass、最新 AI review 0 Critical。请审阅,谢谢。

  20. raychen911 commented on Aug 5, 2026

    @raychen911
    ContributorAuthor

    PR #104 was closed earlier today due to a typo in the original description (referenced Issue #6 instead of #91). The description has been corrected to \Closes #91\ and a reopen has been requested. PR #104 implements the full 6-phase pipeline with 111 tests and 38 rounds of AI review resolved. Ready for review.

    已经重新打开

  21. raychen911 commented on Aug 5, 2026

    @raychen911
    ContributorAuthor

    更新交付 — 实现已重投为 PR #284

    原 PR #139 因历史重写被 GitHub 永久禁用(无法 reopen),完整实现已重投至 PR #284:

    • PR:feat(examples): add evaluation + optimization closed-loop pipeline #284 feat(examples): add evaluation + optimization closed-loop pipeline
    • 状态:✅ CI 8/8 全绿 · 419 tests pass · 最新 AI review 0 Critical / 1 Warning / 1 Suggestion
    • 改动:51 文件 / +13,094 行,全部落在 examples/optimization/eval_optimize_loop/,不触碰 SDK 代码

    方案设计说明(300–500 字)

    失败归因:基于 TraceMatcher 的逐 case 评估,按最终回复不匹配、工具调用错误、参数错误、LLM rubric 不达标、知识召回不足、格式不符等 10 类聚类,每条带 confidence / detail / evidence;对照 gold 表准确率 ≥ 90%。

    接受策略:多维 gate(质量 / 成本 / 预算 / 时间 / 场景)输出 accept / reject / needs review,验证集总分提升达阈值且无新增 hard fail 才接受;best_score 口径(SDK vs 模拟)随结果携带,杜绝不可比误判。

    防过拟合:优化后必须重跑验证集并逐 case 对比(new_pass / new_fail / unchanged),train 提升 + val 退化显式判定为 overfit 并拒绝;overfit 场景与真实过拟合在报告/审计中区分标注。

    产物审计:每轮候选 prompt、评测结果、接受/拒绝理由、运行成本、耗时、随机种子与复现命令全部落盘 optimization_report.{json,md},可复现、可审计。

    迭代:多轮 AI review 已全部处理,修复涵盖 SDK None 字段归一、路径锚定(holdout/prompt/train/val/output)、比较运算符 = 误判、repo-root 含 SDK 校验、live 降级兜底、防过拟合守卫、CI 默认入口冒烟等。

    请 @raychen911 审阅,谢谢!

    这边已经在审核,后续耐心等待公布结果

  22. Wsp030914 commented on Aug 5, 2026

    @Wsp030914

    @raychen911 I would like to kindly ask for some clarification regarding the closure of PR #255 . I noticed that PR #255 was closed with the note "Closed as related to #92," while both the PR title and description indicate that it "Resolves #91." Additionally, the implementation appears to have addressed the requirements described in #91, and the AI review did not identify any critical issues. Could you please help clarify the reason for closing PR #255 ? I would also appreciate knowing whether there is a possibility of reopening it or if any further changes are needed from my side before it can proceed with the review process. Thank you very much for your time and guidance.

    这边重新打开了

    您好,请问可以把我的#244 的也重新打开吗,我这边也是同样问题

  23. raychen911 commented on Aug 5, 2026

    @raychen911
    ContributorAuthor

    @raychen911 I would like to kindly ask for some clarification regarding the closure of PR #255 . I noticed that PR #255 was closed with the note "Closed as related to #92," while both the PR title and description indicate that it "Resolves #91." Additionally, the implementation appears to have addressed the requirements described in #91, and the AI review did not identify any critical issues. Could you please help clarify the reason for closing PR #255 ? I would also appreciate knowing whether there is a possibility of reopening it or if any further changes are needed from my side before it can proceed with the review process. Thank you very much for your time and guidance.

    这边重新打开了

    您好,请问可以把我的#244 的也重新打开吗,我这边也是同样问题

    已经打开

  24. raychen911 commented on Aug 5, 2026

    @raychen911
    ContributorAuthor

    @guocfu 完成任务并获奖

  25. raychen911 commented on Aug 5, 2026

    @raychen911
    ContributorAuthor
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions