fix: 恢复actionprocessor,增加与formatinfo的联动逻辑

This commit is contained in:
tcmofashi
2025-05-26 12:38:03 +08:00
parent 0f62742138
commit 407d278f84
2 changed files with 41 additions and 34 deletions

View File

@@ -16,6 +16,7 @@ from src.chat.focus_chat.info.info_base import InfoBase
from src.chat.focus_chat.info_processors.chattinginfo_processor import ChattingInfoProcessor
from src.chat.focus_chat.info_processors.mind_processor import MindProcessor
from src.chat.focus_chat.info_processors.working_memory_processor import WorkingMemoryProcessor
from src.chat.focus_chat.info_processors.action_processor import ActionProcessor
from src.chat.heart_flow.observation.hfcloop_observation import HFCloopObservation
from src.chat.heart_flow.observation.working_observation import WorkingMemoryObservation
from src.chat.focus_chat.info_processors.tool_processor import ToolProcessor
@@ -39,6 +40,7 @@ PROCESSOR_CLASSES = {
"ToolProcessor": (ToolProcessor, "tool_use_processor"),
"WorkingMemoryProcessor": (WorkingMemoryProcessor, "working_memory_processor"),
"SelfProcessor": (SelfProcessor, "self_identify_processor"),
"ActionProcessor": (ActionProcessor, "action_processor"), # 这个处理器不需要配置键名,默认启用
}
@@ -425,10 +427,7 @@ class HeartFChatting:
self.all_observations = observations
with Timer("回忆", cycle_timers):
logger.debug(f"{self.log_prefix} 开始回忆")
running_memorys = await self.memory_activator.activate_memory(observations)
logger.debug(f"{self.log_prefix} 回忆完成")
print(running_memorys)
with Timer("执行 信息处理器", cycle_timers):
all_plan_info = await self._process_processors(observations, running_memorys, cycle_timers)

View File

@@ -54,39 +54,47 @@ class ActionProcessor(BaseProcessor):
if observations:
action_info = ActionInfo()
all_actions = None
hfc_obs = None
chat_obs = None
for obs in observations:
if isinstance(obs, HFCloopObservation):
# 创建动作信息
all_actions = obs.all_actions
action_changes = await self.analyze_loop_actions(obs)
if action_changes["add"] or action_changes["remove"]:
action_info.set_action_changes(action_changes)
# 设置变更原因
reasons = []
if action_changes["add"]:
reasons.append(f"添加动作{action_changes['add']}因为检测到大量无回复")
if action_changes["remove"]:
reasons.append(f"移除动作{action_changes['remove']}因为检测到连续回复")
action_info.set_reason(" | ".join(reasons))
if isinstance(obs, ChattingObservation) and all_actions is not None:
action_changes = {"add": [], "remove": []}
# 检查动作的关联类型
chat_context = chat_manager.get_stream(obs.chat_id).context
for action_name in all_actions.keys():
data = all_actions[action_name]
if data.get("associated_types"):
if not chat_context.check_types(data["associated_types"]):
action_changes["remove"].append(action_name)
logger.debug(f"{self.log_prefix} 动作 {action_name} 关联类型不匹配,移除该动作")
if len(action_changes["remove"]) > 0:
action_info.set_action_changes(action_changes)
# 设置变更原因
reasons = []
if action_info.get_reason():
reasons.append(action_info.get_reason())
if action_changes["remove"]:
reasons.append(f"移除动作{action_changes['remove']}因为关联类型不匹配")
action_info.set_reason(" | ".join(reasons))
hfc_obs = obs
if isinstance(obs, ChattingObservation):
chat_obs = obs
if hfc_obs:
obs = hfc_obs
# 创建动作信息
all_actions = obs.all_actions
action_changes = await self.analyze_loop_actions(obs)
if action_changes["add"] or action_changes["remove"]:
action_info.set_action_changes(action_changes)
# 设置变更原因
reasons = []
if action_changes["add"]:
reasons.append(f"添加动作{action_changes['add']}因为检测到大量无回复")
if action_changes["remove"]:
reasons.append(f"移除动作{action_changes['remove']}因为检测到连续回复")
action_info.set_reason(" | ".join(reasons))
if chat_obs and all_actions is not None:
obs = chat_obs
action_changes = {"add": [], "remove": []}
# 检查动作的关联类型
chat_context = chat_manager.get_stream(obs.chat_id).context
for action_name in all_actions.keys():
data = all_actions[action_name]
if data.get("associated_types"):
if not chat_context.check_types(data["associated_types"]):
action_changes["remove"].append(action_name)
logger.debug(f"{self.log_prefix} 动作 {action_name} 关联类型不匹配,移除该动作")
if len(action_changes["remove"]) > 0:
action_info.set_action_changes(action_changes)
# 设置变更原因
reasons = []
if action_info.get_reason():
reasons.append(action_info.get_reason())
if action_changes["remove"]:
reasons.append(f"移除动作{action_changes['remove']}因为关联类型不匹配")
action_info.set_reason(" | ".join(reasons))
processed_infos.append(action_info)