针对「base model 答对、Agent 答错」的 case,通过 6 步 prompt pipeline 自动定位失败根因,输出 5 大类 / 13 子类的结构化归因。
背景:DeepSeek V3 → V4 升级后,Agent 在 MedXPertQA 上出现性能回归。本项目用于规模化定位回归原因。根因 taxonomy 与 prompt 设计见
agent_failure_analysis_plan.md。
- Coverage check — gold answer 是否被召回 chunks 覆盖 + 污染风险
- Chunk scan — 并行批量给每个 chunk 打 relevance 分 + 抽 key_snippet
- Aggregation(纯代码)— 聚合 supporting / fragmented snippets
- Sufficiency — 综合判定 sufficient / partial / insufficient
- 条件分支 — sufficient → 推理失败定位(D1–D5);insufficient → 检索定位(query / retrieval / rerank)
- Synthesize — 输出
primary_cause+confidence+recommendation
pip install -r requirements.txt
# test_data 不入库,需自备 JSONL
python run_analysis.py --input data/cases.jsonl --limit 10 --trace results/trace.jsonl
Docker(NAS 挂载场景):
./scripts/run_docker.sh --build # 任务参数在脚本顶部「任务参数」区块改
CLI 参数:--input / --output / --conf / --limit / --case_ids / --trace / --problem_type
| 字段 | 说明 |
|---|---|
STRONG_MODEL / CHEAP_MODEL |
深推理 / 批量扫描用的模型;api_key 留空则回退环境变量 *_API_KEY |
analysis.outer_scope |
rerank(v1,前 ~634 块) / embedding(v2,全召回) |
analysis.concurrency |
并行 case 数(默认 5) |
analysis.resume |
跳过 output 中已存在的 case_id |
run_analysis.py async CLI 入口
conf.yaml 模型 / 并发 / 输出配置
src/
pipeline/ 6 步编排 + chunk 聚合
prompts/templates/ 7 个 Jinja2 prompt 模板(改 prompt 改这里)
schema/types.py 全部 Pydantic 数据模型 + Enum
services/llms/ async OpenAI 客户端 + JSON repair + 重试
utils/ 增量写入 / 全链路 trace
scripts/ Docker 构建 / 结果绘图
tests/ pytest
输入 JSONL(每行一个 case):id / question / gold_answer / base_model_answer / agent_answer / sub_queries / recall_list[] / chunks_with_ids
输出 JSONL:每行含 6 步中间结果 + final.primary_cause;单 case 出错以 error 字段标记,不中断整体运行。
- Async-first:所有 LLM 调用走
AsyncOpenAI+Semaphore控并发 - Pydantic v2 + Enum 强约束:schema 集中在
src/schema/types.py - Prompt 与代码分离:所有 prompt 在
src/prompts/templates/*.md,不在代码里拼字符串 - JSON 容错:
llm.py内置json_repairfallback - Trace 全量:
--trace记录每次调用的 token / 耗时 / 成本
test_data/、results/、各类 tarball 与本地缓存均按 .gitignore 排除,不入库。