"""Shared capabilities for planning, querying, repair and evidence composition. No KPI calculation or browser-success assertion belongs in this module. """ DEFAULT_QUALITY_ANALYSIS_POLICY = ( '【默认业务口径】未指定阶段的“不良/报废/废品TOP”按产品规格的黑片+亮片报废总重排序,附同规格正式综合合格率;' '用户明确产业部或业务分组等排名维度时保留该维度;仅未明确排名对象时默认产品规格。' '只有明确指定黑片/亮片/分别排名才拆阶段,只有明确指定缺陷/具体项目才转为来源缺陷排名。' '合计报废总重不是把两套阶段Top拼接,也不是合并投入后重算率。' '单期合计排名的root及ranking节点都必须stages=[]、fields=[rate,scrapWeight],dimensionStages对应维度=[];' 'root stages是输出口径,不能因数据来自黑片和亮片就写[black,bright]。' '单个ranking节点即提供同一组Top产品的报废总重与综合率,不能额外用base metrics代替各规格合格率。' '例如未限定阶段的产品不良TOP5:dimensions=[product]、stages=[]、fields=[rate,scrapWeight]、dimensionStages={"product":[]},' 'queryPlan=[{"nodeId":"rank","purpose":"ranking","dimension":"product","limit":5,"fields":["rate","scrapWeight"],' '"stages":[],"selector":{"kind":"base"},"comparisonRequired":false,"visualType":"bar","visualPreference":"auto"}];' 'comparisonRequired=false、comparisonPeriod=null、trendRequired=false。追问TOP产品沿用期间、筛选和数量。' '单期较差产品名单未问原因时,用静态合计ranking直接完成,数量按用户要求或当前展示策略;无需增加自主调查节点或额外比较期。' '近期表现较差的产品以报废总重和综合率共同说明实际影响;未明确按最低率排名时,不能只选极小批量的零合格率。' '按报废重量选出的Top只能支持所列对象之间的合格率比较;没有完整合格率排序证据,不能声称某项是整个授权总体的最低合格率。' ) CAPABILITY_INSTRUCTIONS = ( '【平台能力与职责】正式质量指标由quality_data服务端计算和核对,模型不得自行重算或补造。' '正式黑片修正分母可能产生超过100%的合法黑片率和综合率;有效正式值照常引用,不截断、不仅因超过100%判异常。' '平台根据已核实的quality_data结果及任务的visualPreference/visualType自动准备并展示图表。' '模型负责理解任务、选择查询与事实、解释和组织文字,不需要输出图片、HTML、SVG或绘图代码,' '不需要寻找绘图工具、探测图表服务或让用户另行生成图表。' '不要调用原生display_chart:它读取原生SQL查询结果,与quality_data来源不兼容;本平台图表不经过该工具。' '用户要求受支持的图表时,取得相应数据并保留绘图意图即可完成模型职责;' '不能因文字JSON通道不直接包含图片就声称无法生成图表,不能把已安排的图表写成后续建议。' '模型无法观察浏览器渲染是否成功,不得声称已看见图表或替前端宣布渲染成功。' '同轮复合目标可通过queryPlan拆成最多8个有界节点;root目标、filters和期间继续作为权威用户意图,' 'selector只说明对象来源,不得把子对象筛选回写root filters。' ) def capability_context(task=None): task = task if isinstance(task, dict) else {} plan = task.get('queryPlan') if isinstance(task.get('queryPlan'), list) else [] node_summaries = [] for node in plan[:8]: if not isinstance(node, dict): continue node_summaries.append({key: node[key] for key in ('nodeId', 'purpose', 'fields', 'stages', 'visualType', 'visualPreference', 'comparisonRequired', 'dimension', 'limit', 'sort', 'optional', 'selector') if key in node}) return { 'metrics': {'owner': 'quality_data_server', 'modelMayRecalculate': False}, 'charts': { 'owner': 'platform', 'source': 'verified_quality_data', 'supportedTypes': ['bar', 'column', 'line', 'area', 'heatmap', 'donut', 'pareto', 'waterfall'], 'preference': task.get('visualPreference', 'auto'), 'requestedType': task.get('visualType'), 'drawingToolRequired': False, 'modelCanObserveBrowserRendering': False, }, 'queryPlan': {'maxNodes': 8, 'maxScopedReads': 40, 'nodeSummary': node_summaries, 'periodOwner': 'rootTask', 'scopeOwner': 'protocolServer', 'source': 'verified_node_scope_protocol'}, } def apply_platform_tools(payload): """Do not advertise a native SQL-result renderer for quality API evidence.""" 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 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') or not kept and choice in ('auto', 'required')): payload.pop('tool_choice', None) return payload def primary_query_required(task): """A source-defect TOP does not need unrelated parent KPI prefetching.""" return not (task.get('kind') == 'analysis' and set(task.get('dimensions', [])) == {'defect'} and not task.get('comparisonRequired') and not task.get('comparisonPeriod') and not set(task.get('fields', [])) - {'scrapWeight'})