feat(affinity_flow): 添加 Normal 模式开关以控制自动切换
新增了 `affinity_flow.enable_normal_mode` 配置项,允许用户自由启用或禁用 Normal 聊天模式。 当禁用 Normal 模式时: - 规划器将强制把处于 Normal 模式的会话切换回 Focus 模式。 - 在 Focus 模式下完成回复后,将不再自动切换到 Normal 模式。 这为希望始终保持完整规划流程的用户提供了更大的灵活性。
This commit is contained in:
@@ -685,6 +685,9 @@ class PermissionConfig(ValidatedConfigBase):
|
||||
class AffinityFlowConfig(ValidatedConfigBase):
|
||||
"""亲和流配置类(兴趣度评分和人物关系系统)"""
|
||||
|
||||
# Normal模式开关
|
||||
enable_normal_mode: bool = Field(default=True, description="是否启用自动Normal模式切换")
|
||||
|
||||
# 兴趣评分系统参数
|
||||
reply_action_interest_threshold: float = Field(default=0.4, description="回复动作兴趣阈值")
|
||||
non_reply_action_interest_threshold: float = Field(default=0.2, description="非回复动作兴趣阈值")
|
||||
|
||||
@@ -17,6 +17,7 @@ from src.plugins.built_in.affinity_flow_chatter.plan_generator import ChatterPla
|
||||
|
||||
if TYPE_CHECKING:
|
||||
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.message_manager_data_model import StreamContext
|
||||
|
||||
@@ -100,7 +101,15 @@ class ChatterActionPlanner:
|
||||
|
||||
|
||||
# 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模式下使用简化流程
|
||||
if chat_mode == ChatMode.NORMAL:
|
||||
@@ -188,12 +197,15 @@ class ChatterActionPlanner:
|
||||
|
||||
# 7. Focus模式下如果执行了reply动作,切换到Normal模式
|
||||
if chat_mode == ChatMode.FOCUS and context:
|
||||
has_reply = any(
|
||||
action.action_type in ["reply", "proactive_reply"]
|
||||
for action in filtered_plan.decided_actions
|
||||
)
|
||||
if has_reply:
|
||||
logger.info("Focus模式: 执行了reply动作,切换到Normal模式")
|
||||
if filtered_plan.decided_actions:
|
||||
has_reply = any(
|
||||
action.action_type in ["reply", "proactive_reply"]
|
||||
for action in filtered_plan.decided_actions
|
||||
)
|
||||
else:
|
||||
has_reply = False
|
||||
if has_reply and global_config.affinity_flow.enable_normal_mode:
|
||||
logger.info("Focus模式: 执行了reply动作,自动切换到Normal模式")
|
||||
context.chat_mode = ChatMode.NORMAL
|
||||
await self._sync_chat_mode_to_stream(context)
|
||||
|
||||
@@ -211,6 +223,14 @@ class ChatterActionPlanner:
|
||||
只计算兴趣值并判断是否达到reply阈值,不执行完整的plan流程。
|
||||
根据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:
|
||||
unread_messages = context.get_unread_messages() if context else []
|
||||
|
||||
@@ -249,7 +269,7 @@ class ChatterActionPlanner:
|
||||
action_type="reply",
|
||||
reasoning="Normal模式: 兴趣度达到阈值,直接回复",
|
||||
action_data={"target_message_id": target_message.message_id},
|
||||
action_message=target_message_dict,
|
||||
action_message=target_message,
|
||||
)
|
||||
|
||||
# Normal模式下直接构建最小化的Plan,跳过generator和action_modifier
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
[inner]
|
||||
version = "7.5.0"
|
||||
version = "7.5.1"
|
||||
|
||||
#----以下是给开发人员阅读的,如果你只是部署了MoFox-Bot,不需要阅读----
|
||||
#如果你想要修改配置文件,请递增version的值
|
||||
@@ -527,6 +527,7 @@ chat_ids = [
|
||||
]
|
||||
|
||||
[affinity_flow]
|
||||
enable_normal_mode = true # 是否启用 Normal 聊天模式。启用后,在专注模式回复后会自动切换,并根据兴趣度决定是否回复,以实现更快速的回复。
|
||||
# 兴趣评分系统参数
|
||||
reply_action_interest_threshold = 0.9 # 回复动作兴趣阈值
|
||||
non_reply_action_interest_threshold = 0.8 # 非回复动作兴趣阈值
|
||||
|
||||
Reference in New Issue
Block a user