异步记忆系统优化 & Action组件修复
主要改进: 1. 异步记忆系统优化 - 解决记忆操作阻塞主程序问题 - 新增异步记忆队列管理器 (async_memory_optimizer.py) - 新增异步瞬时记忆包装器 (async_instant_memory_wrapper.py) - 优化主程序记忆构建任务为后台非阻塞执行 - 优化消息处理器记忆调用,增加超时保护和回退机制 2. Action组件修复 - 解决'未找到Action组件: no_reply'问题 - 修复no_reply动作激活类型配置错误 - 新增reply回退动作 (reply.py) - 增强planner.py动作选择回退机制 - 增强cycle_processor.py动作创建回退机制
This commit is contained in:
@@ -14,9 +14,9 @@ logger = get_logger("no_reply_action")
|
||||
class NoReplyAction(BaseAction):
|
||||
"""不回复动作,支持waiting和breaking两种形式."""
|
||||
|
||||
focus_activation_type = ActionActivationType.NEVER
|
||||
normal_activation_type = ActionActivationType.NEVER
|
||||
mode_enable = ChatMode.FOCUS
|
||||
focus_activation_type = ActionActivationType.ALWAYS # 修复:在focus模式下应该始终可用
|
||||
normal_activation_type = ActionActivationType.ALWAYS # 修复:在normal模式下应该始终可用
|
||||
mode_enable = ChatMode.FOCUS | ChatMode.NORMAL # 修复:在所有模式下都可用
|
||||
parallel_action = False
|
||||
|
||||
# 动作基本信息
|
||||
|
||||
79
src/plugins/built_in/core_actions/reply.py
Normal file
79
src/plugins/built_in/core_actions/reply.py
Normal file
@@ -0,0 +1,79 @@
|
||||
from typing import Tuple
|
||||
|
||||
# 导入新插件系统
|
||||
from src.plugin_system import BaseAction, ActionActivationType, ChatMode
|
||||
|
||||
# 导入依赖的系统组件
|
||||
from src.common.logger import get_logger
|
||||
from src.plugin_system.apis import generator_api
|
||||
|
||||
|
||||
logger = get_logger("reply_action")
|
||||
|
||||
|
||||
class ReplyAction(BaseAction):
|
||||
"""基本回复动作:确保系统始终有一个可用的回退动作!!!"""
|
||||
|
||||
focus_activation_type = ActionActivationType.ALWAYS
|
||||
normal_activation_type = ActionActivationType.ALWAYS
|
||||
mode_enable = ChatMode.FOCUS | ChatMode.NORMAL
|
||||
parallel_action = False
|
||||
|
||||
# 动作基本信息
|
||||
action_name = "reply"
|
||||
action_description = "进行基本回复"
|
||||
|
||||
# 动作参数定义
|
||||
action_parameters = {}
|
||||
|
||||
# 动作使用场景
|
||||
action_require = [""]
|
||||
|
||||
# 关联类型
|
||||
associated_types = []
|
||||
|
||||
async def execute(self) -> Tuple[bool, str]:
|
||||
"""执行回复动作"""
|
||||
try:
|
||||
reason = self.action_data.get("reason", "")
|
||||
|
||||
logger.info(f"{self.log_prefix} 执行基本回复动作,原因: {reason}")
|
||||
|
||||
# 获取当前消息和上下文
|
||||
if not self.chat_stream or not self.chat_stream.get_latest_message():
|
||||
logger.warning(f"{self.log_prefix} 没有可回复的消息")
|
||||
return False, ""
|
||||
|
||||
latest_message = self.chat_stream.get_latest_message()
|
||||
|
||||
# 使用生成器API生成回复
|
||||
success, reply_set, _ = await generator_api.generate_reply(
|
||||
target_message=latest_message.processed_plain_text,
|
||||
chat_stream=self.chat_stream,
|
||||
reasoning=reason,
|
||||
action_message={}
|
||||
)
|
||||
|
||||
if success and reply_set:
|
||||
# 提取回复文本
|
||||
reply_text = ""
|
||||
for message_type, content in reply_set:
|
||||
if message_type == "text":
|
||||
reply_text += content
|
||||
break
|
||||
|
||||
if reply_text:
|
||||
logger.info(f"{self.log_prefix} 回复生成成功: {reply_text[:50]}...")
|
||||
return True, reply_text
|
||||
else:
|
||||
logger.warning(f"{self.log_prefix} 生成的回复为空")
|
||||
return False, ""
|
||||
else:
|
||||
logger.warning(f"{self.log_prefix} 回复生成失败")
|
||||
return False, ""
|
||||
|
||||
except Exception as e:
|
||||
logger.error(f"{self.log_prefix} 执行回复动作时发生异常: {e}")
|
||||
import traceback
|
||||
traceback.print_exc()
|
||||
return False, ""
|
||||
Reference in New Issue
Block a user