feat(affinity_flow_chatter): 优化戳一戳动作以更精准地回应原始消息
当LLM在执行 poke_user 动作时未指定 target_message_id,系统现在会主动在消息历史中寻找触发该动作的“戳一戳”通知,以实现更具上下文的回应。如果未找到对应的通知消息,则会回退到使用最新的消息作为目标。 此外,本次更新包含以下修复: - 修复了在计划过滤器中错误地引用 `self.available_actions` 的问题,现已更正为 `plan.available_actions`。 - 修复了 `ActionModifier` 中动作列表在多阶段过滤时未及时更新的问题,确保了动作筛选的准确性。
This commit is contained in:
@@ -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"
|
||||
@@ -589,3 +597,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