修复:智能分析空回答与工具结束条件冲突
统一自主分析工具范围与执行前校验,严格核验正常结束、最终正文和图表恢复状态,并显示空回答及恢复失败原因。 包含两次已上线修复及回归测试,保留已有回答与业务数据。 验证:1101 项 Python、469 项前端、97 项后端测试通过;前后端构建和真实模型、页面验收通过。
This commit is contained in:
@@ -763,6 +763,17 @@ class ConversationAccumulator:
|
||||
return value
|
||||
return ""
|
||||
|
||||
@property
|
||||
def final_answer_ready(self) -> bool:
|
||||
if not self.answer or any(call.get('status') == 'started' for call in self.tool_calls):
|
||||
return False
|
||||
if not self.tool_calls:
|
||||
return True
|
||||
last_tool = max((i for i, entry in enumerate(self.timeline)
|
||||
if entry.get('kind') in ('tool_start', 'tool_result')), default=-1)
|
||||
return any(entry.get('kind') == 'assistant' and str(entry.get('text') or '').strip()
|
||||
for entry in self.timeline[last_tool + 1:])
|
||||
|
||||
def status(self, *, cancel_cause: str | None = None, stop_succeeded: bool | None = None,
|
||||
transport_failed: bool = False) -> tuple[str, str | None]:
|
||||
if cancel_cause == "user":
|
||||
@@ -781,18 +792,27 @@ class ConversationAccumulator:
|
||||
return ("PARTIAL" if self.answer else "FAILED", "transport_or_stream_error")
|
||||
if self.tool_error and (self.unattributed_tool_error or any(call["status"] == "failed" and not call.get("recovered") for call in self.tool_calls)):
|
||||
return ("PARTIAL" if self.answer else "FAILED", "mcp_error")
|
||||
if self.answer and (self.done_received or "stop" in self.finish_reasons):
|
||||
if (self.final_answer_ready and self.finish_reasons[-1] == 'stop'
|
||||
and stop_succeeded is not False):
|
||||
return "COMPLETED", "stop"
|
||||
return ("PARTIAL" if self.answer else "FAILED", "incomplete")
|
||||
|
||||
|
||||
def _contains_error_flag(value: Any) -> bool:
|
||||
if isinstance(value, dict):
|
||||
if value.get("isError") is True or value.get("error"):
|
||||
if (any(value.get(flag) is True for flag in ('isError', 'mcpValidationError', 'mcpAuthRequired'))
|
||||
or value.get('success') is False or value.get('error')):
|
||||
return True
|
||||
return any(_contains_error_flag(item) for item in value.values())
|
||||
# Inspect only known response envelopes. Rows, source cells, notes and
|
||||
# arbitrary JSON strings are business data, not nested tool outcomes.
|
||||
content = value.get('content')
|
||||
if isinstance(content, list) and any(isinstance(part, dict) and part.get('type') == 'text'
|
||||
and _contains_error_flag(part.get('text')) for part in content):
|
||||
return True
|
||||
return _contains_error_flag(value['structuredContent']) if isinstance(value.get('structuredContent'), dict) else False
|
||||
if isinstance(value, list):
|
||||
return any(_contains_error_flag(item) for item in value)
|
||||
return any(isinstance(part, dict) and part.get('type') == 'text'
|
||||
and _contains_error_flag(part.get('text')) for part in value)
|
||||
if isinstance(value, str) and len(value) <= 64 * 1024:
|
||||
stripped = value.strip()
|
||||
if stripped.startswith(("{", "[")):
|
||||
@@ -1922,6 +1942,10 @@ def _sse_request(
|
||||
ready_state: dict[str, Any] = {"identity": None, "since": None}
|
||||
|
||||
def completion_ready() -> bool:
|
||||
# The watchdog can observe a stale halted exploration state between a
|
||||
# natural model finish and the stream's trailing [DONE] marker.
|
||||
if accumulator.done_received or (accumulator.finish_reasons and accumulator.finish_reasons[-1] == 'stop'):
|
||||
return False
|
||||
if autonomous:
|
||||
progress_path = actor_root / 'private' / 'native-exploration-state.json'
|
||||
if not _require_private_regular_file(progress_path):
|
||||
@@ -2630,6 +2654,7 @@ def _run_turn(payload: dict[str, Any], *, stdout: Any = sys.stdout, stdin: Any =
|
||||
from nao_protocol_execution import execute
|
||||
request['_autonomousAnswer'] = protocol.get('autonomousEnabled') is True
|
||||
if authority['task'].get('executionMode') == 'native_agent':
|
||||
model_gate.native_agent = True
|
||||
from nao_native_run import run_native_exploration
|
||||
return run_native_exploration(request=request, task=authority['task'], authority=authority,
|
||||
actor_root=actor_root, delegated=delegated, connection=selected_connection,
|
||||
@@ -3108,6 +3133,7 @@ def _run_turn(payload: dict[str, Any], *, stdout: Any = sys.stdout, stdin: Any =
|
||||
if model_gate is not None:
|
||||
try:
|
||||
_atomic_json(actor_root/'private'/'last-model-audit.json',{'model':selected_model,'requests':model_gate.request_audit,
|
||||
'rejectedToolCalls':model_gate.rejected_tool_calls if isinstance(model_gate.rejected_tool_calls,int) else 0,
|
||||
'rejectedStaleRequests':model_gate.rejected_stale_requests if isinstance(model_gate.rejected_stale_requests,int) else 0})
|
||||
except (OSError,TypeError,ValueError):pass
|
||||
model_gate.close()
|
||||
|
||||
Reference in New Issue
Block a user