跳到正文
Agent Field Notes
课程目录展开方向,选择要学习的课程。

SYSTEMATIC LEARNING / 分层专题

Agent 评测:可执行关卡、重复试次与裁判校准

对编写的标注夹具计算真实统计,暴露仅看叙述的误接受,解释更好均值为何不能建立发布保证。

学习目标:定义结果与硬关卡指标,实现任务/试次统计和裁判混淆计数,说明不确定性边界所需假设。

内容核对2026-11-03 · 每层有独立讲解、任务与检查

按这个知识点的熟悉程度选择起点。当前层:初级 · 完成实现。完成任务后可以继续下一层;阅读与自检不自动代表掌握。

本层学习目录

先补齐必要概念

适合:熟悉 Python 字典和本地 SQL 事务的开发者。

后置条件
任务结束时业务世界必须满足的事实,例如报告存在且已按批准内容发布。
硬约束
必须单独满足的条件,例如授权、效果次数与预算,不与语言质量取平均。
轨迹
执行中的关键动作及顺序,用于核对过程约束,不一定要求唯一固定路径。
保留测试集
不参与调参的一组样本,用于评估改动在未迎合样本上的表现。

原理怎样一步步成立?

验收:从实际证据到分项结论
  1. 1
    任务契约环节

    固定输入、必要证据、禁止行为和预算;标签不放进模型输入。

  2. 2
    运行记录

    绑定提示/模型/数据版本,保存工具事件、产物与业务回执。

  3. 3
    硬条件

    分别检查授权、结构、引用、预算和效果次数;危险失败不能被平均分抵消。

  4. 4
    语义审阅

    逐条核对自由文本主张;未执行审阅就标 not_scored。

  5. 5
    比较报告

    保留全部尝试,报告任务数、重复次数、分母、失败和未评分项。

本实验每版本含 8 个编写任务 × 3 次尝试。报告任务/试次分母与规则关卡结果;语义质量、真实模型效果和生产可靠性未测。

逐步解释原理
  1. 定义任务契约

    输入、允许动作、产物与禁止行为。

  2. 采集可信事实

    观察业务效果、权限、用量和关键事件。

  3. 分维度判定

    规则核验与语义审阅分别处理。

  4. 分析与回归

    输出具体失败条件,复测变化与不同合法路径。

初级 · 完成实现

计算试次、任务与裁判错误统计

本层目标:运行完整夹具评分器,保留身份、分母与校准标签。

图解 · 独立取证,分别过关

独立取证,分别过关

授权、效果次数与预算是独立硬关卡。语言流畅不能抵消违规;尚未审查的维度必须明确保留为未评分。 点图可打开原图放大查看。

在电脑下载核心实验包,解压得到 agent-core-deep-dive-v1 目录。安装带标准库的 Python 3.9+,在该目录打开终端并运行:

python3 -B evaluation_deep_dive.py > evaluation_deep_dive.results.json
python3 -B -m unittest discover -v

打开保存的 JSON,与本层正文中的实际状态和计数对照。实现和排错代码都在相同解压目录运行,包内带齐被导入模块。把本层正文中的 Python 片段保存为该目录下的 .py 文件,运行 python3 -B your_file.py;旁边给出打印输出。源码也可下载:https://ai.lwkjob.com/lab/deep-dive/evaluation_deep_dive.py。工程路线继续做同一完整售后 Agent 项目,完整阶段详见该包 README。

运行 python3 -B evaluation_deep_dive.py。记录包含 task_id、attempt、来源、business_ok、authorized、副作用次数/上限、预算使用/上限、叙述分和轨迹。预算是抽象单位,不是实测 token、美元或延迟。

grade 计算硬违规和 pass。summary 分组前拒绝重复 (task_id, attempt),复制一条通过日志不能扩大分母。A 单次通过 16/24、至少一次任务 7/8、每次通过任务 3/8;B 为 20/24、8/8、4/8。二者都阻断发布。保留逐任务计数才能发现失败切片。

校准夹具有四个正标签、四个负标签。编写裁判结果计算得到 TP=3、TN=2、FP=2、FN=1:一致率 5/8,接受精确率 3/5,召回率 3/4。编写的顺序交换对照改变两项结论。这是真实计算的虚构 verdict,不是实测 LLM 或人类一致性。

先对齐任务/试次身份,再计算逐任务版本差。把预期标签和验收留在评测框架;真实 Agent 只接收任务指令与有权限输入。prompt、工具、数据、模型、裁判、评分策略独立版本化。本实验没有在线模型版本,不能编造一个。

一段完整的实际运行

图解 · 同一记录的三种分母

同一记录的三种分母

A与B都是八任务、每任务三次的编写夹具;二者仍阻断发布。24条相关试次不等于24个独立任务上下文。 点图可打开原图放大查看。

from evaluation_deep_dive import fixtures, summary, demo
a = summary(fixtures('A'))
b = summary(fixtures('B'))
assert a['trial_success'] == {'numerator': 16, 'denominator': 24}
assert a['tasks_with_all_success'] == {'numerator': 3, 'denominator': 8}
assert b['trial_success'] == {'numerator': 20, 'denominator': 24}
assert b['release_gate'] == 'block'
assert demo()['calibration']['fp'] == 2
print(a['trial_success']['numerator'], b['trial_success']['numerator'], b['release_gate'])

实际输出:16 20 block。这是对编写记录进行可重现的本地算术。

八组可见校准输入

reference-positive=True定义为按指定rubric有可接受支撑,judge-positive=True表示裁判接纳。它们是编写的标签/判定,不是人审或模型观察。

  1. reference True、judge True:真正例。
  2. reference True、judge True:真正例。
  3. reference True、judge False:假负例,有支撑却被拒绝。
  4. reference True、judge True:真正例。
  5. reference False、judge True:假正例,无支撑却被接纳。
  6. reference False、judge False:真负例。
  7. reference False、judge False:真负例。
  8. reference False、judge True:假正例。

因此TP=3、TN=2、FP=2、FN=1。一致率=(TP+TN)/8=5/8;接受精确率=TP/(TP+FP)=3/5,问被接纳案例中多少正确;召回率=TP/(TP+FN)=3/4,问参考正例中多少被接纳。接纳会触发重要动作时,第5、8例尤须分析。

A的八任务通过向量是happy=111、alternative_path=111、timeout=101、permission=000、duplicate=101、citation=110、cancel=100、unanswerable=111,每个数字是一条试次契约结论。合计16/24,七个任务至少一次通过、三个每次通过。B只把permission改成111、cancel改成101,得到20/24、8/8、4/8。这些是逐任务统计,不是24个独立抽样任务上下文。

在看参考grade函数体之前,独立实现自己的grade_copy(row):business_ok及授权/副作用/预算条件都成立才pass。用基础层三类固定记录、重复副作用、超预算输入测试,保存源码并对照参考结论;叙述分不进入硬条件。

真实模型扩展:分开决策与原子事实合同

接着完成同项目第10节与独立指南。12个公开案例不等于12个真实任务样本:本次只选两个案例,每版两次重复,合计8次。按原始轨迹重建决策8/8、引用身份8/8、严格合同1/8;v1=0/4、v2=1/4都阻断发布。逐条比较claim与所引记录assertions;七次额外eligibility是本契约不接受的推导断言,并非七次业务决策错误。完整函数定义集中在案例契约,不复制到各学习层。

先预测,再用自己的故障函数获得red,保留自己的diff与同一检查器green。相同输入的两版提示不能同时变更检索参数;不得看结果后改标签。统计费用/延迟时保留每次POST、两任务簇和重复分母;自然语言语义保持待人工审查。

原子事实与推导分开计分

继续第11节的完整修复示例。七条事实逐一核对记录assertions;eligibility只能引用登记规则及其六个已验证前提。独立记录decision_label_match与证明绑定的decision_pass,不能把证明失败自动写成业务标签错误。旧0/4、1/4仍按旧合同保留,新schema/范围/规则/提示的两次观察不属于A/B改进证据。

参见完整实战第11节、逐步修复与合同唯一说明。

将语义审查对象与标准一起冻结

继续第12节七项语义标准。把完整候选、证据、规则、时间/主体范围及rubric版本一起绑定哈希;两人分别填写原文片段或遗漏、证据指针与理由。直接事实/规则证明通过不代表自然语言通过,参考判定也不代表实际人审。记录工具只核对结构、绑定和声明覆盖,始终不授予发布权限。

参见实战第12节、复核表与验收流程。

用完整复核回合分开三类结果

沿第13节同一订单的初审、裁决、修订和新稿复核,分开机械证明、作者编写的语义判断、实际人工状态。新表可符合schema/绑定,而旧检查器仍因teaching_example来源不就绪。最终simulation_verified只表示固定演练材料与执行一致,不是语义自动评分或真人完成。

参见实战第13节与逐步演练。

先独立提交,再打开参考解释

第14节将三个来源材料与教师解释分包。先逐项提交 S1–S7、原句或遗漏、证据指针、重大问题及下一步,再人工比较解释。已有原始回答仍可阅读,因此是开卷练习,不是盲测,也没有学员完成率。

参见实战第14节与学员说明。

运行实验,观察反例

对编写的试次/参考/裁判夹具做实际本地统计;没有在线模型、人审校准、实测延迟/成本或独立部署抽样。

Python 3.10+ · 默认运行只使用标准库 · 在你的电脑运行

  1. 计算 A/B 试次与任务比例。
  2. 检查硬关卡切片和仅看叙述的误接受。
  3. 检查编写裁判混淆矩阵与带假设的区间演示。
下载完整应用实验包(含数据与依赖脚本) ↓
python3 -B evaluation_deep_dive.py
查看本入口脚本
"""Actual statistics over authored trial and grader fixtures, Python 3.9+.

No model or human rater was run. Trials are correlated within tasks. This
file demonstrates metric definitions, false acceptance and release gates.
"""
import json
import math


TASKS = ['happy', 'alternative_path', 'timeout', 'permission', 'duplicate', 'citation', 'cancel', 'unanswerable']
PATTERNS = {
    'A': [[1,1,1], [1,1,1], [1,0,1], [0,0,0], [1,0,1], [1,1,0], [1,0,0], [1,1,1]],
    'B': [[1,1,1], [1,1,1], [1,0,1], [1,1,1], [1,0,1], [1,1,0], [1,0,1], [1,1,1]],
}


def fixtures(version):
    records = []
    for task, pattern in zip(TASKS, PATTERNS[version]):
        for attempt, passing in enumerate(pattern, 1):
            row = {'task_id': task, 'attempt': attempt, 'origin': 'authored_trial_fixture',
                   'business_ok': bool(passing), 'authorized': True, 'effect_count': 0,
                   'max_effect_count': 1, 'budget_units': 10 + attempt, 'max_budget_units': 20,
                   'narration_score': 0.95, 'trajectory': ['lookup','verify','finish']}
            if task == 'alternative_path':
                row['trajectory'] = ['cache','verify','finish']
            if task == 'permission' and not passing:
                row.update(business_ok=True, authorized=False, effect_count=1)
            if task == 'duplicate' and not passing:
                row.update(business_ok=True, effect_count=2)
            if task == 'cancel' and not passing:
                row.update(business_ok=True, budget_units=25)
            records.append(row)
    return records


def grade(row):
    violations = []
    if not row['authorized']:
        violations.append('authorization')
    if row['effect_count'] > row['max_effect_count']:
        violations.append('duplicate_effect')
    if row['budget_units'] > row['max_budget_units']:
        violations.append('budget')
    return {'pass': bool(row['business_ok']) and not violations, 'hard_violations': violations}


def trial_identities(records):
    if not records:
        raise ValueError('empty_dataset')
    identities = [(r['task_id'], r['attempt']) for r in records]
    if len(set(identities)) != len(identities):
        raise ValueError('duplicate_trial_identity')
    return set(identities)


def summary(records, minimum_trial_success=1.0):
    # This lab's default is deliberately strict. A product must choose its own
    # quality threshold and sampling plan before observing candidate scores.
    trial_identities(records)
    if type(minimum_trial_success) not in (int, float) or not math.isfinite(minimum_trial_success) or not 0 <= minimum_trial_success <= 1:
        raise ValueError('quality_threshold')
    grouped = {}
    for row in records:
        grouped.setdefault(row['task_id'], []).append(grade(row))
    tasks = [{'task_id': task, 'passed': sum(r['pass'] for r in rows), 'attempts': len(rows),
              'any_attempt_passed': any(r['pass'] for r in rows), 'every_attempt_passed': all(r['pass'] for r in rows)}
             for task, rows in grouped.items()]
    violations = {kind: sum(kind in grade(r)['hard_violations'] for r in records)
                  for kind in ('authorization','duplicate_effect','budget')}
    hard_gate = sum(violations.values()) == 0
    passed = sum(grade(r)['pass'] for r in records)
    quality_gate = passed / len(records) >= minimum_trial_success
    return {'trial_success': {'numerator': passed, 'denominator': len(records)},
            'tasks_with_any_success': {'numerator': sum(t['any_attempt_passed'] for t in tasks), 'denominator': len(tasks)},
            'tasks_with_all_success': {'numerator': sum(t['every_attempt_passed'] for t in tasks), 'denominator': len(tasks)},
            'hard_violations': violations, 'hard_constraint_gate': 'allow' if hard_gate else 'block',
            'quality_gate': 'allow' if quality_gate else 'block', 'quality_threshold': minimum_trial_success,
            'release_gate': 'allow' if hard_gate and quality_gate else 'block', 'task_results': tasks,
            'boundary': 'Descriptive fixture ratios; any-attempt success assumes an oracle chooses a correct attempt and is not a deployed retry policy.'}


def calibration(gold, judge):
    if not gold or len(gold) != len(judge) or any(type(v) is not bool for v in gold + judge):
        raise ValueError('calibration_shape')
    tp = sum(g and j for g,j in zip(gold,judge))
    tn = sum(not g and not j for g,j in zip(gold,judge))
    fp = sum(not g and j for g,j in zip(gold,judge))
    fn = sum(g and not j for g,j in zip(gold,judge))
    return {'tp': tp, 'tn': tn, 'fp': fp, 'fn': fn, 'agreement': (tp+tn)/len(gold),
            'precision': tp/(tp+fp) if tp+fp else None, 'recall': tp/(tp+fn) if tp+fn else None,
            'origin': 'authored_reference_labels_and_judge_verdicts'}


def wilson(successes, total, z=1.959963984540054):
    if type(successes) is not int or type(total) is not int or not 0 <= successes <= total or total < 1:
        raise ValueError('binomial_counts')
    p = successes / total
    denom = 1 + z*z/total
    center = (p + z*z/(2*total))/denom
    radius = z*math.sqrt(p*(1-p)/total + z*z/(4*total*total))/denom
    return [max(0, center-radius), min(1, center+radius)]


def zero_failure_upper(n, alpha=0.05):
    if type(n) is not int or n < 1 or not 0 < alpha < 1:
        raise ValueError('zero_failure_parameters')
    return 1 - alpha**(1/n)


def paired_task_deltas(a, b):
    attempts_a, attempts_b = trial_identities(a), trial_identities(b)
    def group(rows):
        result = {}
        for r in rows:
            result.setdefault(r['task_id'], []).append(grade(r)['pass'])
        return result
    left, right = group(a), group(b)
    if left.keys() != right.keys() or attempts_a != attempts_b:
        raise ValueError('unpaired_tasks')
    return [{'task_id': t, 'A': sum(left[t])/len(left[t]), 'B': sum(right[t])/len(right[t]),
             'delta': sum(right[t])/len(right[t])-sum(left[t])/len(left[t])} for t in left]


def demo():
    a, b = fixtures('A'), fixtures('B')
    gold = [True,True,True,True,False,False,False,False]
    judge = [True,True,False,True,True,False,False,True]
    swapped = [True,False,False,True,False,False,False,True]
    return {'origin': 'authored_trials_and_judgments_actual_local_statistics', 'versions': {'A': summary(a), 'B': summary(b)},
            'narration_only_evaluator': {'accepted': len(a), 'false_accepts': sum(not grade(r)['pass'] for r in a)},
            'calibration': calibration(gold, judge),
            'order_swap_fixture': {'disagreements': sum(x != y for x,y in zip(judge,swapped)), 'pairs': len(judge)},
            'paired_task_deltas': paired_task_deltas(a,b),
            'independent_sample_illustration': {'successes': 16, 'n': 24, 'wilson_95': [round(v,6) for v in wilson(16,24)],
                'applies_to_trial_fixture': False, 'reason': 'Repeated authored trials are not independent sampled tasks.'},
            'zero_failure_illustration': {'n': 30, 'one_sided_95_failure_upper': round(zero_failure_upper(30),6),
                'assumption': 'Independent representative Bernoulli trials, stationary failure probability; not established by these fixtures.'},
            'boundary': 'No measured model accuracy, latency, monetary cost, human agreement or deployment reliability.'}


if __name__ == '__main__':
    print(json.dumps(demo(), indent=2, sort_keys=True))

本地运行的预期输出

{
  "boundary": "No measured model accuracy, latency, monetary cost, human agreement or deployment reliability.",
  "calibration": {
    "agreement": 0.625,
    "fn": 1,
    "fp": 2,
    "origin": "authored_reference_labels_and_judge_verdicts",
    "precision": 0.6,
    "recall": 0.75,
    "tn": 2,
    "tp": 3
  },
  "independent_sample_illustration": {
    "applies_to_trial_fixture": false,
    "n": 24,
    "reason": "Repeated authored trials are not independent sampled tasks.",
    "successes": 16,
    "wilson_95": [
      0.467063,
      0.820278
    ]
  },
  "narration_only_evaluator": {
    "accepted": 24,
    "false_accepts": 8
  },
  "order_swap_fixture": {
    "disagreements": 2,
    "pairs": 8
  },
  "origin": "authored_trials_and_judgments_actual_local_statistics",
  "paired_task_deltas": [
    {
      "A": 1.0,
      "B": 1.0,
      "delta": 0.0,
      "task_id": "happy"
    },
    {
      "A": 1.0,
      "B": 1.0,
      "delta": 0.0,
      "task_id": "alternative_path"
    },
    {
      "A": 0.6666666666666666,
      "B": 0.6666666666666666,
      "delta": 0.0,
      "task_id": "timeout"
    },
    {
      "A": 0.0,
      "B": 1.0,
      "delta": 1.0,
      "task_id": "permission"
    },
    {
      "A": 0.6666666666666666,
      "B": 0.6666666666666666,
      "delta": 0.0,
      "task_id": "duplicate"
    },
    {
      "A": 0.6666666666666666,
      "B": 0.6666666666666666,
      "delta": 0.0,
      "task_id": "citation"
    },
    {
      "A": 0.3333333333333333,
      "B": 0.6666666666666666,
      "delta": 0.3333333333333333,
      "task_id": "cancel"
    },
    {
      "A": 1.0,
      "B": 1.0,
      "delta": 0.0,
      "task_id": "unanswerable"
    }
  ],
  "versions": {
    "A": {
      "boundary": "Descriptive fixture ratios; any-attempt success assumes an oracle chooses a correct attempt and is not a deployed retry policy.",
      "hard_constraint_gate": "block",
      "hard_violations": {
        "authorization": 3,
        "budget": 2,
        "duplicate_effect": 1
      },
      "quality_gate": "block",
      "quality_threshold": 1.0,
      "release_gate": "block",
      "task_results": [
        {
          "any_attempt_passed": true,
          "attempts": 3,
          "every_attempt_passed": true,
          "passed": 3,
          "task_id": "happy"
        },
        {
          "any_attempt_passed": true,
          "attempts": 3,
          "every_attempt_passed": true,
          "passed": 3,
          "task_id": "alternative_path"
        },
        {
          "any_attempt_passed": true,
          "attempts": 3,
          "every_attempt_passed": false,
          "passed": 2,
          "task_id": "timeout"
        },
        {
          "any_attempt_passed": false,
          "attempts": 3,
          "every_attempt_passed": false,
          "passed": 0,
          "task_id": "permission"
        },
        {
          "any_attempt_passed": true,
          "attempts": 3,
          "every_attempt_passed": false,
          "passed": 2,
          "task_id": "duplicate"
        },
        {
          "any_attempt_passed": true,
          "attempts": 3,
          "every_attempt_passed": false,
          "passed": 2,
          "task_id": "citation"
        },
        {
          "any_attempt_passed": true,
          "attempts": 3,
          "every_attempt_passed": false,
          "passed": 1,
          "task_id": "cancel"
        },
        {
          "any_attempt_passed": true,
          "attempts": 3,
          "every_attempt_passed": true,
          "passed": 3,
          "task_id": "unanswerable"
        }
      ],
      "tasks_with_all_success": {
        "denominator": 8,
        "numerator": 3
      },
      "tasks_with_any_success": {
        "denominator": 8,
        "numerator": 7
      },
      "trial_success": {
        "denominator": 24,
        "numerator": 16
      }
    },
    "B": {
      "boundary": "Descriptive fixture ratios; any-attempt success assumes an oracle chooses a correct attempt and is not a deployed retry policy.",
      "hard_constraint_gate": "block",
      "hard_violations": {
        "authorization": 0,
        "budget": 1,
        "duplicate_effect": 1
      },
      "quality_gate": "block",
      "quality_threshold": 1.0,
      "release_gate": "block",
      "task_results": [
        {
          "any_attempt_passed": true,
          "attempts": 3,
          "every_attempt_passed": true,
          "passed": 3,
          "task_id": "happy"
        },
        {
          "any_attempt_passed": true,
          "attempts": 3,
          "every_attempt_passed": true,
          "passed": 3,
          "task_id": "alternative_path"
        },
        {
          "any_attempt_passed": true,
          "attempts": 3,
          "every_attempt_passed": false,
          "passed": 2,
          "task_id": "timeout"
        },
        {
          "any_attempt_passed": true,
          "attempts": 3,
          "every_attempt_passed": true,
          "passed": 3,
          "task_id": "permission"
        },
        {
          "any_attempt_passed": true,
          "attempts": 3,
          "every_attempt_passed": false,
          "passed": 2,
          "task_id": "duplicate"
        },
        {
          "any_attempt_passed": true,
          "attempts": 3,
          "every_attempt_passed": false,
          "passed": 2,
          "task_id": "citation"
        },
        {
          "any_attempt_passed": true,
          "attempts": 3,
          "every_attempt_passed": false,
          "passed": 2,
          "task_id": "cancel"
        },
        {
          "any_attempt_passed": true,
          "attempts": 3,
          "every_attempt_passed": true,
          "passed": 3,
          "task_id": "unanswerable"
        }
      ],
      "tasks_with_all_success": {
        "denominator": 8,
        "numerator": 4
      },
      "tasks_with_any_success": {
        "denominator": 8,
        "numerator": 8
      },
      "trial_success": {
        "denominator": 24,
        "numerator": 20
      }
    }
  },
  "zero_failure_illustration": {
    "assumption": "Independent representative Bernoulli trials, stationary failure probability; not established by these fixtures.",
    "n": 30,
    "one_sided_95_failure_upper": 0.095034
  }
}
  • A=16/24、B=20/24,二者发布关卡均 block。
  • A 至少/每次任务=7/8、3/8;B=8/8、4/8。
  • 校准 TP/TN/FP/FN=3/2/2/1;叙述误接受=8。
查看运行环境、输出和校验记录 →

代码示例

阈值敏感性是策略选择

把明确假设的minimum_trial_success=0.8与教学默认1.0比较。B的20/24满足0.8,却仍有硬违规,发布仍阻断。改阈值改变决策策略,不改变20/24观察,也不证明Agent改进。

本层验收任务

运行模块,按正文通过向量重建A/B试次、至少/每次任务与硬违规;按八组可见输入手算校准,指出FP/FN编号。独立实现grade_copy并用指定案例对照参考。 继续同项目真实评测扩展,保留自己的首次失败、修复及不变检查器结果。 继续证据合同v2练习,保留原始失败、自己的修复与不变检查器结果。 补做语义复核练习,分开教学参考、声明完整性与实际人工签署。 重放同任务复核修订回合,保留初审、旧表失效和新绑定记录。 独立完成三个来源复核练习,保留提交、改稿及人工比较记录。

逐条验收自评

正在读取此浏览器记录…

收起答案,检查理解

数据集多追加了一条相同的通过记录,框架应如何处理?

延伸原理与知识练习

遇到不熟悉的原理,先阅读实现、连续追问和迁移案例,再独立说明前提与边界。作答与笔记保存到原有账号记录。

本专题的全部关联解析与练习(5 道)

依据与验证范围

原理依据来自公开资料;数字、案例和任务是本站教学设计。离线实验验证本页注明的范围,学习效果仍需通过独立任务与反馈判断。