跳到正文
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. 分析与回归

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

资深 · 解释取舍

按部署策略选择重试指标与不确定性

本层目标:说明重复观察、区间与零失败何时能够支持发布决策。

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

独立取证,分别过关

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

把部署策略从单次改为最多三次只读尝试,加一个会误判的选择器。至少一次成功假设有人能识别正确候选。真实选择器会提前接受错答案,所以要评测整个重试/验证策略、停止规则、共享预算与误接受。写工具在允许的重试中保持同一持久业务意图。

在相同独立抽样任务上配对 A/B,并报告任务差。重复试次共享难度时,总体推断按任务抽样或 bootstrap;把 24 条相关的编写试次当 24 个独立伯努利样本不成立。八个挑选的教学任务不能建立代表性部署分布。

实验用 Wilson 区间演示数学。假设独立样本 24 次成功 16 次,区间约为 [0.467063,0.820278];输出明确说该假设不适用于编写的重复夹具。NIST 比例区间。

若 n 次独立、有代表性且失败概率稳定的伯努利观察中零失败,单侧 95% 上界为 1−0.05^(1/n)。n=30 时约 0.095034,来自 P(零失败)=(1−q)^n。它是基于假设的演示,不是本实验或生产风险的估计,也不是零风险的断言。严重罕见故障还需要对抗回归、独立风险关卡和监测。

比较每次都成功要求、只读验证后重试与人工升级,它们对可用性、预算、延迟和误接受有不同代价。模型或裁判升级前用共享锚点校准,再保留独立 held-out;版本化评分规则,避免把裁判变动误当 Agent 变化。

一次具体策略比较

假设只读回答在一个截止时间和总预算中最多尝试三次,写动作则只有一个审批业务操作、传输可重复投递。选择器可能第一轮误接便停止,后面即使存在好候选也没被交付。所以测实际返回策略成功与选择器误接受,不能只问组中是否曾有成功。

A/B前定义目标任务分布及独立任务样本,共享难度的重复尝试采用逐任务配对差和聚类重采样。看到结果前写minimum_trial_success及必要的切片质量门槛,实验默认1.0是演示,不是从生产风险推出来的要求。权限/效果/预算、质量、语义审阅覆盖及未测项保持独立。30次零失败只能在所述抽样和观察假设下支持那个演示上界。

运行实验,观察反例

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

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

继续做进阶研究实验

让评测读取事件和实际效果

沿同一研究任务的实际检查点、事件和服务方回执,区分运行成功、结果契约和未评分的语义质量。

阅读全文与故障分析 → · 下载实验包 ↓

python3 cli.py memory-put
python3 cli.py submit
python3 cli.py run
python3 evaluate.py
python3 -m unittest discover -s . -p test_lab.py -v

保留证据,逐条核对

  • 从事件和检查点解释 passed 的各项依据。
  • 分别指出 scope、引用、幂等效果和步骤预算的可信观测。
  • semantic_support 与 model_quality 是 not_scored,不能把 passed 写成模型质量成绩。

默认使用确定性摘要函数和合成文档;评测真实运行轨迹与机械约束,没有验证真实模型的语义支持。

代码示例

输出未变而测量器改变

新裁判重评未变Agent输出,分数提升可能是裁判/rubric漂移而非质量变化。保留共享锚点,用同一测量器重评两版本后再归因。

本层验收任务

为单次写动作与三次只读回答规定发布评测。定义任务抽样、选择器误接受、重试预算、配对比较、区间假设和严重故障回归关卡。

逐条验收自评

正在读取此浏览器记录…

收起答案,检查理解

30 次样本没有授权失败,引用 95% 二项上界还需要什么假设?

延伸原理与知识练习

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

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

依据与验证范围

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