Feat/eval optimization loop 91 - #179
Conversation
- replay harness: 同一组轨迹驱动 InMemory/SQLite/Redis,比较事件/state/memory/summary - 归一化(占位符,保留字段存在性)+ JSONPath 精确 allowed_diff + 覆盖率治理 - summary: SDK 确定性模型 + 三分比较 + loss/overwrite/affiliation 检测 - 检出验证: 快照层注入 + 端到端后端注入(改 SQL 行 / Redis key 重读) - 实测发现 SQLite summary 持久化 drift,标 KNOWN_DRIFT 只报告不改 - 29 tests pass, 1 skipped (Redis 需 TRPC_REPLAY_REDIS_URL)
构建「评测→失败归因→prompt优化→验证集回归→接受决策→审计落盘」可复现闭环: - 分层失败归因(规则快通道 + 反事实深归因,本地 metric 零成本) - 过拟合三重检测(显式公式 + 泛化缺口 + 趋势背离) - 可配置 gate(三态 accept/reject/needs_review) - sha256 审计 + 三态成本 fail-closed - fake/trace/online 三模式,fake 无 API key 可跑通(<1s),9 pytest 全过
|
I have read the CLA Document and I hereby sign the CLA |
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #179 +/- ##
==========================================
Coverage ? 88.43489%
==========================================
Files ? 491
Lines ? 46035
Branches ? 0
==========================================
Hits ? 40711
Misses ? 5324
Partials ? 0 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
解决 PR trpc-group#179 与 upstream/main 的冲突: - 8 个 tests/sessions/replay 冲突文件(backends/harness/injectors/ report/summary_checks + test_replay_consistency/injections/unit) 统一采用 upstream/main 版本,即 PR trpc-group#178 合并后经 9 次 review 修复(FPR 口径/Redis state 注入/删除未用 class 等)的最新版。 PR trpc-group#179 分支携带的是 PR trpc-group#178 未经 review 的旧版,且 eval_optimize_loop 不依赖 replay 模块(仅以字符串字面量 measured_from_replay 引用)。 - 保留 PR trpc-group#179 的 eval_optimize_loop example(32 文件)完整不动。 - 其余文件(.gitignore 等)自动合并。 测试: eval_optimize_loop 9 passed; replay 32 passed + 2 skipped(Redis).
AI Code Review设计文档仅显示了一个示例值。 现在让我看看 online 模式下的 让我验证一下测试 现在, 5 个全部正确 → 5/5 >= 0.75。很好。 现在让我考虑一个真正的问题:在 让我再次检查 现在让我验证 让我检查 我已经有足够的信息了。让我再仔细看看一个关注点: 让我验证一下是否存在凭证泄露:agent.py 中的 现在让我检查 让我确认关于 其实,更大的担忧是 让我完成最终评审。我还要检查一下 让我验证一个关于 一切一致。让我写下评审意见。 发现的问题🚨 Critical无。
|
Summary
Added
examples/optimization/eval_optimize_loop/: a reproducible closed-loop pipeline of Evaluate → Attribute → Optimize → Validate → Gate → Audit. Runs without an API key infakemode (< 1s).A lightweight orchestration layer on top of the SDK's
AgentEvaluator/AgentOptimizer: extracts candidates fromOptimizeResult.rounds, independently re-evaluates them on train/validation sets (optimizer self-scores are not trusted), performs per-case diff comparison, and applies gating.Domain: Library Catalog Agent (Novel/Science/History/FAQ classification + catalog tools + JSON). Six test cases cover three essential scenarios:
optimizable-success,no-op, andoverfitting-regression.Three modes:
fake/trace(deterministic, no LLM) andonline(realAgentOptimizer).Motivation
Issue #91 transforms prompt optimization into an auditable release decision. Aggregate scores cannot reveal validation-set regressions, new critical failures, or root causes. Therefore, optimization and release gating are decoupled: every candidate must pass independent re-evaluation before acceptance.
Design
pipeline/attribution.py): A rule engine attributes based on actual vs. expected trajectory differences (format / tool selection / parameters / knowledge / final response mismatch). Falls back to single-variable counterfactuals when rules miss. Counterfactuals run local pure-Python metrics (zero API cost), enabling ≥75% accuracy with ≤3 min runtime.pipeline/gate.py): Explicittrain↑ while val↓, generalization gap (only whenvalis unmet), and trend divergence — plus critical-case regression. Candidates withval-down / train-upare always rejected.fake/tracemodes use pre-recorded variants and two LLM-free SDK evaluators (final_response_avg_scorecontains,tool_trajectory_avg_scoreexact). Features atomic writes + SHA256 digests; three-statecost.measurementwhere unknown costs are treated as failures (fail-closed).accept/reject/needs_review) and corresponding exit codes (0/2/1).Validation
pytest tests/ -q: 9 passed (three scenarios, overfitting detection, attribution coverage/accuracy, ≤3 min runtime, report fields, hidden samples, CLI exit codes, data quality).fake/trace→ exit0, selectsrobust;overfit→ rejected (overfitting + critical regression);ineffective→ rejected (tie).flake8+yapf+git diff --checkall pass.Deliverables
run_pipeline.py+ 7 modules inpipeline/offline/fixtures.pyagent/(onlineLlmAgentwith prompt hot-reload)gate.json+optimizer.jsonsample_output/(reports + audit logs)README.md(~400-char design note) +DESIGN.mdCloses #91