feat(affinity_flow): 添加 Normal 模式开关以控制自动切换

新增了 `affinity_flow.enable_normal_mode` 配置项,允许用户自由启用或禁用 Normal 聊天模式。

当禁用 Normal 模式时:
- 规划器将强制把处于 Normal 模式的会话切换回 Focus 模式。
- 在 Focus 模式下完成回复后,将不再自动切换到 Normal 模式。

这为希望始终保持完整规划流程的用户提供了更大的灵活性。
This commit is contained in:
tt-P607
2025-10-29 10:46:31 +08:00
parent 44fe53268d
commit 54d1071432
3 changed files with 34 additions and 10 deletions

View File

@@ -685,6 +685,9 @@ class PermissionConfig(ValidatedConfigBase):
class AffinityFlowConfig(ValidatedConfigBase): class AffinityFlowConfig(ValidatedConfigBase):
"""亲和流配置类(兴趣度评分和人物关系系统)""" """亲和流配置类(兴趣度评分和人物关系系统)"""
# Normal模式开关
enable_normal_mode: bool = Field(default=True, description="是否启用自动Normal模式切换")
# 兴趣评分系统参数 # 兴趣评分系统参数
reply_action_interest_threshold: float = Field(default=0.4, description="回复动作兴趣阈值") reply_action_interest_threshold: float = Field(default=0.4, description="回复动作兴趣阈值")
non_reply_action_interest_threshold: float = Field(default=0.2, description="非回复动作兴趣阈值") non_reply_action_interest_threshold: float = Field(default=0.2, description="非回复动作兴趣阈值")

View File

@@ -17,6 +17,7 @@ from src.plugins.built_in.affinity_flow_chatter.plan_generator import ChatterPla
if TYPE_CHECKING: if TYPE_CHECKING:
from src.chat.planner_actions.action_manager import ChatterActionManager from src.chat.planner_actions.action_manager import ChatterActionManager
from src.common.data_models.database_data_model import DatabaseMessages
from src.common.data_models.info_data_model import Plan from src.common.data_models.info_data_model import Plan
from src.common.data_models.message_manager_data_model import StreamContext from src.common.data_models.message_manager_data_model import StreamContext
@@ -100,7 +101,15 @@ class ChatterActionPlanner:
# 1. 生成初始 Plan # 1. 生成初始 Plan
chat_mode = context.chat_mode if context else ChatMode.NORMAL chat_mode = context.chat_mode if context else ChatMode.FOCUS
# 如果禁用了Normal模式则强制将任何处于Normal模式的会话切换回Focus模式。
if not global_config.affinity_flow.enable_normal_mode and chat_mode == ChatMode.NORMAL:
logger.info("Normal模式已禁用强制切换回Focus模式")
chat_mode = ChatMode.FOCUS
if context:
context.chat_mode = ChatMode.FOCUS
await self._sync_chat_mode_to_stream(context)
# Normal模式下使用简化流程 # Normal模式下使用简化流程
if chat_mode == ChatMode.NORMAL: if chat_mode == ChatMode.NORMAL:
@@ -188,12 +197,15 @@ class ChatterActionPlanner:
# 7. Focus模式下如果执行了reply动作切换到Normal模式 # 7. Focus模式下如果执行了reply动作切换到Normal模式
if chat_mode == ChatMode.FOCUS and context: if chat_mode == ChatMode.FOCUS and context:
if filtered_plan.decided_actions:
has_reply = any( has_reply = any(
action.action_type in ["reply", "proactive_reply"] action.action_type in ["reply", "proactive_reply"]
for action in filtered_plan.decided_actions for action in filtered_plan.decided_actions
) )
if has_reply: else:
logger.info("Focus模式: 执行了reply动作切换到Normal模式") has_reply = False
if has_reply and global_config.affinity_flow.enable_normal_mode:
logger.info("Focus模式: 执行了reply动作自动切换到Normal模式")
context.chat_mode = ChatMode.NORMAL context.chat_mode = ChatMode.NORMAL
await self._sync_chat_mode_to_stream(context) await self._sync_chat_mode_to_stream(context)
@@ -211,6 +223,14 @@ class ChatterActionPlanner:
只计算兴趣值并判断是否达到reply阈值不执行完整的plan流程。 只计算兴趣值并判断是否达到reply阈值不执行完整的plan流程。
根据focus_energy决定退出normal模式回到focus模式的概率。 根据focus_energy决定退出normal模式回到focus模式的概率。
""" """
# 最后的保障措施,以防意外进入此流程
if not global_config.affinity_flow.enable_normal_mode:
logger.warning("意外进入了Normal模式流程但该模式已被禁用将强制切换回Focus模式进行完整规划。")
if context:
context.chat_mode = ChatMode.FOCUS
await self._sync_chat_mode_to_stream(context)
# 重新运行主规划流程这次将正确使用Focus模式
return await self._enhanced_plan_flow(context)
try: try:
unread_messages = context.get_unread_messages() if context else [] unread_messages = context.get_unread_messages() if context else []
@@ -249,7 +269,7 @@ class ChatterActionPlanner:
action_type="reply", action_type="reply",
reasoning="Normal模式: 兴趣度达到阈值,直接回复", reasoning="Normal模式: 兴趣度达到阈值,直接回复",
action_data={"target_message_id": target_message.message_id}, action_data={"target_message_id": target_message.message_id},
action_message=target_message_dict, action_message=target_message,
) )
# Normal模式下直接构建最小化的Plan跳过generator和action_modifier # Normal模式下直接构建最小化的Plan跳过generator和action_modifier

View File

@@ -1,5 +1,5 @@
[inner] [inner]
version = "7.5.0" version = "7.5.1"
#----以下是给开发人员阅读的如果你只是部署了MoFox-Bot不需要阅读---- #----以下是给开发人员阅读的如果你只是部署了MoFox-Bot不需要阅读----
#如果你想要修改配置文件请递增version的值 #如果你想要修改配置文件请递增version的值
@@ -527,6 +527,7 @@ chat_ids = [
] ]
[affinity_flow] [affinity_flow]
enable_normal_mode = true # 是否启用 Normal 聊天模式。启用后,在专注模式回复后会自动切换,并根据兴趣度决定是否回复,以实现更快速的回复。
# 兴趣评分系统参数 # 兴趣评分系统参数
reply_action_interest_threshold = 0.9 # 回复动作兴趣阈值 reply_action_interest_threshold = 0.9 # 回复动作兴趣阈值
non_reply_action_interest_threshold = 0.8 # 非回复动作兴趣阈值 non_reply_action_interest_threshold = 0.8 # 非回复动作兴趣阈值