refactor(event): 将日志级别从info调整为debug,以减少日志输出并提高可读性
This commit is contained in:
@@ -34,51 +34,48 @@ class ProactiveThinkingReplyHandler(BaseEventHandler):
|
||||
Returns:
|
||||
HandlerResult: 处理结果
|
||||
"""
|
||||
logger.info("[主动思考事件] ProactiveThinkingReplyHandler 开始执行")
|
||||
logger.info(f"[主动思考事件] 接收到的参数: {kwargs}")
|
||||
logger.debug("[主动思考事件] ProactiveThinkingReplyHandler 开始执行")
|
||||
logger.debug(f"[主动思考事件] 接收到的参数: {kwargs}")
|
||||
|
||||
if not kwargs:
|
||||
logger.warning("[主动思考事件] kwargs 为空,跳过处理")
|
||||
logger.debug("[主动思考事件] kwargs 为空,跳过处理")
|
||||
return HandlerResult(success=True, continue_process=True, message=None)
|
||||
|
||||
stream_id = kwargs.get("stream_id")
|
||||
if not stream_id:
|
||||
logger.warning(f"[主动思考事件] Reply事件缺少stream_id参数,kwargs={kwargs}")
|
||||
logger.debug(f"[主动思考事件] Reply事件缺少stream_id参数")
|
||||
return HandlerResult(success=True, continue_process=True, message=None)
|
||||
|
||||
logger.info(f"[主动思考事件] 收到 AFTER_SEND 事件,stream_id={stream_id}")
|
||||
logger.debug(f"[主动思考事件] 收到 AFTER_SEND 事件,stream_id={stream_id}")
|
||||
|
||||
try:
|
||||
from src.config.config import global_config
|
||||
|
||||
# 检查是否启用reply重置
|
||||
logger.info(f"[主动思考事件] reply_reset_enabled={global_config.proactive_thinking.reply_reset_enabled}")
|
||||
if not global_config.proactive_thinking.reply_reset_enabled:
|
||||
logger.info(f"[主动思考事件] reply_reset_enabled 为 False,跳过重置")
|
||||
logger.debug(f"[主动思考事件] reply_reset_enabled 为 False,跳过重置")
|
||||
return HandlerResult(success=True, continue_process=True, message=None)
|
||||
|
||||
# 检查是否被暂停
|
||||
was_paused = await proactive_thinking_scheduler.is_paused(stream_id)
|
||||
logger.info(f"[主动思考事件] 聊天流 {stream_id} 暂停状态: {was_paused}")
|
||||
logger.debug(f"[主动思考事件] 聊天流 {stream_id} 暂停状态: {was_paused}")
|
||||
|
||||
if was_paused:
|
||||
logger.info(f"[主动思考事件] 检测到reply事件,聊天流 {stream_id} 之前因抛出话题而暂停,现在恢复")
|
||||
logger.debug(f"[主动思考事件] 检测到reply事件,聊天流 {stream_id} 之前因抛出话题而暂停,现在恢复")
|
||||
|
||||
# 重置定时任务(这会自动清除暂停标记并创建新任务)
|
||||
logger.info(f"[主动思考事件] 准备调用 schedule_proactive_thinking,stream_id={stream_id}")
|
||||
success = await proactive_thinking_scheduler.schedule_proactive_thinking(stream_id)
|
||||
logger.info(f"[主动思考事件] schedule_proactive_thinking 调用完成,success={success}")
|
||||
|
||||
if success:
|
||||
if was_paused:
|
||||
logger.info(f"[主动思考事件] ✅ 聊天流 {stream_id} 的主动思考已恢复并重置")
|
||||
logger.info(f"✅ 聊天流 {stream_id} 主动思考已恢复并重置")
|
||||
else:
|
||||
logger.info(f"[主动思考事件] ✅ 聊天流 {stream_id} 的主动思考定时任务已重置")
|
||||
logger.debug(f"✅ 聊天流 {stream_id} 主动思考任务已重置")
|
||||
else:
|
||||
logger.warning(f"[主动思考事件] ❌ 重置聊天流 {stream_id} 的主动思考任务失败")
|
||||
logger.warning(f"❌ 重置聊天流 {stream_id} 主动思考任务失败")
|
||||
|
||||
except Exception as e:
|
||||
logger.error(f"[主动思考事件] ❌ 处理reply事件时出错: {e}", exc_info=True)
|
||||
logger.error(f"❌ 处理reply事件时出错: {e}", exc_info=True)
|
||||
|
||||
# 总是继续处理其他handler
|
||||
return HandlerResult(success=True, continue_process=True, message=None)
|
||||
|
||||
@@ -498,72 +498,65 @@ async def execute_proactive_thinking(stream_id: str):
|
||||
|
||||
config = global_config.proactive_thinking
|
||||
|
||||
logger.info(f"[主动思考] 开始为聊天流 {stream_id} 执行主动思考")
|
||||
logger.debug(f"🤔 开始主动思考 {stream_id}")
|
||||
|
||||
try:
|
||||
# 0. 前置检查
|
||||
# 检查是否在安静时段
|
||||
if proactive_thinking_scheduler._is_in_quiet_hours():
|
||||
logger.debug(f"当前在安静时段,跳过主动思考")
|
||||
logger.debug(f"安静时段,跳过")
|
||||
return
|
||||
|
||||
# 检查每日限制
|
||||
if not proactive_thinking_scheduler._check_daily_limit(stream_id):
|
||||
logger.info(f"聊天流 {stream_id} 今日主动发言次数已达上限")
|
||||
logger.debug(f"今日发言达上限")
|
||||
return
|
||||
|
||||
# 1. 搜集信息
|
||||
logger.info(f"[主动思考] 步骤1:搜集上下文信息")
|
||||
logger.debug(f"步骤1: 搜集上下文")
|
||||
context = await _planner.gather_context(stream_id)
|
||||
if not context:
|
||||
logger.warning(f"[主动思考] 无法搜集聊天流 {stream_id} 的上下文,跳过本次主动思考")
|
||||
logger.warning(f"无法搜集上下文,跳过")
|
||||
return
|
||||
logger.info(f"[主动思考] 上下文搜集完成")
|
||||
|
||||
# 检查兴趣分数阈值
|
||||
interest_score = context.get('interest_score', 0.5)
|
||||
if not proactive_thinking_scheduler._check_interest_score_threshold(interest_score):
|
||||
logger.info(f"[主动思考] 聊天流 {stream_id} 兴趣分数不在阈值范围内")
|
||||
logger.debug(f"兴趣分数不在阈值范围内")
|
||||
return
|
||||
|
||||
# 2. 进行决策
|
||||
logger.info(f"[主动思考] 步骤2:LLM决策")
|
||||
logger.debug(f"步骤2: LLM决策")
|
||||
decision = await _planner.make_decision(context)
|
||||
if not decision:
|
||||
logger.warning(f"[主动思考] 决策失败,跳过本次主动思考")
|
||||
logger.warning(f"决策失败,跳过")
|
||||
return
|
||||
logger.info(f"[主动思考] 决策完成")
|
||||
|
||||
action = decision.get("action", "do_nothing")
|
||||
reasoning = decision.get("reasoning", "无")
|
||||
|
||||
# 记录决策日志
|
||||
if config.log_decisions:
|
||||
logger.info(f"[决策详情] stream_id={stream_id}, action={action}, reasoning={reasoning}")
|
||||
logger.debug(f"决策: action={action}, reasoning={reasoning}")
|
||||
|
||||
# 3. 根据决策执行相应动作
|
||||
if action == "do_nothing":
|
||||
logger.info(f"决策:什么都不做。理由:{reasoning}")
|
||||
# 记录决策
|
||||
logger.debug(f"决策:什么都不做。理由:{reasoning}")
|
||||
proactive_thinking_scheduler.record_decision(stream_id, action, reasoning, None)
|
||||
return
|
||||
|
||||
elif action == "simple_bubble":
|
||||
logger.info(f"[主动思考] 决策:简单冒个泡。理由:{reasoning}")
|
||||
logger.info(f"💬 决策:冒个泡。理由:{reasoning}")
|
||||
|
||||
# 记录决策
|
||||
proactive_thinking_scheduler.record_decision(stream_id, action, reasoning, None)
|
||||
|
||||
# 生成简单的消息
|
||||
logger.info(f"[主动思考] 步骤3:生成冒泡回复")
|
||||
logger.debug(f"步骤3: 生成冒泡回复")
|
||||
reply = await _planner.generate_reply(context, "simple_bubble")
|
||||
if reply:
|
||||
logger.info(f"[主动思考] 步骤4:发送消息")
|
||||
await send_api.text_to_stream(
|
||||
stream_id=stream_id,
|
||||
text=reply,
|
||||
)
|
||||
logger.info(f"[主动思考] 已发送冒泡消息到 {stream_id}")
|
||||
logger.info(f"✅ 已发送冒泡消息")
|
||||
|
||||
# 增加每日计数
|
||||
proactive_thinking_scheduler._increment_daily_count(stream_id)
|
||||
|
||||
@@ -236,28 +236,26 @@ class ProactiveThinkingScheduler:
|
||||
Returns:
|
||||
bool: 是否成功创建/重置任务
|
||||
"""
|
||||
logger.info(f"[调度器] 开始为聊天流 {stream_id} 创建/重置主动思考任务")
|
||||
logger.debug(f"[调度器] 开始为聊天流 {stream_id} 创建/重置主动思考任务")
|
||||
try:
|
||||
async with self._lock:
|
||||
# 如果该流因抛出话题而暂停,先清除暂停标记
|
||||
if stream_id in self._paused_streams:
|
||||
logger.info(f"[调度器] 清除聊天流 {stream_id} 的暂停标记")
|
||||
logger.debug(f"[调度器] 清除聊天流 {stream_id} 的暂停标记")
|
||||
self._paused_streams.discard(stream_id)
|
||||
|
||||
# 如果已经有任务,先移除
|
||||
if stream_id in self._stream_schedules:
|
||||
old_schedule_id = self._stream_schedules[stream_id]
|
||||
logger.info(f"[调度器] 移除聊天流 {stream_id} 的旧任务,schedule_id={old_schedule_id}")
|
||||
logger.debug(f"[调度器] 移除聊天流 {stream_id} 的旧任务")
|
||||
await unified_scheduler.remove_schedule(old_schedule_id)
|
||||
logger.info(f"[调度器] 旧任务已移除")
|
||||
|
||||
# 获取 focus_energy 并计算间隔
|
||||
logger.info(f"[调度器] 开始获取聊天流 {stream_id} 的 focus_energy")
|
||||
focus_energy = await self._get_stream_focus_energy(stream_id)
|
||||
logger.info(f"[调度器] 获取到 focus_energy={focus_energy:.3f}")
|
||||
logger.debug(f"[调度器] focus_energy={focus_energy:.3f}")
|
||||
|
||||
interval_seconds = self._calculate_interval(focus_energy)
|
||||
logger.info(f"[调度器] 计算得到触发间隔={interval_seconds}秒 ({interval_seconds/60:.1f}分钟)")
|
||||
logger.debug(f"[调度器] 触发间隔={interval_seconds}秒 ({interval_seconds/60:.1f}分钟)")
|
||||
|
||||
# 导入回调函数(延迟导入避免循环依赖)
|
||||
from src.plugins.built_in.affinity_flow_chatter.proactive_thinking_executor import (
|
||||
@@ -265,7 +263,6 @@ class ProactiveThinkingScheduler:
|
||||
)
|
||||
|
||||
# 创建新任务
|
||||
logger.info(f"[调度器] 开始创建新的调度任务")
|
||||
schedule_id = await unified_scheduler.create_schedule(
|
||||
callback=execute_proactive_thinking,
|
||||
trigger_type=TriggerType.TIME,
|
||||
@@ -278,23 +275,20 @@ class ProactiveThinkingScheduler:
|
||||
)
|
||||
|
||||
self._stream_schedules[stream_id] = schedule_id
|
||||
logger.info(f"[调度器] 新任务已创建,schedule_id={schedule_id}")
|
||||
|
||||
# 计算下次触发时间
|
||||
next_run_time = datetime.now() + timedelta(seconds=interval_seconds)
|
||||
|
||||
logger.info(
|
||||
f"[调度器] ✅ 为聊天流 {stream_id} 创建主动思考任务成功\n"
|
||||
f" - Focus Energy: {focus_energy:.3f}\n"
|
||||
f" - 触发间隔: {interval_seconds}秒 ({interval_seconds/60:.1f}分钟)\n"
|
||||
f" - 下次触发: {next_run_time.strftime('%Y-%m-%d %H:%M:%S')}\n"
|
||||
f" - Schedule ID: {schedule_id}"
|
||||
f"✅ 聊天流 {stream_id} 主动思考任务已创建 | "
|
||||
f"Focus: {focus_energy:.3f} | "
|
||||
f"间隔: {interval_seconds/60:.1f}分钟 | "
|
||||
f"下次: {next_run_time.strftime('%H:%M:%S')}"
|
||||
)
|
||||
return True
|
||||
|
||||
except Exception as e:
|
||||
logger.error(f"[调度器] ❌ 为聊天流 {stream_id} 创建主动思考任务失败: {e}", exc_info=True)
|
||||
logger.error(f"为聊天流 {stream_id} 创建主动思考任务失败: {e}", exc_info=True)
|
||||
logger.error(f"❌ 创建主动思考任务失败 {stream_id}: {e}", exc_info=True)
|
||||
return False
|
||||
|
||||
async def pause_proactive_thinking(self, stream_id: str, reason: str = "抛出话题") -> bool:
|
||||
@@ -321,7 +315,7 @@ class ProactiveThinkingScheduler:
|
||||
|
||||
if success:
|
||||
self._paused_streams.add(stream_id)
|
||||
logger.info(f"暂停聊天流 {stream_id} 的主动思考任务,原因: {reason}")
|
||||
logger.info(f"⏸️ 暂停主动思考 {stream_id},原因: {reason}")
|
||||
|
||||
return success
|
||||
|
||||
@@ -349,12 +343,12 @@ class ProactiveThinkingScheduler:
|
||||
|
||||
if success:
|
||||
self._paused_streams.discard(stream_id)
|
||||
logger.info(f"恢复聊天流 {stream_id} 的主动思考任务")
|
||||
logger.info(f"▶️ 恢复主动思考 {stream_id}")
|
||||
|
||||
return success
|
||||
|
||||
except Exception as e:
|
||||
logger.error(f"恢复聊天流 {stream_id} 的主动思考任务失败: {e}", exc_info=True)
|
||||
logger.error(f"❌ 恢复主动思考失败 {stream_id}: {e}", exc_info=True)
|
||||
return False
|
||||
|
||||
async def cancel_proactive_thinking(self, stream_id: str) -> bool:
|
||||
@@ -375,12 +369,12 @@ class ProactiveThinkingScheduler:
|
||||
self._paused_streams.discard(stream_id)
|
||||
|
||||
success = await unified_scheduler.remove_schedule(schedule_id)
|
||||
logger.info(f"取消聊天流 {stream_id} 的主动思考任务")
|
||||
logger.debug(f"⏹️ 取消主动思考 {stream_id}")
|
||||
|
||||
return success
|
||||
|
||||
except Exception as e:
|
||||
logger.error(f"取消聊天流 {stream_id} 的主动思考任务失败: {e}", exc_info=True)
|
||||
logger.error(f"❌ 取消主动思考失败 {stream_id}: {e}", exc_info=True)
|
||||
return False
|
||||
|
||||
async def is_paused(self, stream_id: str) -> bool:
|
||||
|
||||
Reference in New Issue
Block a user