fix:优化离开focus模式的机制,完全移除Interest机制,
This commit is contained in:
@@ -29,7 +29,6 @@ class ActionManager:
|
||||
# 当前正在使用的动作集合,默认加载默认动作
|
||||
self._using_actions: Dict[str, ActionInfo] = {}
|
||||
|
||||
|
||||
# 默认动作集,仅作为快照,用于恢复默认
|
||||
self._default_actions: Dict[str, ActionInfo] = {}
|
||||
|
||||
@@ -159,9 +158,9 @@ class ActionManager:
|
||||
Optional[BaseAction]: 创建的动作处理器实例,如果动作名称未注册则返回None
|
||||
"""
|
||||
# 检查动作是否在当前使用的动作集中
|
||||
if action_name not in self._using_actions:
|
||||
logger.warning(f"当前不可用的动作类型: {action_name}")
|
||||
return None
|
||||
# if action_name not in self._using_actions:
|
||||
# logger.warning(f"当前不可用的动作类型: {action_name}")
|
||||
# return None
|
||||
|
||||
handler_class = _ACTION_REGISTRY.get(action_name)
|
||||
if not handler_class:
|
||||
@@ -283,7 +282,9 @@ class ActionManager:
|
||||
|
||||
def restore_actions(self) -> None:
|
||||
"""恢复到默认动作集"""
|
||||
logger.debug(f"恢复动作集: 从 {list(self._using_actions.keys())} 恢复到默认动作集 {list(self._default_actions.keys())}")
|
||||
logger.debug(
|
||||
f"恢复动作集: 从 {list(self._using_actions.keys())} 恢复到默认动作集 {list(self._default_actions.keys())}"
|
||||
)
|
||||
self._using_actions = self._default_actions.copy()
|
||||
|
||||
def restore_default_actions(self) -> None:
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
# 导入所有动作模块以确保装饰器被执行
|
||||
from . import reply_action # noqa
|
||||
from . import no_reply_action # noqa
|
||||
from . import exit_focus_chat_action # noqa
|
||||
|
||||
# 在此处添加更多动作模块导入
|
||||
|
||||
@@ -5,8 +5,6 @@ from src.chat.focus_chat.planners.actions.base_action import BaseAction, registe
|
||||
from typing import Tuple, List
|
||||
from src.chat.heart_flow.observation.observation import Observation
|
||||
from src.chat.message_receive.chat_stream import ChatStream
|
||||
from src.chat.heart_flow.heartflow import heartflow
|
||||
from src.chat.heart_flow.sub_heartflow import ChatState
|
||||
|
||||
logger = get_logger("action_taken")
|
||||
|
||||
@@ -27,7 +25,7 @@ class ExitFocusChatAction(BaseAction):
|
||||
"当前内容不需要持续专注关注,你决定退出专注聊天",
|
||||
"聊天内容已经完成,你决定退出专注聊天",
|
||||
]
|
||||
default = True
|
||||
default = False
|
||||
|
||||
def __init__(
|
||||
self,
|
||||
@@ -56,7 +54,6 @@ class ExitFocusChatAction(BaseAction):
|
||||
self.observations = observations
|
||||
self.log_prefix = log_prefix
|
||||
self._shutting_down = shutting_down
|
||||
self.chat_id = chat_stream.stream_id
|
||||
|
||||
async def handle_action(self) -> Tuple[bool, str]:
|
||||
"""
|
||||
@@ -74,23 +71,8 @@ class ExitFocusChatAction(BaseAction):
|
||||
try:
|
||||
# 转换状态
|
||||
status_message = ""
|
||||
self.sub_heartflow = await heartflow.get_or_create_subheartflow(self.chat_id)
|
||||
if self.sub_heartflow:
|
||||
try:
|
||||
# 转换为normal_chat状态
|
||||
await self.sub_heartflow.change_chat_state(ChatState.CHAT)
|
||||
status_message = "已成功切换到普通聊天模式"
|
||||
logger.info(f"{self.log_prefix} {status_message}")
|
||||
except Exception as e:
|
||||
error_msg = f"切换到普通聊天模式失败: {str(e)}"
|
||||
logger.error(f"{self.log_prefix} {error_msg}")
|
||||
return False, error_msg
|
||||
else:
|
||||
warning_msg = "未找到有效的sub heartflow实例,无法切换状态"
|
||||
logger.warning(f"{self.log_prefix} {warning_msg}")
|
||||
return False, warning_msg
|
||||
|
||||
return True, status_message
|
||||
command = "stop_focus_chat"
|
||||
return True, status_message, command
|
||||
|
||||
except asyncio.CancelledError:
|
||||
logger.info(f"{self.log_prefix} 处理 'exit_focus_chat' 时等待被中断 (CancelledError)")
|
||||
@@ -99,4 +81,4 @@ class ExitFocusChatAction(BaseAction):
|
||||
error_msg = f"处理 'exit_focus_chat' 时发生错误: {str(e)}"
|
||||
logger.error(f"{self.log_prefix} {error_msg}")
|
||||
logger.error(traceback.format_exc())
|
||||
return False, error_msg
|
||||
return False, "", ""
|
||||
|
||||
@@ -156,7 +156,7 @@ class ActionPlanner:
|
||||
logger.info(f"{self.log_prefix}{reasoning}")
|
||||
self.action_manager.restore_actions()
|
||||
logger.debug(
|
||||
f"{self.log_prefix}恢复到默认动作集, 当前可用: {list(self.action_manager.get_using_actions().keys())}"
|
||||
f"{self.log_prefix}沉默后恢复到默认动作集, 当前可用: {list(self.action_manager.get_using_actions().keys())}"
|
||||
)
|
||||
return {
|
||||
"action_result": {"action_type": action, "action_data": action_data, "reasoning": reasoning},
|
||||
@@ -241,7 +241,7 @@ class ActionPlanner:
|
||||
# 恢复到默认动作集
|
||||
self.action_manager.restore_actions()
|
||||
logger.debug(
|
||||
f"{self.log_prefix}恢复到默认动作集, 当前可用: {list(self.action_manager.get_using_actions().keys())}"
|
||||
f"{self.log_prefix}规划后恢复到默认动作集, 当前可用: {list(self.action_manager.get_using_actions().keys())}"
|
||||
)
|
||||
|
||||
action_result = {"action_type": action, "action_data": action_data, "reasoning": reasoning}
|
||||
|
||||
Reference in New Issue
Block a user