统一:DSH 智能分析、Top100 与图表静默恢复
接入 DSH 专用运行时和对话界面,保留模型原始回答,支持会话分页、连续追问与显式报告。 补齐组合筛选、各维度 Top100、分组查询到排名图的转换,图表故障静默省略并基于保存数据自动恢复。 优化报告风格、图表顺序和表格换行,更新接入说明及构建输入。 验证:独立目录前后端构建通过;118 项 Java、102 项前端、102 项图表、14 项 DSH 应用和 13 项组合筛选检查通过。 仅提交相关源码、锁定依赖与测试;不包含凭据、会话、业务数据或本地产物。
This commit is contained in:
+94
-18
@@ -51,10 +51,15 @@ def run_native_exploration(*, request, task, authority, actor_root, delegated, c
|
||||
'sessionId': request['sessionId'], 'releaseId': request['releaseId'],
|
||||
'task': task, 'protocol': identity})
|
||||
started = time.monotonic()
|
||||
_, _, model, base_url = manager.ensure_instance(actor_root, request['sessionId'],
|
||||
expected_actor_id=request['actorId'], model_connection=connection)
|
||||
client = _authenticate(actor_root, base_url)
|
||||
timings['nativeStartup'] = round((time.monotonic() - started) * 1000)
|
||||
engine = request.get('runtimeEngine', 'NAO')
|
||||
model = connection[2]
|
||||
if engine == 'NAO':
|
||||
_, _, model, base_url = manager.ensure_instance(actor_root, request['sessionId'],
|
||||
expected_actor_id=request['actorId'], model_connection=connection)
|
||||
client = _authenticate(actor_root, base_url)
|
||||
timings['nativeStartup'] = round((time.monotonic() - started) * 1000)
|
||||
elif engine != 'DSH':
|
||||
raise ValueError('分析引擎无效。')
|
||||
emit({'type': 'progress', 'message': '正在根据实际结果自主调查…', 'executionMode': 'native_agent'})
|
||||
started = time.monotonic()
|
||||
investigation_started = started
|
||||
@@ -66,19 +71,38 @@ def run_native_exploration(*, request, task, authority, actor_root, delegated, c
|
||||
('planningAndReview', 'taskConfirmation', 'nativeStartup'))
|
||||
+ round((time.monotonic() - investigation_started) * 1000))
|
||||
emit(event)
|
||||
accumulator, native_status, native_reason, stop_succeeded = _sse_request(
|
||||
client=client, base_url=base_url, model=model, question=request['question'],
|
||||
release_id=request['releaseId'], context=context, chat_id=None,
|
||||
session_state=state, session_id=request['sessionId'], actor_root=actor_root,
|
||||
emit=track_progress, cancel_event=cancel_event, timeout=native_timeout(),
|
||||
prior_evidence_files=prior_evidence_files, turn_id=request['turnId'])
|
||||
if engine == 'DSH':
|
||||
from dsh_agent_runtime import run_dsh_agent
|
||||
from nao_native_exploration import NativeExplorationTools, native_model_view
|
||||
from nao_quality_tools import tool_definition
|
||||
from nao_runtime_policy import turn_deadline
|
||||
tools = NativeExplorationTools(delegated=delegated, evidence_dir=actor_root/'evidence',
|
||||
task=task, identity={**identity, 'releaseId':request['releaseId']},
|
||||
state_path=actor_root/'private'/'native-exploration-state.json')
|
||||
def authorize_dsh():
|
||||
if cancel_event.is_set():
|
||||
raise RuntimeError('cancelled')
|
||||
delegated.call('/api/analysis/model-authorization', method='GET')
|
||||
accumulator, native_status, native_reason, stop_succeeded = run_dsh_agent(
|
||||
actor_root=actor_root, connection=connection, question=request['question'],
|
||||
context=context, task=task, identity=identity, turn_id=request['turnId'],
|
||||
cancel_event=cancel_event, emit=track_progress,
|
||||
tool_handler=lambda args:native_model_view(tools.quality_data(args)),
|
||||
authorize=authorize_dsh, tool_definition=tool_definition(native_protocol=True), deadline=turn_deadline())
|
||||
else:
|
||||
accumulator, native_status, native_reason, stop_succeeded = _sse_request(
|
||||
client=client, base_url=base_url, model=model, question=request['question'],
|
||||
release_id=request['releaseId'], context=context, chat_id=None,
|
||||
session_state=state, session_id=request['sessionId'], actor_root=actor_root,
|
||||
emit=track_progress, cancel_event=cancel_event, timeout=native_timeout(),
|
||||
prior_evidence_files=prior_evidence_files, turn_id=request['turnId'])
|
||||
timings['investigation'] = round((time.monotonic() - started) * 1000)
|
||||
draft_path = actor_root / 'private' / 'native-draft.json'
|
||||
_atomic_json(draft_path, {'turnId': request['turnId'], 'executionId': identity['executionId'],
|
||||
'answer': accumulator.answer, 'status': native_status,
|
||||
'reason': native_reason})
|
||||
if cancel_event.is_set() or native_status == 'CANCELLED':
|
||||
result = {'type': 'result', 'engine': 'NAO', 'status': 'CANCELLED', 'answer': '',
|
||||
result = {'type': 'result', 'engine': engine, 'status': 'CANCELLED', 'answer': '',
|
||||
'stopReason': '用户停止', 'finishReason': 'cancelled', 'agentTask': task,
|
||||
'protocol': identity, 'executionMode': 'native_agent', 'toolCalls': accumulator.tool_calls,
|
||||
'toolCount': len(accumulator.tool_calls), 'timeline': accumulator.timeline,
|
||||
@@ -119,7 +143,14 @@ def run_native_exploration(*, request, task, authority, actor_root, delegated, c
|
||||
and complete_scopes is not None and bool(documents)
|
||||
and not missing and not progress.get('halted'))
|
||||
if native_status != 'COMPLETED' and not corrected_tool_errors and not controlled_no_progress:
|
||||
missing.append('自主调查未正常结束(' + str(native_reason or native_status) + '),已保留核实结果。')
|
||||
reason_label = {
|
||||
'authorization_unavailable': '授权检查暂未完成',
|
||||
'authorization_rejected': '本轮授权检查被拒绝',
|
||||
'authorization_revoked': '本轮授权已失效',
|
||||
'timeout': '已达到本轮时间上限',
|
||||
'transport_error': '运行连接中断',
|
||||
}.get(native_reason, str(native_reason or native_status))
|
||||
missing.append('自主调查未正常结束(' + reason_label + '),已保留核实结果。')
|
||||
elif native_status == 'COMPLETED' and not natural_finish:
|
||||
missing.append('自主调查未收到有效的正常结束信号。')
|
||||
if not documents:
|
||||
@@ -138,6 +169,50 @@ def run_native_exploration(*, request, task, authority, actor_root, delegated, c
|
||||
summary_warnings = ['部分重点图表未能完整展示;已保留核实文字和表格。']
|
||||
missing = list(dict.fromkeys(str(item) for item in missing if item))
|
||||
answer = accumulator.answer if isinstance(accumulator.answer, str) else ''
|
||||
checked_answer = None
|
||||
narrative_binding = 'not_assessed'
|
||||
if engine == 'DSH' and not documents:
|
||||
narrative_binding = 'rejected'
|
||||
answer = '本轮尚未取得可核验的查询证据,不能形成正式分析结论。请检查数据范围或重新分析。'
|
||||
missing.append('未取得可核验查询证据,调查草稿未作为分析结论发布。')
|
||||
if engine == 'DSH' and documents and answer.strip():
|
||||
# A successful agent loop is not a business-content acceptance. Keep its
|
||||
# draft privately and bind the published narration to signed evidence.
|
||||
from nao_evidence_finalizer import synthesize_native, FinalizationUnavailable
|
||||
from nao_protocol_execution import _platform_visual_context, _save_composition
|
||||
checked_context = {**context, '_autonomousAnswer': True,
|
||||
'_platformVisuals': _platform_visual_context(visuals)}
|
||||
emit({'type': 'progress', 'message': '正在核对分析结论与正式证据…',
|
||||
'executionMode': 'native_agent'})
|
||||
synthesis_started = time.monotonic()
|
||||
try:
|
||||
checked_answer = synthesize_native(base_url=connection[0], api_key=connection[1],
|
||||
model=model, question=request['question'], evidence=documents,
|
||||
cancel_event=cancel_event, context=checked_context, native_answer=answer)
|
||||
_save_composition(checked_answer, actor_root, request['turnId'])
|
||||
answer = checked_answer.get('answer', '')
|
||||
checked_complete = (checked_answer.get('evidenceSufficient') is True
|
||||
and checked_answer.get('finishReason') == 'stop'
|
||||
and not (checked_answer.get('titleRequired') and not checked_answer.get('titleValid')))
|
||||
narrative_binding = 'verified_composition' if checked_complete else 'incomplete'
|
||||
missing.extend(checked_answer.get('missingEvidence', []))
|
||||
missing.extend(checked_answer.get('titleMissingEvidence', []))
|
||||
if narrative_binding != 'verified_composition':
|
||||
missing.append('报告结论尚未全部通过证据核验。')
|
||||
except (FinalizationUnavailable, ValueError, OSError):
|
||||
narrative_binding = 'rejected'
|
||||
missing.append('报告结论未通过证据核验,已保留查询证据。')
|
||||
answer = '本轮已取得查询证据,但报告结论未通过核验。请查看已核实的图表与数据,或重新分析。'
|
||||
timings['synthesis'] = round((time.monotonic()-synthesis_started)*1000)
|
||||
if cancel_event.is_set():
|
||||
result = {'type':'result', 'engine':engine, 'status':'CANCELLED', 'answer':'',
|
||||
'stopReason':'用户停止', 'finishReason':'cancelled', 'agentTask':task,
|
||||
'protocol':identity, 'executionMode':'native_agent',
|
||||
'toolCalls':accumulator.tool_calls, 'timeline':accumulator.timeline,
|
||||
'queryEvidenceRefs':[], 'protocolEvidence':[], 'visuals':[],
|
||||
'visualState':'not_requested'}
|
||||
emit(result)
|
||||
return result
|
||||
original_refs = _answer_evidence_refs(answer)
|
||||
complete_receipt_ids = {p.get('queryId') for p in receipts if isinstance(p, dict)
|
||||
and p.get('executionId') == identity['executionId'] and isinstance(p.get('queryId'), str)
|
||||
@@ -174,7 +249,8 @@ def run_native_exploration(*, request, task, authority, actor_root, delegated, c
|
||||
and bool(conclusion_ids) and not unresolved_refs
|
||||
and len(cited_ids if original_refs else background_ids) <= 40)
|
||||
narrative_complete = bool(answer.strip() and natural_finish
|
||||
and (native_status == 'COMPLETED' or corrected_tool_errors))
|
||||
and (native_status == 'COMPLETED' or corrected_tool_errors)
|
||||
and (engine != 'DSH' or narrative_binding == 'verified_composition'))
|
||||
charts_complete = not visual_warnings
|
||||
complete = bool(data_complete and narrative_complete and not missing)
|
||||
if warnings or visual_warnings:
|
||||
@@ -187,12 +263,12 @@ def run_native_exploration(*, request, task, authority, actor_root, delegated, c
|
||||
'finishReasons': list(accumulator.finish_reasons),
|
||||
'originalBodyCharacters': len(answer), 'originalBodyNonempty': bool(answer.strip()),
|
||||
'narrativeComplete': narrative_complete, 'dataComplete': data_complete,
|
||||
'narrativeFactBinding': 'not_assessed', 'citedEvidenceRefs': sorted(cited_refs),
|
||||
'narrativeFactBinding': narrative_binding, 'citedEvidenceRefs': sorted(cited_refs),
|
||||
'unresolvedEvidenceRefs': unresolved_refs, 'missingEvidence': missing,
|
||||
'visualWarnings': visual_warnings, 'notices': list(dict.fromkeys(summary_warnings))})
|
||||
result = {'type': 'result', 'engine': 'NAO', 'status': 'COMPLETED' if complete else 'PARTIAL',
|
||||
'answer': answer, 'readingSummary': None,
|
||||
'reportTitle': None, 'agentTask': task, 'protocol': identity,
|
||||
result = {'type': 'result', 'engine': engine, 'status': 'COMPLETED' if complete else 'PARTIAL',
|
||||
'answer': answer, 'readingSummary': (checked_answer or {}).get('readingSummary'),
|
||||
'reportTitle': (checked_answer or {}).get('reportTitle'), 'agentTask': task, 'protocol': identity,
|
||||
'executionMode': 'native_agent', 'completionMethod': 'native_autonomous_analysis',
|
||||
'stopReason': 'evidence_finalized' if complete else 'evidence_incomplete',
|
||||
'finishReason': ('stop' if narrative_complete else
|
||||
@@ -204,7 +280,7 @@ def run_native_exploration(*, request, task, authority, actor_root, delegated, c
|
||||
'answerQuality': {'version': 1, 'dataComplete': data_complete,
|
||||
'narrativeComplete': narrative_complete,
|
||||
'chartsComplete': charts_complete,
|
||||
'narrativeFactBinding': 'not_assessed',
|
||||
'narrativeFactBinding': narrative_binding,
|
||||
'citedEvidenceRefs': sorted(cited_refs),
|
||||
'backgroundEvidenceQueryIds': background_ids,
|
||||
'unresolvedEvidenceRefs': unresolved_refs,
|
||||
|
||||
Reference in New Issue
Block a user