|
@@ -114,8 +114,6 @@ class DialogueManager:
|
|
|
self.staff_profile = self.user_manager.get_staff_profile(staff_id)
|
|
|
# FIXME: 交互时间和对话记录都涉及到回滚
|
|
|
self.last_interaction_time = 0
|
|
|
- self.consecutive_clarifications = 0
|
|
|
- self.complex_request_counter = 0
|
|
|
self.human_intervention_triggered = False
|
|
|
self.vector_memory = DummyVectorMemoryManager(user_id)
|
|
|
self.message_aggregation_sec = config.get('agent_behavior', {}).get('message_aggregation_sec', 5)
|
|
@@ -222,16 +220,21 @@ class DialogueManager:
|
|
|
"""根据用户消息更新对话状态,并返回是否需要发起回复 及下一条需处理的用户消息"""
|
|
|
message_text = message.content
|
|
|
message_ts = message.sendTime
|
|
|
- # 如果当前已经是人工介入状态,保持该状态
|
|
|
+
|
|
|
+ # 如果当前已经是人工介入状态,根据消息类型决定保持/退出
|
|
|
if self.current_state == DialogueState.HUMAN_INTERVENTION:
|
|
|
- # 记录对话历史,但不改变状态
|
|
|
- self.append_dialogue_history({
|
|
|
- "role": "user",
|
|
|
- "content": message_text,
|
|
|
- "timestamp": int(time.time() * 1000),
|
|
|
- "state": self.current_state.name
|
|
|
- })
|
|
|
- return False, message_text
|
|
|
+ if message.type == MessageType.HUMAN_INTERVENTION_END:
|
|
|
+ self.resume_from_human_intervention()
|
|
|
+ # 恢复状态,但无需Agent产生回复
|
|
|
+ return False, None
|
|
|
+ else:
|
|
|
+ self.append_dialogue_history({
|
|
|
+ "role": "user",
|
|
|
+ "content": message_text,
|
|
|
+ "timestamp": int(time.time() * 1000),
|
|
|
+ "state": self.current_state.name
|
|
|
+ })
|
|
|
+ return False, message_text
|
|
|
|
|
|
# 检查是否处于消息聚合状态
|
|
|
if self.current_state == DialogueState.MESSAGE_AGGREGATING:
|
|
@@ -273,16 +276,6 @@ class DialogueManager:
|
|
|
# 根据消息内容和当前状态确定新状态
|
|
|
new_state = self._determine_state_from_message(message_text)
|
|
|
|
|
|
- # 处理连续澄清的情况
|
|
|
- if new_state == DialogueState.CLARIFICATION:
|
|
|
- self.consecutive_clarifications += 1
|
|
|
- # FIXME(zhoutian): 规则过于简单
|
|
|
- if self.consecutive_clarifications >= 10000:
|
|
|
- new_state = DialogueState.HUMAN_INTERVENTION
|
|
|
- # self._trigger_human_intervention("连续多次澄清请求")
|
|
|
- else:
|
|
|
- self.consecutive_clarifications = 0
|
|
|
-
|
|
|
# 更新状态
|
|
|
self.do_state_change(new_state)
|
|
|
|
|
@@ -305,20 +298,6 @@ class DialogueManager:
|
|
|
# 简单的规则-关键词匹配
|
|
|
message_lower = message_text.lower()
|
|
|
|
|
|
- # 判断是否是复杂请求
|
|
|
- # FIXME(zhoutian): 规则过于简单
|
|
|
- # complex_request_keywords = ["帮我", "怎么办", "我需要", "麻烦你", "请帮助", "急", "紧急"]
|
|
|
- # if any(keyword in message_lower for keyword in complex_request_keywords):
|
|
|
- # self.complex_request_counter += 1
|
|
|
- #
|
|
|
- # # 如果检测到困难请求且计数达到阈值,触发人工介入
|
|
|
- # if self.complex_request_counter >= 1:
|
|
|
- # # self._trigger_human_intervention("检测到复杂请求")
|
|
|
- # return DialogueState.HUMAN_INTERVENTION
|
|
|
- # else:
|
|
|
- # # 如果不是复杂请求,重置计数器
|
|
|
- # self.complex_request_counter = 0
|
|
|
-
|
|
|
# 问候检测
|
|
|
greeting_keywords = ["你好", "早上好", "中午好", "晚上好", "嗨", "在吗"]
|
|
|
if any(keyword in message_lower for keyword in greeting_keywords):
|
|
@@ -384,16 +363,6 @@ class DialogueManager:
|
|
|
"""从人工介入状态恢复"""
|
|
|
if self.current_state == DialogueState.HUMAN_INTERVENTION:
|
|
|
self.do_state_change(DialogueState.CHITCHAT)
|
|
|
- self.consecutive_clarifications = 0
|
|
|
- self.complex_request_counter = 0
|
|
|
-
|
|
|
- # 记录恢复事件
|
|
|
- self.append_dialogue_history({
|
|
|
- "role": "system",
|
|
|
- "content": "已从人工介入状态恢复到自动对话",
|
|
|
- "timestamp": int(time.time() * 1000),
|
|
|
- "state": self.current_state.name
|
|
|
- })
|
|
|
|
|
|
def generate_response(self, llm_response: str) -> Optional[str]:
|
|
|
"""
|