feat(affinity_flow_chatter): 优化戳一戳动作以更精准地回应原始消息
当LLM在执行 poke_user 动作时未指定 target_message_id,系统现在会主动在消息历史中寻找触发该动作的“戳一戳”通知,以实现更具上下文的回应。如果未找到对应的通知消息,则会回退到使用最新的消息作为目标。 此外,本次更新包含以下修复: - 修复了在计划过滤器中错误地引用 `self.available_actions` 的问题,现已更正为 `plan.available_actions`。 - 修复了 `ActionModifier` 中动作列表在多阶段过滤时未及时更新的问题,确保了动作筛选的准确性。
This commit is contained in:
@@ -125,7 +125,8 @@ class ActionModifier:
|
||||
|
||||
# === 第二阶段:检查动作的关联类型 ===
|
||||
chat_context = self.chat_stream.context
|
||||
type_mismatched_actions = self._check_action_associated_types(all_actions, chat_context)
|
||||
current_actions_s2 = self.action_manager.get_using_actions()
|
||||
type_mismatched_actions = self._check_action_associated_types(current_actions_s2, chat_context)
|
||||
|
||||
if type_mismatched_actions:
|
||||
removals_s2.extend(type_mismatched_actions)
|
||||
@@ -140,11 +141,12 @@ class ActionModifier:
|
||||
logger.debug(f"{self.log_prefix}开始激活类型判定阶段")
|
||||
|
||||
# 获取当前使用的动作集(经过第一阶段处理)
|
||||
current_using_actions = self.action_manager.get_using_actions()
|
||||
# 在第三阶段开始前,再次获取最新的动作列表
|
||||
current_actions_s3 = self.action_manager.get_using_actions()
|
||||
|
||||
# 获取因激活类型判定而需要移除的动作
|
||||
removals_s3 = await self._get_deactivated_actions_by_type(
|
||||
current_using_actions,
|
||||
current_actions_s3,
|
||||
chat_content,
|
||||
)
|
||||
|
||||
|
||||
@@ -443,8 +443,16 @@ class ChatterPlanFilter:
|
||||
if target_message_id := action_data.get("target_message_id"):
|
||||
target_message_dict = self._find_message_by_id(target_message_id, message_id_list)
|
||||
else:
|
||||
# 如果LLM没有指定target_message_id,我们就默认选择最新的一条消息
|
||||
target_message_dict = self._get_latest_message(message_id_list)
|
||||
# 如果LLM没有指定target_message_id,进行特殊处理
|
||||
if action == "poke_user":
|
||||
# 对于poke_user,尝试找到触发它的那条戳一戳消息
|
||||
target_message_dict = self._find_poke_notice(message_id_list)
|
||||
if not target_message_dict:
|
||||
# 如果找不到,再使用最新消息作为兜底
|
||||
target_message_dict = self._get_latest_message(message_id_list)
|
||||
else:
|
||||
# 其他动作,默认选择最新的一条消息
|
||||
target_message_dict = self._get_latest_message(message_id_list)
|
||||
|
||||
if target_message_dict:
|
||||
# 直接使用字典作为action_message,避免DatabaseMessages对象创建失败
|
||||
@@ -466,7 +474,7 @@ class ChatterPlanFilter:
|
||||
|
||||
if (
|
||||
action not in ["no_action", "no_reply", "reply", "do_nothing", "proactive_reply"]
|
||||
and action not in self.available_actions
|
||||
and action not in plan.available_actions
|
||||
):
|
||||
reasoning = f"LLM 返回了当前不可用的动作 '{action}'。原始理由: {reasoning}"
|
||||
action = "no_action"
|
||||
@@ -586,3 +594,15 @@ class ChatterPlanFilter:
|
||||
if not message_id_list:
|
||||
return None
|
||||
return message_id_list[-1].get("message")
|
||||
|
||||
def _find_poke_notice(self, message_id_list: list) -> Optional[Dict[str, Any]]:
|
||||
"""在消息列表中寻找戳一戳的通知消息"""
|
||||
for item in reversed(message_id_list):
|
||||
message = item.get("message")
|
||||
if (
|
||||
isinstance(message, dict)
|
||||
and message.get("type") == "notice"
|
||||
and "戳" in message.get("processed_plain_text", "")
|
||||
):
|
||||
return message
|
||||
return None
|
||||
|
||||
Reference in New Issue
Block a user