File size: 7,672 Bytes
158258b | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 | #!/usr/bin/env python3
"""Render the summary into the markdown tables the report embeds.
Kept separate from `run_analysis.py` so the numbers and their presentation
can be regenerated independently: re-run this after any change to the
feature extractors and the report's tables update without hand-editing.
python analysis/make_tables.py # per-agent tables into analysis/out/ and docs/results/
"""
from __future__ import annotations
import os
import sys
sys.path.insert(0, os.path.dirname(os.path.abspath(__file__)))
from run_analysis import AGENT_ROOTS, OUT_DIR, ROOT, build, summarize # noqa: E402
from trace_analysis.probes import probe_cohort # noqa: E402
from trace_analysis.stats import within_task_z # noqa: E402
DOC_NAMES = {
"claude": ("claude_code_agent_trace_tables_2026-10.md", "Claude Code (claude-opus-5)", "claude_code_agent_trace_analysis_2026-10.md"),
"codex": ("codex_sdk_agent_trace_tables_2026-10.md", "Codex SDK (gpt-5.6-sol)", "codex_sdk_agent_trace_analysis_2026-10.md"),
}
DOC_HEADER = """# 附录:{title} Trace 逐项数据表(2026-10)
本文件由 `python analysis/make_tables.py` 生成,配合
[`{doc}`]({doc}) 阅读。
修改特征抽取后重跑该脚本即可刷新,不要手工编辑表格内容。
## 高层要点 / Takeaways
1. **这是附录,不是结论。** 这里只有逐 run、逐特征的**全量数值**,
解读一律在 [`{doc}`]({doc}) 里,两边不重复。
2. **要查一个具体的 run 发生了什么**,从这里的表定位到 run id,
再去 `analysis/out/*/narratives/` 读那一份的可读流水账。
3. **跨 benchmark 不要直接比绝对分** —— 用 `z in task` 那一列(同 benchmark 内的 z-score),
本项目所有相关性分析都基于它。
4. **`cohort` 列决定一行算不算数**:只有 `primary` 和 `recovered` 进入分析,
其余是被我们自己的基础设施掐断的,不是 agent 放弃。
> This file is a generated appendix: per-run, per-feature raw numbers only. All interpretation
> lives in the analysis document it accompanies. Compare across benchmarks using the `z in task`
> column, never the raw accuracy; and note that only `primary` and `recovered` rows enter the
> analysis — the rest were cut short by our own infrastructure, not by the agent.
列的含义:
- **cohort** — `primary` 为 agent 自己跑完并被打分;`recovered` 为研究循环完整、仅收尾消息被我们的网关掐断。
- **z in task** — 最终准确率在**同一 benchmark 内部**的 z-score。跨 benchmark 的绝对分不可比,所有相关性分析都基于这一列。
- **versions** — 按 `evaluate.py --model-path` 去重的独立模型版本数,即真实迭代轮数。
- **idle h** — 没有任何前台或后台任务在跑的墙钟时长。
---
"""
def table(rows: list[dict], cols: list[tuple[str, str]]) -> str:
out = ["| " + " | ".join(h for _, h in cols) + " |", "|" + "---|" * len(cols)]
for r in rows:
cells = []
for k, _ in cols:
v = r.get(k)
cells.append("" if v is None else (f"{v:.3f}" if isinstance(v, float) else str(v)))
out.append("| " + " | ".join(cells) + " |")
return "\n".join(out)
def build_tables(agent: str, results_root: str) -> None:
runs, feats = build(results_root)
s = summarize(feats)
inc = [f for f in feats if f.cohort in ("primary", "recovered")]
keep = {f.run_id for f in inc}
s["prose_probes"] = probe_cohort([r for r in runs if r.run_id in keep])
z = within_task_z(inc)
parts: list[str] = ["<!-- generated by analysis/make_tables.py; do not hand-edit -->", ""]
parts += ["## cohort", "", table(
[{"k": k, "v": v} for k, v in s["cohort_counts"].items()]
+ [{"k": f"excluded: {k}", "v": v} for k, v in s["exclusions"].items()],
[("k", "bucket"), ("v", "traces")],
), ""]
parts += ["## per benchmark", "", table(
s["per_task"],
[
("task", "benchmark"),
("n_runs", "runs"),
("mean_accuracy", "accuracy"),
("mean_turns", "turns"),
("mean_eval_calls", "official evals"),
("mean_model_versions", "model versions"),
("mean_dead_air_h", "idle h"),
("mean_tail_idle_h", "h after best"),
("mean_oom_hits", "OOM hits"),
("mean_cost_usd", "cost $"),
],
), ""]
parts += ["## per run", "", table(
sorted(
[
{
"run": f.run_id.rsplit("_", 1)[0],
"when": f.run_id.rsplit("_", 1)[1],
"cohort": f.cohort,
"acc": f.accuracy,
"z": round(z.get(f.run_id, 0.0), 2),
"turns": f.turns,
"vers": f.n_distinct_model_versions,
"evals": f.n_eval_calls,
"oom": f.error_signals.get("oom", 0),
"errs": f.tool_errors,
"idle_h": round(f.dead_air_h or 0, 2),
"cost": round(f.cost_usd, 2),
}
for f in inc
],
key=lambda r: (r["run"], r["when"]),
),
[
("run", "task / base model"),
("when", "stamp"),
("cohort", "cohort"),
("acc", "accuracy"),
("z", "z in task"),
("turns", "turns"),
("vers", "versions"),
("evals", "evals"),
("oom", "OOM"),
("errs", "tool errors"),
("idle_h", "idle h"),
("cost", "cost $"),
],
), ""]
parts += ["## techniques (runs with evidence, of %d)" % len(inc), "", table(
[{"t": k, "n": v, "pct": round(100 * v / len(inc), 1)} for k, v in s["technique_run_counts"].items()],
[("t", "technique"), ("n", "runs"), ("pct", "%")],
), ""]
parts += ["## technique vs relative outcome", "", table(
s["technique_effects"],
[("technique", "technique"), ("n_with", "with"), ("n_without", "without"),
("mean_z_with", "mean z with"), ("mean_z_without", "mean z without"), ("delta_z", "Δz")],
), ""]
parts += ["## feature vs relative outcome (Spearman)", "", table(
s["feature_correlations"],
[("feature", "feature"), ("rho_vs_within_task_z", "rho"), ("n", "n")],
), ""]
parts += ["## rerun spread (same cell, two runs)", "", table(
s["rerun_variance"],
[("task", "benchmark"), ("base_model", "base model"), ("min", "worse"), ("max", "better"), ("spread", "spread")],
), ""]
parts += ["## prose habits", "", table(
[{"probe": k, **v} for k, v in s["prose_probes"].items() if not k.startswith("anywhere_")],
[("probe", "habit"), ("runs_with_evidence", "runs"), ("of", "of"), ("pct", "%"), ("surface", "where")],
), ""]
parts += ["## datasets used (top 25)", "", table(
[{"d": k, "n": v} for k, v in list(s["dataset_run_counts"].items())[:25]],
[("d", "dataset"), ("n", "runs")],
), ""]
path = os.path.join(OUT_DIR, agent, "tables.md")
os.makedirs(os.path.dirname(path), exist_ok=True)
with open(path, "w") as fh:
fh.write("\n".join(parts))
print(f"wrote {path}")
fname, title, analysis_doc = DOC_NAMES[agent]
doc = os.path.join(ROOT, "docs", "results", fname)
with open(doc, "w") as fh:
fh.write(DOC_HEADER.format(title=title, doc=analysis_doc) + "\n".join(parts[1:]))
print(f"wrote {doc}")
def main() -> None:
for agent, root in AGENT_ROOTS.items():
build_tables(agent, root)
if __name__ == "__main__":
main()
|