修复:智能分析空回答与工具结束条件冲突

统一自主分析工具范围与执行前校验,严格核验正常结束、最终正文和图表恢复状态,并显示空回答及恢复失败原因。

包含两次已上线修复及回归测试,保留已有回答与业务数据。

验证:1101 项 Python、469 项前端、97 项后端测试通过;前后端构建和真实模型、页面验收通过。
This commit is contained in:
2026-11-03 08:56:49 +08:00
parent 7ffb5cdb9c
commit 52d92c95d8
20 changed files with 387 additions and 37 deletions
+17 -8
View File
@@ -62,20 +62,29 @@ def capability_context(task=None):
}
def apply_platform_tools(payload):
"""Do not advertise a native SQL-result renderer for quality API evidence."""
QUALITY_NATIVE_TOOLS = frozenset({'read', 'list', 'grep', 'search', 'mcp_call', 'mcp_connect'})
def apply_platform_tools(payload, *, native_agent=False):
"""Expose tools compatible with platform evidence and answer completion."""
tools = payload.get('tools')
if not isinstance(tools, list): return payload
kept = [tool for tool in tools if not (isinstance(tool, dict)
and isinstance(tool.get('function'), dict)
and tool['function'].get('name') == 'display_chart')]
if len(kept) == len(tools): return payload
allowed = QUALITY_NATIVE_TOOLS if native_agent else QUALITY_NATIVE_TOOLS | {'story'}
# Clarification/warehouse selection are upstream stop conditions with native
# UI replies that this platform cannot consume. SQL, renderers and writers
# also use a different data/artifact lifecycle. Unknown tools stay disabled.
tools = tools if isinstance(tools, list) else []
kept = [tool for tool in tools if isinstance(tool, dict) and tool.get('type') == 'function'
and isinstance(tool.get('function'), dict) and isinstance(tool['function'].get('name'), str)
and tool['function'].get('name') in allowed]
if kept: payload['tools'] = kept
else: payload.pop('tools', None)
choice = payload.get('tool_choice')
if ((isinstance(choice, dict) and (choice.get('function') or {}).get('name') == 'display_chart')
kept_names = {tool['function']['name'] for tool in kept}
choice_name = choice.get('function', {}).get('name') if isinstance(choice, dict) and isinstance(choice.get('function'), dict) else None
if ((isinstance(choice, dict) and choice_name not in kept_names)
or not kept and choice in ('auto', 'required')):
payload.pop('tool_choice', None)
if not kept: payload.pop('parallel_tool_calls', None)
return payload