31Determinism & Replay

L4P1

Agent 默认非确定(sampling 有 temperature),线上 bug 难复现。Replay 是 harness 工程的命脉之一。

Replay 要求:

· 固定 seed:temperature=0 不够(浮点不确定),需要模型 API 支持 seed 参数。

· 记录所有 tool_result:replay 时不真调外部,直接喂保存的 result。

· 记录模型版本:同一 prompt 在 Sonnet 4.5 和 Opus 4.5 行为不同,版本必须固定。

· 记录 env:工作目录、环境变量、可用 tools 集合。

Snapshot 结构:

{
  trace_id, timestamp, model_version,
  messages: [...],
  tool_calls: [{name, args, result, latency}, ...],
  env: {cwd, vars, tools},
  final_state: {files_changed, exit_status}
}

难点:外部 API 调用非幂等。replay 时不能真发邮件、真支付。解法:replay 模式下所有外发 tool 切换到 mock,从 snapshot 读 result。

典型用途:线上 incident postmortem、regression test、debug 卡死、给训练团队提供 failure case。

速查
"昨天那个 bug 怎么复现?"——三件套:snapshot trace + 模型版本固定 + 外部调用 mock。缺一项就无法稳定 replay。