From 70a2f5b504b9b0fb90493d7775d9f384bdf42935 Mon Sep 17 00:00:00 2001 From: 16337 <1633794139@qq.com> Date: Tue, 31 Mar 2026 18:22:27 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=EF=BC=9A=E6=89=8B=E5=8A=A8?= =?UTF-8?q?=E5=BB=BA=E5=8D=95=E4=BC=98=E5=85=88=E4=BA=8E=E5=B7=A5=E5=8D=95?= =?UTF-8?q?=E5=A4=84=E7=90=86=E7=BB=93=E6=9E=9C=E5=9B=BE=E7=89=87=E4=B8=8A?= =?UTF-8?q?=E4=BC=A0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/services/agent_dispatcher.py | 37 +++++++++++++++++++++++++++++++- app/services/session_manager.py | 2 +- 2 files changed, 37 insertions(+), 2 deletions(-) diff --git a/app/services/agent_dispatcher.py b/app/services/agent_dispatcher.py index a0142bd..a43ac9c 100644 --- a/app/services/agent_dispatcher.py +++ b/app/services/agent_dispatcher.py @@ -56,9 +56,12 @@ class AgentDispatcher: self._pending_images[user_id] = [] session = get_session_manager().get(user_id) + normalized_content = content.strip() try: - reply = await self._handle_manual_order_message(user_id, session, content.strip()) + reply = self._maybe_start_manual_order_from_text(session, normalized_content) + if reply is None: + reply = await self._handle_manual_order_message(user_id, session, normalized_content) if reply is None: reply = await self._langgraph_chat(user_id, content) except Exception as e: @@ -99,6 +102,10 @@ class AgentDispatcher: permanent_url = oss.get_permanent_url(object_key) presign_url = oss.get_presigned_url(object_key) + if session.state == "waiting_manual_order_image": + del presign_url + return await self._start_manual_order_flow(session, permanent_url) + # 3. 检查用户是否有待处理工单 handling_alarm_id = self._find_handling_alarm(user_id) if handling_alarm_id: @@ -196,8 +203,36 @@ class AgentDispatcher: "请回复区域编号。" ) + @staticmethod + def _maybe_start_manual_order_from_text(session, content: str) -> Optional[str]: + """用户明确提出创建工单时,优先进入手动建单流程。""" + if session.state != "idle": + return None + + trigger_phrases = ( + "创建工单", + "新建工单", + "手动工单", + "手动上报", + "我要创建工单", + "我要上报", + "上报工单", + ) + if not any(phrase in content for phrase in trigger_phrases): + return None + + session.reset() + session.state = "waiting_manual_order_image" + return "请先上传现场图片,我会在收到图片后引导您选择区域并补充备注。" + async def _handle_manual_order_message(self, user_id: str, session, content: str) -> Optional[str]: """处理手动工单创建状态机。""" + if session.state == "waiting_manual_order_image": + if content in {"取消", "算了", "不用了"}: + session.reset() + return "已取消本次手动工单创建。" + return "请先上传现场图片。若不需要创建工单,回复“取消”即可。" + if session.state == "waiting_manual_order_area": area = self._match_area_option(content, session.pending_manual_order_area_options) if not area: diff --git a/app/services/session_manager.py b/app/services/session_manager.py index a3aa8d1..dabb425 100644 --- a/app/services/session_manager.py +++ b/app/services/session_manager.py @@ -18,7 +18,7 @@ class UserSession: def __init__(self, user_id: str): self.user_id = user_id - self.state = "idle" # idle / waiting_close_photo / waiting_manual_order_area / waiting_manual_order_remark / waiting_manual_order_confirm + self.state = "idle" # idle / waiting_close_photo / waiting_manual_order_image / waiting_manual_order_area / waiting_manual_order_remark / waiting_manual_order_confirm self.pending_image_url = "" # 暂存的图片 COS key self.pending_analysis = "" # VLM 分析结果描述 self.pending_alarm_type = "" # VLM 识别的告警类型