This commit is contained in:
zyp
2026-11-24 15:38:28 +08:00
parent a6740c4509
commit c27f84cf91
20 changed files with 823 additions and 42 deletions
@@ -6,6 +6,7 @@ import re
from app.modules.work_assistant.model_gateway import ModelOutputInvalid
from app.modules.work_assistant.review_jobs import JobDeferred
from app.modules.work_assistant.personnel_workflow import BEHAVIOR_CONTRACT
def row_fingerprint(section, row):
@@ -87,11 +88,27 @@ headline与finding/record/assessment一起阅读;action是下一步建议,
每个输入项目恰好返回一项,不添加新建议,不改写候选,不扩大原文结论。'''
def invents_leadership(row, issue):
"""A topic heading cannot be reinterpreted as an assertion of leadership.
This narrow review-contract check never waives a claim that actually says
led, independently performed, or completed the work.
"""
claim=issue.get('claim','');reason=issue.get('reason','')
prose=' '.join(row.get(field,'') for field in ('headline','finding','action'))
return (issue.get('confirmed') is True and claim in row.get('headline','')
and bool(re.match(r'^(?:聚焦|关注|参与)',claim))
and '主导' in reason and '协助' in issue.get('source_quote','')
and not re.search(r'主导|牵头|独立|已完成.*纠错|完成.*修改',prose))
def reassess_findings(candidate, cache, adjudicated, attempts, invoke, remaining, material_for_rows, excluded=()):
"""Recheck repeated semantic objections once per exact row; never bypass code validation."""
pending=[]
for row in candidate['findings']:
fingerprint=row_fingerprint('findings',row)
if fingerprint not in excluded and invents_leadership(row,adjudicated.get(fingerprint,{})):
cache[fingerprint]=[]
if attempts.get(row['key'],0)>=2 and cache.get(fingerprint) and fingerprint not in adjudicated and fingerprint not in excluded:
pending.append((fingerprint,row,cache[fingerprint]))
if not pending:return
@@ -124,7 +141,7 @@ def reassess_findings(candidate, cache, adjudicated, attempts, invoke, remaining
return value
material=material_for_rows([row for _,row,_ in pending])
try:
verdict=invoke(ADJUDICATION_INSTRUCTION,{'adjudication':True,'items':items,'material':material},schema,
verdict=invoke(ADJUDICATION_INSTRUCTION+'\n'+BEHAVIOR_CONTRACT,{'adjudication':True,'items':items,'material':material},schema,
timeout_seconds=min(95,remaining),max_tokens=2000,transform=accept)
except (ModelOutputInvalid,json.JSONDecodeError):
# An optional second opinion may be unusable. Keep every original
@@ -136,5 +153,7 @@ def reassess_findings(candidate, cache, adjudicated, attempts, invoke, remaining
# Transactional merge: a bad or incomplete verdict cannot clear any objections.
for issue in verdict['issues']:
fingerprint=pending[issue['index']][0]
if invents_leadership(pending[issue['index']][1],issue):
issue={**issue,'confirmed':False,'reason':'原判断仅概括参与的工作主题,未声称主导或独立完成;复核不得添加候选没有断言的含义。'}
cache[fingerprint]=[issue['reason']] if issue['confirmed'] else []
adjudicated[fingerprint]=deepcopy(issue)