Skip to content

feat(evaluation): add an auditable eval-optimize pipeline#169

Closed
neutronstar238 wants to merge 39 commits into
trpc-group:mainfrom
neutronstar238:main
Closed

feat(evaluation): add an auditable eval-optimize pipeline#169
neutronstar238 wants to merge 39 commits into
trpc-group:mainfrom
neutronstar238:main

Conversation

@neutronstar238

@neutronstar238 neutronstar238 commented Jul 12, 2026

Copy link
Copy Markdown

Closes #91

Summary Adds a reproducible evaluation and prompt-optimization loop under examples/optimization/eval_optimize_loop. - Evaluates baseline, optimizer-dev, and validation sets separately with per-case metrics, pass/fail status, traces, and failure attribution. - Runs candidate prompt optimization through AgentOptimizer / TargetPrompt, then re-evaluates each candidate against the validation set. - Produces schema-validated JSON and Markdown reports with baseline/candidate scores, case deltas, gate decisions, rejection reasons, costs, durations, seeds, and prompt artifacts. - Adds fail-closed acceptance gates for validation improvement, hard failures, critical-case regressions, malformed evidence, and budget constraints. - Includes deterministic fake and trace modes that run without API keys, plus explicit opt-in online mode. - Covers accepted optimization, no-op rejection, and training-only improvement with validation regression (overfitting) rejection. - Handles DeepSeek JSON-object response formatting without sending unsupported native schemas and closes judge execution paths cleanly. ## Validation - Ran the evaluation suite plus affected agent/model regression tests. - Ran the full pipeline in fake and trace modes; both completed in about 3.3 seconds. - Ran the online pipeline with configured credentials; the optimizer completed successfully and generated a schema-valid report. - Verified that the online run no longer emits the targeted DeepSeek response-format or async stream cleanup warnings.

Copilot AI review requested due to automatic review settings July 12, 2026 16:44
@github-actions

github-actions Bot commented Jul 12, 2026

Copy link
Copy Markdown

CLA Assistant Lite bot All contributors have signed the CLA ✍️ ✅

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Adds an offline-first, auditable evaluation + prompt-optimization loop example (examples/optimization/eval_optimize_loop) and hardens SDK plumbing used by the pipeline (judge execution, provider schema capability detection, and streaming resource cleanup).

Changes:

  • Introduces a reproducible eval/optimize pipeline example with evalsets, fixtures, JSON Schema contract, and documentation.
  • Adds provider capability hooks for “native response schema” support (DeepSeek disables schemas; judge falls back to JSON mode).
  • Improves runtime correctness: disables model streaming when requested and closes async streaming resources / agent runs deterministically (with new regression tests).

Reviewed changes

Copilot reviewed 29 out of 33 changed files in this pull request and generated 2 comments.

Show a summary per file
File Description
trpc_agent_sdk/models/openai_adapter/_deepseek.py DeepSeek schema capability + JSON mode
trpc_agent_sdk/models/openai_adapter/_base.py Default provider schema capability hook
trpc_agent_sdk/models/_openai_model.py Stream cleanup + exposes schema capability
trpc_agent_sdk/evaluation/_llm_judge.py Non-streaming judge runs + schema fallback
trpc_agent_sdk/evaluation/_agent_evaluator.py Safer file.json:case_id parsing
trpc_agent_sdk/agents/core/_llm_processor.py Buffer events for non-streaming runs
trpc_agent_sdk/agents/_llm_agent.py Honor RunConfig.streaming
tests/models/test_openai_model_ext.py Verifies stream closed before client
tests/evaluation/test_llm_judge_think.py Verifies judge closes agent run + disables streaming
tests/evaluation/test_llm_judge_multi_model.py DeepSeek judge uses JSON mode w/o schema
tests/agents/test_llm_agent_ext.py Verifies non-streaming run disables model streaming
tests/agents/core/test_llm_processor.py Verifies non-streaming drains before yielding
pyproject.toml Adds jsonschema to extras
examples/optimization/eval_optimize_loop/val.evalset.json Example validation evalset
examples/optimization/eval_optimize_loop/train.evalset.json Example training evalset
examples/optimization/eval_optimize_loop/README.md Example usage + design notes
examples/optimization/eval_optimize_loop/optimizer.json Example optimizer configuration
examples/optimization/eval_optimize_loop/optimizer_dev.evalset.json Optimizer holdout evalset
examples/optimization/eval_optimize_loop/optimization_report.schema.json JSON Schema contract for reports
examples/optimization/eval_optimize_loop/fixtures/trace_outputs.json Trace-mode fixture outputs
examples/optimization/eval_optimize_loop/fixtures/optimization_report.sample.json Sample report artifact
examples/optimization/eval_optimize_loop/fixtures/offline_metrics.sample.json Offline metric config sample
examples/optimization/eval_optimize_loop/fixtures/fake_outputs.json Fake-mode fixture outputs
examples/optimization/eval_optimize_loop/agent/prompts/system.md Example system prompt
examples/optimization/eval_optimize_loop/agent/prompts/router.md Example routing prompt
examples/optimization/eval_optimize_loop/agent/config.py Online mode env config helper
examples/optimization/eval_optimize_loop/agent/agent.py Online agent factory
examples/optimization/eval_optimize_loop/agent/init.py Package marker for example agent
docs/superpowers/plans/2026-07-10-eval-optimize-loop-hardening.md Implementation plan doc (new)
AGENTS.md Repo-wide agent contribution guidelines
.gitignore Ignore generated runs/ and metrics artifacts

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines +1790 to +1794
try:
close_stream = getattr(response, "close", None)
if not callable(close_stream):
close_stream = getattr(response, "aclose", None)
if callable(close_stream):
Comment on lines +1 to +3
# Eval Optimize Loop Hidden-Test Hardening Implementation Plan

> **For agentic workers:** REQUIRED SUB-SKILL: Use superpowers:subagent-driven-development (recommended) or superpowers:executing-plans to implement this plan task-by-task. Steps use checkbox (`- [ ]`) syntax for tracking.
@codecov

codecov Bot commented Jul 12, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
⚠️ Please upload report for BASE (main@e113610). Learn more about missing BASE report.

Additional details and impacted files
@@            Coverage Diff             @@
##             main        #169   +/-   ##
==========================================
  Coverage        ?   87.97662%           
==========================================
  Files           ?         467           
  Lines           ?       44139           
  Branches        ?           0           
==========================================
  Hits            ?       38832           
  Misses          ?        5307           
  Partials        ?           0           

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@neutronstar238

Copy link
Copy Markdown
Author

I have read the CLA Document and I hereby sign the CLA

@neutronstar238

Copy link
Copy Markdown
Author

Coverage follow-up for 7800ec7:

  • CI passed: 9,667 passed, 2 skipped, 1 xfailed; total coverage is 87.98%.
  • Codecov now reports: “All modified and coverable lines are covered by tests.” The codecov/patch check passes.
  • The remaining “missing BASE (main@e113610)” warning is repository-side. The upstream main CI run 29080284818 generated coverage, but its upload had an empty CODECOV_TOKEN and Codecov rejected it with Token required because branch is protected.

A maintainer must either configure CODECOV_TOKEN for the upstream repository or enable Codecov OIDC (id-token: write plus use_oidc: true). A fork PR cannot tokenlessly upload a report for the protected upstream BASE commit.

@neutronstar238

Copy link
Copy Markdown
Author

Closing this PR so the verified current head can be submitted as a fresh PR and retrigger the external pull-request pipeline. A replacement link will follow.

@neutronstar238

Copy link
Copy Markdown
Author

Replacement pull request: #171

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

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

2 participants