feat(agent): form pipeline + collection prompt workflow@20261021
- merge main: workflow/20261021 (collection prompt adds step-5 mandatory time readback-confirm before routing; non-motor/0003 branch rework; accident_cause unified schema), updated eval suites (photo_skip/ button_guidance rewritten, no_false trimmed to asr, new non_motor_vehicle + time_confirmation with form/reply assertions), runner gains form/formMatches/replyMatches expectations - prompts/collection.md regenerated from 20261021; extraction prompt archived (contentExtract description, 6-key whitelist) - collect: extraction call per turn (extraction.md + current time/form injected), merge follows 更新表单 semantics (meaningful values only, number/string equality, diff -> turn_patch); accident_fields now uses external form keys - backend: form_update flows to ChatResult and SSE formUpdate event (stream emits prefix, FormUpdate, body) - fields: FORM_FIELDS whitelist with strict type validation - verified: 155 unit tests; golden evals on real model - photo_skip 4/4, no_false 2/2, photo_button_guidance 12/12, non_motor_vehicle 14/14, collection_skip 10/12, time_confirmation 1/2; remaining 3 failures are model sequence/literal-template adherence, recorded in plan appendix
This commit is contained in:
+30
-1
@@ -16,7 +16,7 @@ from .clock import Clock, SystemClock, validate_accident_time
|
||||
|
||||
ACCIDENT_FIELD_KEYS = (
|
||||
"ywrysw", "ywfjdc", "ywmtc", "bjrjs",
|
||||
"sgfssj", "sfsgxc", "jdcsl", "sgyy",
|
||||
"sgfssj", "sfsgxc", "jdcsl", "sgyy", "accident_cause",
|
||||
)
|
||||
PERSON1_FIELD_KEYS = (
|
||||
"xm1", "hpzl1", "hphm1", "sfzmhm1", "sfzmwh1", "sjhm1", "sjwh1", "csbw1",
|
||||
@@ -28,6 +28,35 @@ KNOWN_FIELD_KEYS = frozenset(
|
||||
ACCIDENT_FIELD_KEYS + PERSON1_FIELD_KEYS + PERSON2_FIELD_KEYS
|
||||
)
|
||||
|
||||
# 事故表单字段(来源:workflow@20261021「文本内容提取事故信息」白名单 +
|
||||
# 「更新表单」code 节点的差量合并语义)
|
||||
FORM_FIELDS: dict[str, type] = {
|
||||
"has_injury": bool,
|
||||
"has_non_motor_vehicle_hit": bool,
|
||||
"is_on_scene": bool,
|
||||
"vehicle_count": int,
|
||||
"accident_time": str,
|
||||
"accident_cause": str,
|
||||
}
|
||||
|
||||
|
||||
def validate_form_update(data: dict) -> dict:
|
||||
"""按白名单与类型校验提取输出;非法键/类型丢弃(对应更新表单的忽略语义)。"""
|
||||
validated = {}
|
||||
for key, value in (data or {}).items():
|
||||
spec = FORM_FIELDS.get(key)
|
||||
if spec is None:
|
||||
continue
|
||||
if spec is bool and not isinstance(value, bool):
|
||||
continue # 布尔字段严格 bool,不接受 0/1/字符串
|
||||
if spec is int and (isinstance(value, bool) or not isinstance(value, int)):
|
||||
continue
|
||||
if spec is str and not isinstance(value, str):
|
||||
continue
|
||||
validated[key] = value
|
||||
return validated
|
||||
|
||||
|
||||
TIME_FIELDS = frozenset({"sgfssj"}) # 事故发生时间:需时间校验
|
||||
|
||||
# 布尔语义字段:明确肯定/否定之外(模糊、ASR 破碎)不得猜测。
|
||||
|
||||
Reference in New Issue
Block a user