Feat/eval optimization loop 91#179
Open
wzxsdf wants to merge 2 commits into
Open
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 全过
Author
|
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 ? 87.55867%
==========================================
Files ? 467
Lines ? 44103
Branches ? 0
==========================================
Hits ? 38616
Misses ? 5487
Partials ? 0 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
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.
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