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

SYSTEMATIC LEARNING / 分层专题

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

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

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

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

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

本层学习目录

先补齐必要概念

适合:能跟踪请求与结果状态的读者。

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

原理怎样一步步成立?

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

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

  2. 2
    运行记录

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

  3. 3
    硬条件

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

  4. 4
    语义审阅

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

  5. 5
    比较报告

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

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

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

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

  2. 采集可信事实

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

  3. 分维度判定

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

  4. 分析与回归

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

入门 · 理解原理

先定义成功,再看流畅答案

本层目标:区分业务结果、硬约束、语义审查和重复尝试的问题。

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

独立取证,分别过关

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

Agent 可以说“退款完成”却没有副作用回执,也可以读禁用租户文档后写漂亮报告。结果与过程约束需要不同证据:业务状态核对最终结果,权限/副作用事件核对禁止行为,开放文本再审查声明质量。

运行前定义初始任务、允许动作、预期结果与硬限制。本实验 pass=business_ok 且无授权、重复效果或预算违规。高 narration_score 不能抵消禁用副作用。lookup→verify→finish 与 cache→verify→finish 在所需事实成立时都可通过。

分开任务和试次:八个任务各跑三次是 24 条试次记录,但仍只有八个不同任务上下文。单次成功问一遍结果;至少一次成功问一组中有没有正确候选;每次成功问观察到的所有尝试是否都可用。神谕挑中正确答案不等于真实选择器,它可能接受错候选。任务/试次与结果定义。

编写夹具能确定性测试指标定义与评测器错误,不能测真实模型质量、学习效果或生产可靠性。每个比例都要带来源说明。

一条记录与关卡含义

每次尝试记录business_ok、authorized、effect_count/max_effect_count、budget_units/max_budget_units。真实接入时business_ok必须从业务工件或回执取得,这些教学记录则提供编写标签;评分器没有观察在线退款。

  1. 流畅越权尝试的business_ok=True、authorized=False、effect_count=1,即使narration_score=0.95仍在授权关卡失败。
  2. 无害却没完成任务的尝试为business_ok=False、authorized=True、effect_count=0、budget_units=0,没有硬违规,业务任务仍失败。
  3. 合法的cache→verify→finish替代路径,只要所需事实相同就可以通过;不能要求逐步匹配参考轨迹。

修复后的summary分别报告hard_constraint_gate、quality_gate、quality_threshold、release_gate。只过硬筛查不等于可以发布。本实验minimum_trial_success默认1.0,要求观察到的每次尝试都通过业务/规则契约。这是明确教学阈值,不是通用生产要求;真实发布须事先声明质量门槛并核对其他相关维度。零成功且无违规的数据应为hard allow、quality block、release block。

“结果判定器”指判断预期业务结果的来源或程序;重试讨论里的“神谕选择器”则是假设永远选对的选择器,真实验证器不具备这个保证。

运行实验,观察反例

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

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。
查看运行环境、输出和校验记录 →

代码示例

业务失败却没有危险副作用

只读回答可以有权限、在预算内、没有重复效果,却仍答错。安全筛查可allow,质量结论须失败,所以修复后的发布决定结合两门,不能把无危险写当任务成功。

本层验收任务

用正文三类固定记录写发布契约,分开结果、授权、副作用次数、预算及语义审阅。评测前声明质量门槛,分类合法替代路径与无害却业务失败的案例。

逐条验收自评

正在读取此浏览器记录…

收起答案,检查理解

B 的平均通过数提升,却仍重复退款一次,均值能支持发布吗?

延伸原理与知识练习

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

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

依据与验证范围

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