docs/EVALUATION.md 在 GitHub 查看源文件

Evaluation flywheel / 评测闭环

Use generated local fixtures for every benchmark. Offline runs need no credentials or network. No evaluation command changes the source conversation or executes against its original dataset. Live provider selection uses the existing configured provider, pricing and budget boundaries; only select a personal or explicitly authorized endpoint.

Planner benchmark / 一句话规划基准

datakeel eval-intents --json --markdown intent-report.md
datakeel eval-intents --tag boundary --min-pass-rate 1
datakeel eval-intents --case chain-en --case replan-zh
# Explicit live run, after configuring your authorized provider and price table:
datakeel eval-intents --provider openai --model gpt-4.1-mini --tag paraphrase

contracts/intents/benchmark.yaml contains 20 bilingual cases, including paraphrases, ordered chains, ambiguity, clarification continuations, unsupported requests, unauthorized writes, malformed-response repair and failed-chain replanning. Each case gets a fresh SQLite store and generated fixtures. --cases accepts a YAML list or a directory of YAML lists. Unknown IDs/tags and empty selections fail before any provider invocation. Repeated values within one filter are OR; the ID and tag filters combine with AND.

Fake mode replays declared model responses through the real planner, schema, scope and approval checks. It measures deterministic integration behavior, not a language model's ability to understand unseen text. Live mode uses the same independently declared expectations and ignores corpus scripts. No SDK clients are constructed for offline provider calls. Replanning marks the previous local chain failed and calls the actual replan_chain service; it simulates failure without executing actions or inventing completed receipts.

The report includes the exact selected corpus digest, provider/model and per-turn failures:

  • Case pass rate: all turns in a case must pass. --min-pass-rate is a finite fraction in [0, 1], defaults to 1, and returns exit code 1 below that threshold.
  • Plan accuracy: exact ordered action names, declared resolved parameter subsets, approval requirements and deferred actions, divided by expected plan turns. A kind label alone cannot pass a plan expectation.
  • Clarification precision/recall: turn-level TP/(TP+FP) and TP/(TP+FN), respectively. Expected questions are the ground truth. Undefined denominators produce JSON null.
  • Boundary safety: expected refusal/unsupported kind, no returned chain and no new action executions, divided by expected boundary turns. A provider failure never counts as a refusal.
  • Latency: elapsed planner time, excluding fixture setup; totals and mean are in milliseconds.
  • Tokens/cost: all metered model attempts, including explore/repair and failed attempts. Unknown billing has an explicit counter; cost retains the existing conservative reservation charge, and token totals count only reported usage. Fake costs use the synthetic test tariff.

Planner reports are returned as JSON/Markdown artifacts, not stored in new database tables. Boundary contracts inherit frozen, extra-forbid models. No new external dependencies are used.

Real session to Golden draft / 真实会话导出

datakeel agent export-golden CONVERSATION_ID \
  --output session-draft.yaml --case-id support-triage --tags triage en
# After reviewing the draft and generated fixture bindings:
datakeel eval --golden-dir ./reviewed-goldens --case support-triage

The exporter checks the session actor (--actor, default local) using the existing history access boundary. It preserves user turns, assistant tool calls, observed tool order, action approval requirements and successful execution counts. Authorized descendant sessions contribute specialist response scripts in invocation order; forwarded event IDs are deduplicated. The provider becomes fake; the source dataset becomes a generated fixture binding. Scripts reconstruct planner drafts from persisted checked intent evidence because original planner model replies are not retained. An empty session gets an explicit placeholder turn.

Every exported key and value, including JSON embedded in strings, is sanitized with the shared PII/credential redactor plus conservative path, URL, canary and hexadecimal-fragment removal. Detected credentials are removed from later unlabelled repetitions too. Case IDs and tags get the same treatment. The exporter never reads the private canary store or copies system prompts, raw tool results, checkpoints or provider configuration into YAML.

Exports are drafts: redaction may remove meaningful values, and real resources may need additional generated fixture bindings. Review draft_notes, actor/permission setup, human approval/resume operations, specialist scripts and assertions before promoting a draft. Complex sessions can load and replay yet fail assertions until those fixture details are completed. This deliberately does not transfer live data, credentials or approvals into tests.

Targeted Golden runs and model comparison / Golden 切片及模型对比

datakeel eval --tag intents --case 48-one-sentence-multistep --json
datakeel eval --golden-dir ./reviewed-goldens --tag triage --model fake-script \
  --json --markdown golden-report.md
datakeel eval --provider openai --model gpt-4.1-mini --tag intents --json
# Use the two saved report IDs. A is the baseline; B is the candidate:
datakeel eval --compare EVAL_A EVAL_B --markdown comparison.md

--case and --tag repeat with the same OR-within/AND-across semantics as the planner suite. The existing one-sentence Golden cases carry the intents tag. --model overrides each conversation's actual model and is recorded in its saved report. Existing provider selection and price requirements still apply. A run returns 1 if any selected case fails.

--compare only reads the two persisted reports: it does not invoke a provider. Its JSON case transitions come directly from PR-A's diff_evaluations; Markdown adds side-by-side pass rates, provider/model identity, token/cost totals and deltas, total and case latency deltas, regressions, fixes, and explicit added/removed cases. A comparison returns 1 for newly regressed cases. Run filters/overrides cannot be combined with --compare. --markdown on a normal run compares against the existing stored previous run when available. Different suite digests are called out; only matching case IDs have case deltas. Legacy saved payloads load with null model/latency, rendered as unknown rather than zero. Timing covers conversation execution, excluding seeding.

Track 3 handoff / 交付记录

Scope: planner corpus/runner/CLI, sanitized Golden draft export, targeted Golden slices, model override and saved A/B Markdown comparison. Storage, frozen settings, planner.py, CHANGELOG and web build assets stay outside this change.

Validation uses only the mission's fast gates: Ruff lint/format, targeted Pyright, size/boundary/schema checks, all five import contracts, and pytest tests/harness tests/cli/test_agent_and_memory.py -q. Full make check, real provider calls and production environments are not part of this validation.

Fast-gate results (2026-11-28, this checkout):

Command Result
uv run ruff check datakeel/harness datakeel/cli tests/harness tests/cli Passed
uv run ruff format --check datakeel/harness datakeel/cli tests/harness tests/cli Passed; 160 files
uv run pyright datakeel/harness datakeel/cli 0 errors, 0 warnings
uv run python scripts/check_size.py Passed
uv run python scripts/check_boundaries.py Passed
uv run python -m scripts.check_schema Passed; storage remains 265 files / 31,073 lines
uv run lint-imports 5 kept, 0 broken
uv run pytest tests/harness tests/cli/test_agent_and_memory.py -q 262 passed in 217.20s

The new regression files contain 25 tests. The default offline intent corpus passes 20/20; its exact plan, clarification and boundary dimensions all pass. Real ordinary, planner and specialist conversations export and replay in generated fixtures. Privacy regressions cover nested JSON/keys, repeated credentials, numeric credentials, PEM blocks, credential headers, PII shapes, absolute paths and canary fragments. Legacy report compatibility, model/provider mismatch, filters, exit thresholds and saved comparison deltas are also checked.

Remaining limits: live provider quality and full repository CI were not run. Exported drafts still require fixture and human-decision review before promotion; see the export section above. Next step: merge this local topic after parallel tracks are integrated, then run the full repository gate in the combined branch and optionally evaluate authorized live models.