feat(planner): 实现大小脑规划器分离以优化决策流程
将规划器(Planner)拆分为“大脑”和“小脑”两个部分,以实现更精细化的决策控制。 - **大脑(BIG_BRAIN)**: 负责宏观决策,如是否回复、是否需要@人等高层级意图。 - **小脑(SMALL_BRAIN)**: 负责具体的功能性动作执行。 此重构引入了 `PlannerType` 枚举,并更新了动作(Action)定义,允许将动作明确分配给大脑或小脑,从而提升了AI回复的逻辑性和条理性。同时,新增了 `no_action` 类型,用于在规划阶段明确表示“无动作”,提高了处理流程的清晰度。
This commit is contained in:
committed by
Windpicker-owo
parent
cfffc69e20
commit
a30652b0bc
@@ -228,6 +228,8 @@ class CycleProcessor:
|
||||
async def execute_action(action_info):
|
||||
"""执行单个动作的通用函数"""
|
||||
try:
|
||||
if action_info["action_type"] == "no_action":
|
||||
return {"action_type": "no_action", "success": True, "reply_text": "", "command": ""}
|
||||
if action_info["action_type"] == "no_reply":
|
||||
# 直接处理no_reply逻辑,不再通过动作系统
|
||||
reason = action_info.get("reasoning", "选择不回复")
|
||||
@@ -245,7 +247,7 @@ class CycleProcessor:
|
||||
)
|
||||
|
||||
return {"action_type": "no_reply", "success": True, "reply_text": "", "command": ""}
|
||||
elif action_info["action_type"] != "reply":
|
||||
elif action_info["action_type"] != "reply" and action_info["action_type"] != "no_action":
|
||||
# 执行普通动作
|
||||
with Timer("动作执行", cycle_timers):
|
||||
success, reply_text, command = await self._handle_action(
|
||||
@@ -420,7 +422,7 @@ class CycleProcessor:
|
||||
if "reply" in available_actions:
|
||||
fallback_action = "reply"
|
||||
elif available_actions:
|
||||
fallback_action = list(available_actions.keys())
|
||||
fallback_action = list(available_actions.keys())[0]
|
||||
|
||||
if fallback_action and fallback_action != action:
|
||||
logger.info(f"{self.context.log_prefix} 使用回退动作: {fallback_action}")
|
||||
|
||||
@@ -23,7 +23,13 @@ from src.chat.utils.chat_message_builder import (
|
||||
from src.chat.utils.utils import get_chat_type_and_target_info
|
||||
from src.chat.planner_actions.action_manager import ActionManager
|
||||
from src.chat.message_receive.chat_stream import get_chat_manager
|
||||
from src.plugin_system.base.component_types import ActionInfo, ChatMode, ComponentType, ActionActivationType
|
||||
from src.plugin_system.base.component_types import (
|
||||
ActionInfo,
|
||||
ChatMode,
|
||||
ComponentType,
|
||||
ActionActivationType,
|
||||
PlannerType,
|
||||
)
|
||||
from src.plugin_system.core.component_registry import component_registry
|
||||
from src.schedule.schedule_manager import schedule_manager
|
||||
from src.mood.mood_manager import mood_manager
|
||||
@@ -503,6 +509,9 @@ class ActionPlanner:
|
||||
try:
|
||||
sub_planner_actions: Dict[str, ActionInfo] = {}
|
||||
for action_name, action_info in available_actions.items():
|
||||
if action_info.planner_type not in [PlannerType.SMALL_BRAIN, PlannerType.ALL]:
|
||||
continue
|
||||
|
||||
if action_info.activation_type in [ActionActivationType.LLM_JUDGE, ActionActivationType.ALWAYS]:
|
||||
sub_planner_actions[action_name] = action_info
|
||||
elif action_info.activation_type == ActionActivationType.RANDOM:
|
||||
@@ -550,10 +559,15 @@ class ActionPlanner:
|
||||
# --- 3. 大脑独立思考是否回复 ---
|
||||
action, reasoning, action_data, target_message = "no_reply", "大脑初始化默认", {}, None
|
||||
try:
|
||||
big_brain_actions = {
|
||||
name: info
|
||||
for name, info in available_actions.items()
|
||||
if info.planner_type in [PlannerType.BIG_BRAIN, PlannerType.ALL]
|
||||
}
|
||||
prompt, _ = await self.build_planner_prompt(
|
||||
is_group_chat=is_group_chat,
|
||||
chat_target_info=chat_target_info,
|
||||
current_available_actions={}, # 大脑不考虑具体action
|
||||
current_available_actions=big_brain_actions,
|
||||
mode=mode,
|
||||
chat_content_block_override=chat_content_block,
|
||||
message_id_list_override=message_id_list,
|
||||
|
||||
Reference in New Issue
Block a user