"""Deliver the original model body when the user requests a report.""" import re _REQUEST = re.compile( r"(?:生成|输出|编写|撰写|写|制作|形成|起草|给我|提供|整理(?:为|成)|出)" r"[^。!?;\n]{0,38}(?:报告|简报|排查纪要)|(?:分析|对比|质量|复盘|管理|诊断)(?:报告|简报)\s*[。!!??]*$" ) _SKIP = re.compile(r"(?:不用|不必|不要|无需|不需要|别|避免|不(?=(?:再)?(?:生成|输出|编写|撰写|写|制作|形成|起草|提供|出)))\s*(?:另行|另外|单独|再)?\s*[^。!?;\n]{0,18}(?:报告|简报|排查纪要)") def requested(question, task=None): if not isinstance(question, str) or _SKIP.search(question): return False selection = (task or {}).get("aggregateSelection") or {} return bool(_REQUEST.search(question) or _REQUEST.search(selection.get("requestQuestion", ""))) def attach(event, question): """Use the original assistant body for an explicitly requested deliverable.""" event.pop("_verifiedReportNarrative", None) if event.get("type") != "result": return event.pop("reportMarkdown", None) if not requested(question, event.get("agentTask")): return answer = event.get("modelAnswer") if not isinstance(answer, str) or not answer: return event["reportMarkdown"] = answer if not event.get("reportTitle"): heading = re.search(r"^#{1,6} +([^\n]+)", answer, re.M) event["reportTitle"] = heading[1] if heading else "质量分析报告"