fix:修复兴趣集未清空,模型失败导致planer失败,绘图插件配置文件问题

This commit is contained in:
SengokuCola
2025-05-29 00:44:41 +08:00
parent de28e3bc3b
commit 76d305696c
11 changed files with 35 additions and 50 deletions

View File

@@ -54,7 +54,7 @@ CONSECUTIVE_NO_REPLY_THRESHOLD = 3 # 连续不回复的阈值
logger = get_logger("hfc") # Logger Name Changed
# 设定处理器超时时间(秒)
PROCESSOR_TIMEOUT = 40
PROCESSOR_TIMEOUT = 30
async def _handle_cycle_delay(action_taken_this_cycle: bool, cycle_start_time: float, log_prefix: str):
@@ -329,11 +329,20 @@ class HeartFChatting:
formatted_time = f"{elapsed * 1000:.2f}毫秒" if elapsed < 1 else f"{elapsed:.2f}"
timer_strings.append(f"{name}: {formatted_time}")
# 新增:输出每个处理器的耗时
processor_time_costs = self._current_cycle.loop_processor_info.get("processor_time_costs", {})
processor_time_strings = []
for pname, ptime in processor_time_costs.items():
formatted_ptime = f"{ptime * 1000:.2f}毫秒" if ptime < 1 else f"{ptime:.2f}"
processor_time_strings.append(f"{pname}: {formatted_ptime}")
processor_time_log = ("\n各处理器耗时: " + "; ".join(processor_time_strings)) if processor_time_strings else ""
logger.info(
f"{self.log_prefix}{self._current_cycle.cycle_id}次思考,"
f"耗时: {self._current_cycle.end_time - self._current_cycle.start_time:.1f}秒, "
f"动作: {self._current_cycle.loop_plan_info['action_result']['action_type']}"
+ (f"\n详情: {'; '.join(timer_strings)}" if timer_strings else "")
+ processor_time_log
)
await asyncio.sleep(global_config.focus_chat.think_interval)
@@ -369,18 +378,18 @@ class HeartFChatting:
async def _process_processors(
self, observations: List[Observation], running_memorys: List[Dict[str, Any]], cycle_timers: dict
) -> List[InfoBase]:
) -> tuple[List[InfoBase], Dict[str, float]]:
# 记录并行任务开始时间
parallel_start_time = time.time()
logger.debug(f"{self.log_prefix} 开始信息处理器并行任务")
processor_tasks = []
task_to_name_map = {}
processor_time_costs = {} # 新增: 记录每个处理器耗时
for processor in self.processors:
processor_name = processor.__class__.log_prefix
# 用lambda包裹便于传参
async def run_with_timeout(proc=processor):
return await asyncio.wait_for(
proc.process_info(observations=observations, running_memorys=running_memorys),
@@ -404,22 +413,24 @@ class HeartFChatting:
duration_since_parallel_start = task_completed_time - parallel_start_time
try:
# 使用 await task 来获取结果或触发异常
result_list = await task
logger.info(f"{self.log_prefix} 处理器 {processor_name} 已完成!")
if result_list is not None:
all_plan_info.extend(result_list)
else:
logger.warning(f"{self.log_prefix} 处理器 {processor_name} 返回了 None")
# 记录耗时
processor_time_costs[processor_name] = duration_since_parallel_start
except asyncio.TimeoutError:
logger.info(f"{self.log_prefix} 处理器 {processor_name} 超时(>{PROCESSOR_TIMEOUT}s已跳过")
processor_time_costs[processor_name] = PROCESSOR_TIMEOUT
except Exception as e:
logger.error(
f"{self.log_prefix} 处理器 {processor_name} 执行失败,耗时 (自并行开始): {duration_since_parallel_start:.2f}秒. 错误: {e}",
exc_info=True,
)
traceback.print_exc()
# 即使出错,也认为该任务结束了,已从 pending_tasks 中移除
processor_time_costs[processor_name] = duration_since_parallel_start
if pending_tasks:
current_progress_time = time.time()
@@ -435,12 +446,11 @@ class HeartFChatting:
logger.info(f"{self.log_prefix} 所有处理器任务全部完成,总耗时: {total_duration:.2f}")
# logger.debug(f"{self.log_prefix} 所有信息处理器处理后的信息: {all_plan_info}")
return all_plan_info
return all_plan_info, processor_time_costs
async def _observe_process_plan_action_loop(self, cycle_timers: dict, thinking_id: str) -> dict:
try:
with Timer("观察", cycle_timers):
# await self.observations[0].observe()
await self.chatting_observation.observe()
await self.working_observation.observe()
await self.hfcloop_observation.observe()
@@ -461,10 +471,11 @@ class HeartFChatting:
running_memorys = await self.memory_activator.activate_memory(observations)
with Timer("执行 信息处理器", cycle_timers):
all_plan_info = await self._process_processors(observations, running_memorys, cycle_timers)
all_plan_info, processor_time_costs = await self._process_processors(observations, running_memorys, cycle_timers)
loop_processor_info = {
"all_plan_info": all_plan_info,
"processor_time_costs": processor_time_costs,
}
with Timer("规划器", cycle_timers):
@@ -483,7 +494,6 @@ class HeartFChatting:
plan_result.get("action_result", {}).get("reasoning", "未提供理由"),
)
# 在此处添加日志记录
if action_type == "reply":
action_str = "回复"
elif action_type == "no_reply":

View File

@@ -185,7 +185,7 @@ class SelfProcessor(BaseProcessor):
if content == "None":
content = ""
# 记录初步思考结果
logger.debug(f"{self.log_prefix} 自我识别prompt: \n{prompt}\n")
# logger.debug(f"{self.log_prefix} 自我识别prompt: \n{prompt}\n")
logger.info(f"{self.log_prefix} 自我认知: {content}")
return content

View File

@@ -127,7 +127,7 @@ class WorkingMemoryProcessor(BaseProcessor):
# 调用LLM处理记忆
content = ""
try:
logger.debug(f"{self.log_prefix} 处理工作记忆的prompt: {prompt}")
# logger.debug(f"{self.log_prefix} 处理工作记忆的prompt: {prompt}")
content, _ = await self.llm_model.generate_response_async(prompt=prompt)
if not content:

View File

@@ -107,11 +107,11 @@ class MemoryActivator:
cached_keywords=cached_keywords_str,
)
logger.debug(f"prompt: {prompt}")
# logger.debug(f"prompt: {prompt}")
response = await self.summary_model.generate_response(prompt)
logger.debug(f"response: {response}")
# logger.debug(f"response: {response}")
# 只取response的第一个元素字符串
response_str = response[0]
@@ -127,7 +127,7 @@ class MemoryActivator:
# 添加新的关键词到缓存
self.cached_keywords.update(keywords)
logger.debug(f"更新关键词缓存: {self.cached_keywords}")
logger.debug(f"当前激活的记忆关键词: {self.cached_keywords}")
# 调用记忆系统获取相关记忆
related_memory = await HippocampusManager.get_instance().get_memory_from_topic(

View File

@@ -130,6 +130,7 @@ class ActionPlanner:
current_mind = ""
cycle_info = ""
structured_info = ""
is_group_chat = True
for info in all_plan_info:
if isinstance(info, ObsInfo):
observed_messages = info.get_talking_message()

View File

@@ -179,7 +179,7 @@ class ChattingObservation(Observation):
"processed_plain_text": find_msg.get("processed_plain_text"),
}
find_rec_msg = MessageRecv(message_dict)
logger.debug(f"锚定消息处理后find_rec_msg: {find_rec_msg}")
# logger.debug(f"锚定消息处理后find_rec_msg: {find_rec_msg}")
return find_rec_msg
async def observe(self):

View File

@@ -111,6 +111,8 @@ class SubHeartflow:
"""
await self._stop_heart_fc_chat() # 确保 专注聊天已停止
self.interest_dict.clear()
log_prefix = self.log_prefix
try:
# 获取聊天流并创建 NormalChat 实例 (同步部分)