|
@@ -21,6 +21,7 @@ from pqai_agent.history_dialogue_service import HistoryDialogueService
|
|
from pqai_agent.chat_service import ChatServiceType
|
|
from pqai_agent.chat_service import ChatServiceType
|
|
from pqai_agent.message import MessageType, Message
|
|
from pqai_agent.message import MessageType, Message
|
|
from pqai_agent.toolkit.lark_alert_for_human_intervention import LarkAlertForHumanIntervention
|
|
from pqai_agent.toolkit.lark_alert_for_human_intervention import LarkAlertForHumanIntervention
|
|
|
|
+from pqai_agent.toolkit.lark_sheet_record_for_human_intervention import LarkSheetRecordForHumanIntervention
|
|
from pqai_agent.user_manager import UserManager
|
|
from pqai_agent.user_manager import UserManager
|
|
|
|
|
|
class DummyVectorMemoryManager:
|
|
class DummyVectorMemoryManager:
|
|
@@ -344,17 +345,21 @@ class DialogueManager:
|
|
|
|
|
|
def _send_human_intervention_alert(self, reason: Optional[str] = None) -> None:
|
|
def _send_human_intervention_alert(self, reason: Optional[str] = None) -> None:
|
|
time_str = datetime.now().strftime("%Y-%m-%d %H:%M:%S")
|
|
time_str = datetime.now().strftime("%Y-%m-%d %H:%M:%S")
|
|
|
|
+ staff_info = f"{self.staff_profile.get("agent_name", "未知")}[{self.staff_id}]"
|
|
|
|
+ user_info = f"{self.user_profile.get("nickname", "未知")}[{self.user_id}]"
|
|
alert_message = f"""
|
|
alert_message = f"""
|
|
人工介入告警
|
|
人工介入告警
|
|
- 员工: {self.staff_profile.get("agent_name", "未知")}[{self.staff_id}]
|
|
|
|
- 用户: {self.user_profile.get("nickname", "未知")}[{self.user_id}]
|
|
|
|
|
|
+ 员工: {staff_info}
|
|
|
|
+ 用户: {user_info}
|
|
时间: {time_str}
|
|
时间: {time_str}
|
|
原因:{reason if reason else "未知"}
|
|
原因:{reason if reason else "未知"}
|
|
- 最近对话:"""
|
|
|
|
|
|
+ 最近对话:
|
|
|
|
+ """
|
|
|
|
|
|
alert_message = textwrap.dedent(alert_message)
|
|
alert_message = textwrap.dedent(alert_message)
|
|
# 添加最近的对话记录
|
|
# 添加最近的对话记录
|
|
recent_dialogues = self.dialogue_history[-5:]
|
|
recent_dialogues = self.dialogue_history[-5:]
|
|
|
|
+ dialogue_to_send = []
|
|
role_map = {'assistant': '客服', 'user': '用户'}
|
|
role_map = {'assistant': '客服', 'user': '用户'}
|
|
for dialogue in recent_dialogues:
|
|
for dialogue in recent_dialogues:
|
|
if not dialogue['content']:
|
|
if not dialogue['content']:
|
|
@@ -362,9 +367,13 @@ class DialogueManager:
|
|
role = dialogue['role']
|
|
role = dialogue['role']
|
|
if role not in role_map:
|
|
if role not in role_map:
|
|
continue
|
|
continue
|
|
- alert_message += f"\n[{role_map[role]}]{dialogue['content']}"
|
|
|
|
|
|
+ dialogue_to_send.append(f"[{role_map[role]}]{dialogue['content']}")
|
|
|
|
+ alert_message += '\n'.join(dialogue_to_send)
|
|
|
|
|
|
LarkAlertForHumanIntervention().send_lark_alert_for_human_intervention(alert_message)
|
|
LarkAlertForHumanIntervention().send_lark_alert_for_human_intervention(alert_message)
|
|
|
|
+ LarkSheetRecordForHumanIntervention().send_lark_sheet_record_for_human_intervention(
|
|
|
|
+ staff_info, user_info, '\n'.join(dialogue_to_send), reason
|
|
|
|
+ )
|
|
|
|
|
|
def resume_from_human_intervention(self) -> None:
|
|
def resume_from_human_intervention(self) -> None:
|
|
"""从人工介入状态恢复"""
|
|
"""从人工介入状态恢复"""
|