mirror of
https://github.com/ThearchyHelios/AgentLab.git
synced 2026-11-21 16:21:57 +00:00
可点击证据第四期:结论句由模型裁判;只引单元格的问数据图能发成受管
一、结论句裁判
- 报告节点新增 claims: judge:写完、核对完之后,把结论句和它引用的证据摘录交给裁判模型,
判为支持 / 部分支持 / 不支持 / 不是结论,附一句理由;判定只标注,不改写正文
- 送裁判的句子按固定规则预筛:带引用的、含方向词或因果词的送去判,短句、过渡句不送
- 证据摘录:指标写名称、值和原式;查询给 SQL 前 300 字和被引用的行,被引用的列一定给到;遮罩列一律不给;
规则里写明「数字已经由系统核对过,不要复算」
- 一份报告合并成一次调用,超出句数就分批;结构化输出失败时退回 JSON 解析,再失败记为未裁判
- 裁判模型的优先级:节点上写的 > 设置里的「证据裁判模型」> Copilot 的模型;思考关闭;
和写作模型相同时给警告(等于自己审自己)
- rewrite_once(默认关):把不支持的句子和理由交回写作者只改这几句,再裁一次;
改写稿冒出原稿没有的问题就不采用,保留原稿和原来的判定
二、成本上限
- 每份报告的句数、金额、时长,探索运行每次点击的金额,全局每日金额,每一项都可以自定义,也都可以设成不限;
默认 40 句、$0.05、30 秒,每次点击 $0.01,每天 $2
- 调用前先估算,超出上限按优先级截断:先判带引用的,再判含方向词、因果词的,其余记为未裁判并写明「已到上限」;
不报错,也不让报告失败
- 每日花费按本地日期计数,持久化在设置表里;重跑同一次运行不重复计费;价格目录里没有的模型只计次数,并写明估不出金额
三、正式运行与探索运行
- 正式运行在报告节点内裁判,判定写进报告文档、随文档封存;不支持的按 on_unsupported(degrade / withhold)降档或不予出具,
裁判没跑成记缺口,不能判完整出具
- 探索运行按需裁判:POST /api/runs/{id}/evidence/judge,点开哪句判哪句;判定作为 evidence.judged 事件追加在封存之后,
标「封存后追加」,封存核对仍然一致;只读封存范围内的工件;同一句不重复判;运行在裁判期间被接着跑时不记录
- 正式运行调这个接口返回 409,写明「正式运行的裁判在节点内完成」
四、治理与自动修复
- G3 放开 judge:受管级别写 judge 必须写预算(judge.max_cost_usd,或显式写 null 表示不限)
- 发布前自动修复:缺预算时给选项(默认金额 / 不限),不替人选;
从 require_citation 改成 judge 不算降低要求,judge 改回 off、withhold 放宽成 degrade 算降低要求
- Copilot 手册:受管模板可以写 judge 并带预算;问数据按需裁判,不替人打开结论句策略
五、界面
- 结论句句末放徽标:支持 ◆、部分支持 ◇、不支持 ! 整句浅底、未裁判 ?;不用表示「已核对」的绿色;n / N 也跳到不支持的句子
- 证据面板里「模型的解释」:带「模型判断 · 模型名 · 非确定」,封存后追加的另外标出;
「请模型判断这句」只在探索运行、还没判过时出现,触顶时写明已到上限和怎么调
- 出具横幅多一段结论句计数;设置页新增「证据裁判」一组(裁判模型、各项上限、今日花费),设成不限时写明费用受什么约束;
报告节点可以配 judge;运行轨迹里裁判相关的事件都有中文标题
六、门禁修正
- 引用模式下,图里没有口径卡(只引查询单元格)的,出具契约不再要求 metrics_from,受管门禁也不再要求 required:
strict 加 cells 已经保证每个数都点得开、对不上就不予出具;有口径卡的照旧要求。
以前问数据的图怎么都发不成受管,Copilot 补上契约也会被判「冒出新的问题」作废
This commit is contained in:
@@ -1,5 +1,6 @@
|
||||
from __future__ import annotations
|
||||
|
||||
import math
|
||||
import re
|
||||
from collections import defaultdict
|
||||
from enum import StrEnum
|
||||
@@ -423,31 +424,101 @@ def _check_report_sources(node: GraphNode, spec: GraphSpec, result: ValidationRe
|
||||
|
||||
|
||||
#: 报告撰写节点的结论句策略(claims)。off:结论句不参与判档(默认,保持以前的行为);
|
||||
#: require_citation:没挂引用的结论句计入缺口、按出具档位降档。judge(模型裁判)是后续版本的
|
||||
#: require_citation:没挂引用的结论句计入缺口、按出具档位降档。这两档是确定性的(发布前自动修复
|
||||
#: 给人选的也只有这两档)
|
||||
REPORT_CLAIMS = ("off", "require_citation")
|
||||
CLAIMS_LATER = "结论句裁判在后续版本支持"
|
||||
#: judge:结论句由另一个模型按证据逐句判断(engine/judge.py),子配置写在节点的 judge 里
|
||||
CLAIMS_JUDGE = "judge"
|
||||
CLAIMS_VALUES = (*REPORT_CLAIMS, CLAIMS_JUDGE)
|
||||
#: judge 子配置能写的键。三个上限写 null 表示不限;没写的键运行时取设置里的默认(设置 → judge 一组)
|
||||
JUDGE_KEYS = ("provider", "model", "max_claims", "max_cost_usd", "timeout_s", "rewrite_once", "on_unsupported")
|
||||
#: 证据不支持时正式运行怎么判档:degrade 降档(默认)/ withhold 不予出具。探索运行只标注
|
||||
JUDGE_ON_UNSUPPORTED = ("degrade", "withhold")
|
||||
|
||||
|
||||
def claims_problem(value: Any) -> str | None:
|
||||
"""claims 的取值有什么问题,没问题返回 None。校验和报告撰写节点执行时报的是同一句话。"""
|
||||
if value in (None, "") or (isinstance(value, str) and value in REPORT_CLAIMS):
|
||||
if value in (None, "") or (isinstance(value, str) and value in CLAIMS_VALUES):
|
||||
return None
|
||||
if value == "judge":
|
||||
return f"claims 写的是 judge:{CLAIMS_LATER},现在只能写 off 或 require_citation"
|
||||
return f"claims 只能是 {' / '.join(REPORT_CLAIMS)},写的是 {value!r}"
|
||||
return f"claims 只能是 {' / '.join(CLAIMS_VALUES)},写的是 {value!r}"
|
||||
|
||||
|
||||
def _positive(value: Any, *, integer: bool = False) -> bool:
|
||||
if isinstance(value, bool) or not isinstance(value, (int, float)) or not math.isfinite(value) or value <= 0:
|
||||
return False
|
||||
return not integer or int(value) == value
|
||||
|
||||
|
||||
def judge_problems(value: Any) -> list[tuple[str, str]]:
|
||||
"""claims: judge 的子配置有什么问题:[(字段, 人话)],没问题返回 []。校验和节点执行时报的是同一句话。
|
||||
|
||||
上限写 null 就是不限(和没写不一样:没写取设置里的默认)。键写错了也报:写成 max_cost 的预算会被
|
||||
悄悄当成没写、按默认值花钱。
|
||||
"""
|
||||
if value in (None, ""):
|
||||
return []
|
||||
if not isinstance(value, dict):
|
||||
return [("judge", f'judge 要写成一个对象,比如 {{"max_cost_usd": 0.05, "max_claims": 40}},写的是 {value!r}')]
|
||||
out: list[tuple[str, str]] = []
|
||||
for key, item in value.items():
|
||||
field = f"judge.{key}"
|
||||
if key not in JUDGE_KEYS:
|
||||
out.append((field, f"judge 里不认识「{key}」:能写的是 {'、'.join(JUDGE_KEYS)}"))
|
||||
elif key in ("provider", "model") and item is not None and not isinstance(item, str):
|
||||
what = "模型接入的名字" if key == "provider" else "模型 id"
|
||||
out.append((field, f"judge.{key} 要写{what}(字符串),不写或写 null 就用设置里的「证据裁判模型」,"
|
||||
f"写的是 {item!r}"))
|
||||
elif key == "max_claims" and item is not None and not _positive(item, integer=True):
|
||||
out.append((field, f"judge.max_claims 要写正整数(每份报告最多判几句),写 null 表示不限,写的是 {item!r}"))
|
||||
elif key == "max_cost_usd" and item is not None and not _positive(item):
|
||||
out.append((field, "judge.max_cost_usd 要写大于 0 的金额(美元,每份报告的裁判花费上限),"
|
||||
f"写 null 表示不限,写的是 {item!r}"))
|
||||
elif key == "timeout_s" and item is not None and not _positive(item):
|
||||
out.append((field, f"judge.timeout_s 要写大于 0 的秒数(每份报告的裁判时长上限),写 null 表示不限,"
|
||||
f"写的是 {item!r}"))
|
||||
elif key == "rewrite_once" and not isinstance(item, bool):
|
||||
out.append((field, f"judge.rewrite_once 只能是 true 或 false,写的是 {item!r}"))
|
||||
elif key == "on_unsupported" and item not in JUDGE_ON_UNSUPPORTED:
|
||||
out.append((field, f"judge.on_unsupported 只能是 {' / '.join(JUDGE_ON_UNSUPPORTED)},写的是 {item!r}"))
|
||||
return out
|
||||
|
||||
|
||||
def _check_report_claims(node: GraphNode, spec: GraphSpec, result: ValidationResult) -> None:
|
||||
"""claims 写错了(包括还不支持的 judge)挡住运行:执行时报告节点照样会报这一句,
|
||||
与其跑完取数、算完口径卡才死在写报告那一步,不如在画图时说破。
|
||||
"""claims 写错了挡住运行:执行时报告节点照样会报这一句,与其跑完取数、算完口径卡才死在写报告
|
||||
那一步,不如在画图时说破。claims 是 judge 时再查 judge 子配置的形状;裁判模型和写作模型写成
|
||||
同一个的给警告——等于自己审自己。
|
||||
|
||||
和运行时同一个取值规则:节点上没写就取图级 defaults(NodeContext.cfg)。
|
||||
"""
|
||||
value = node.config.get("claims")
|
||||
if value in (None, ""):
|
||||
value = spec.defaults.get("claims")
|
||||
def effective(key: str) -> Any:
|
||||
value = node.config.get(key)
|
||||
return spec.defaults.get(key) if value in (None, "") else value
|
||||
|
||||
value = effective("claims")
|
||||
if problem := claims_problem(value):
|
||||
result.add(problem, node_id=node.id, field="claims", code="report.claims_invalid")
|
||||
if value != CLAIMS_JUDGE:
|
||||
return
|
||||
judge = effective("judge")
|
||||
for field, message in judge_problems(judge):
|
||||
result.add(message, node_id=node.id, field=field, code="report.judge_invalid")
|
||||
judge_model = judge.get("model") if isinstance(judge, dict) else None
|
||||
if isinstance(judge_model, str) and judge_model and judge_model == effective("model"):
|
||||
result.add(f"裁判模型和写作模型都是「{judge_model}」:等于自己审自己,模型写错的地方它多半也看不出来。"
|
||||
"给 judge.model 换一个不同的模型", level="warning", node_id=node.id, field="judge.model",
|
||||
code="report.judge_same_model")
|
||||
|
||||
|
||||
def contract_needs_metrics(contract: dict[str, Any]) -> bool:
|
||||
"""出具契约要不要写 metrics_from(指标来自哪几张口径卡)。
|
||||
|
||||
旧写法按数值回指叙述,没有口径卡就无从回指,一定要写。引用模式(report_from)下,数字回指靠
|
||||
报告里的引用标记:只引查询单元格(cells)的问数据图根本没有口径卡,不该逼它写;契约里列了
|
||||
required / expected 指标的,指标总得有个来处,照样要写。运行时 io.py 也是这么判的。
|
||||
"""
|
||||
if contract.get("report_from") in (None, ""):
|
||||
return True
|
||||
return bool(contract.get("required") or contract.get("expected"))
|
||||
|
||||
|
||||
def _check_report_from(node: GraphNode, report_from: Any, spec: GraphSpec,
|
||||
@@ -542,7 +613,7 @@ def validate_graph(spec: GraphSpec) -> ValidationResult:
|
||||
# 报成 error,两档发布和运行前都挡住
|
||||
result.add("出具契约必须是一个 JSON 对象", node_id=node.id, field="contract",
|
||||
code="contract.not_object")
|
||||
elif contract and not contract.get("metrics_from"):
|
||||
elif contract and not contract.get("metrics_from") and contract_needs_metrics(contract):
|
||||
result.add("出具契约缺 metrics_from(指标来自哪个「口径卡」节点)",
|
||||
node_id=node.id, field="contract.metrics_from", code="contract.metrics_from_missing")
|
||||
if isinstance(contract, dict) and contract.get("report_from") not in (None, ""):
|
||||
|
||||
Reference in New Issue
Block a user