feat(chat): refactor logging and integrate no_reply system action

将日志前缀管理集中到context,新增willing_manager依赖,并把no_reply提升为系统级可用动作

- CycleProcessor 统一改从 context 获取 log_prefix
- HeartFChatting 引入 willing_manager
- ResponseHandler _send_response -> send_response 去下划线统一对外接口
- ActionPlanner 将 no_reply 添加至 current_available_actions
This commit is contained in:
Windpicker-owo
2025-09-01 22:41:42 +08:00
parent f7ed3bbb6c
commit 255e3627b4
4 changed files with 25 additions and 11 deletions

View File

@@ -30,9 +30,7 @@ class CycleProcessor:
context: HFC聊天上下文对象包含聊天流、能量值等信息
response_handler: 响应处理器,负责生成和发送回复
cycle_tracker: 循环跟踪器,负责记录和管理每次思考循环的信息
"""
self.log_prefix = f"[{get_chat_manager().get_stream_name(self.stream_id) or self.stream_id}]"
"""
self.context = context
self.response_handler = response_handler
self.cycle_tracker = cycle_tracker
@@ -40,7 +38,9 @@ class CycleProcessor:
self.action_modifier = ActionModifier(
action_manager=self.context.action_manager, chat_id=self.context.stream_id
)
self.log_prefix = self.context.log_prefix
async def _send_and_store_reply(
self,
response_set,
@@ -52,7 +52,7 @@ class CycleProcessor:
plan_result,
) -> Tuple[Dict[str, Any], str, Dict[str, float]]:
with Timer("回复发送", cycle_timers):
reply_text = await self._send_response(response_set, reply_to_str, loop_start_time, action_message)
reply_text = await self.response_handler.send_response(response_set, reply_to_str, loop_start_time, action_message)
# 存储reply action信息
person_info_manager = get_person_info_manager()
@@ -64,7 +64,7 @@ class CycleProcessor:
action_prompt_display = f"你对{person_name}进行了回复:{reply_text}"
await database_api.store_action_info(
chat_stream=self.chat_stream,
chat_stream=self.context.chat_stream,
action_build_into_prompt=False,
action_prompt_display=action_prompt_display,
action_done=True,
@@ -248,7 +248,7 @@ class CycleProcessor:
gather_timeout = global_config.chat.thinking_timeout
try:
response_set = await asyncio.wait_for(
self.response_handler._generate_response(
self.response_handler.generate_response(
message_data=action_info["action_message"],
available_actions=action_info["available_actions"],
reply_to=reply_to_str,
@@ -284,7 +284,6 @@ class CycleProcessor:
"loop_info": None
}
# TODO: Where is my fucking _send_and_store_reply?
loop_info, reply_text, cycle_timers_reply = await self._send_and_store_reply(
response_set,
reply_to_str,

View File

@@ -12,6 +12,7 @@ from src.chat.express.expression_learner import expression_learner_manager
from src.plugin_system.base.component_types import ChatMode
from src.schedule.schedule_manager import schedule_manager, SleepState
from src.plugin_system.apis import message_api
from src.chat.willing.willing_manager import get_willing_manager
from .hfc_context import HfcContext
from .energy_manager import EnergyManager
@@ -59,7 +60,7 @@ class HeartFChatting:
# 记录最近3次的兴趣度
self.recent_interest_records: deque = deque(maxlen=3)
self.willing_manager = get_willing_manager()
self._initialize_chat_mode()
logger.info(f"{self.context.log_prefix} HeartFChatting 初始化完成")

View File

@@ -64,7 +64,7 @@ class ResponseHandler:
- 构建并返回完整的循环信息
- 用于上级方法的状态跟踪
"""
reply_text = await self._send_response(response_set, reply_to_str, loop_start_time, action_message)
reply_text = await self.send_response(response_set, reply_to_str, loop_start_time, action_message)
person_info_manager = get_person_info_manager()
@@ -105,7 +105,7 @@ class ResponseHandler:
return loop_info, reply_text, cycle_timers
async def _send_response(self, reply_set, reply_to, thinking_start_time, message_data) -> str:
async def send_response(self, reply_set, reply_to, thinking_start_time, message_data) -> str:
"""
发送回复内容的具体实现

View File

@@ -575,6 +575,20 @@ class ActionPlanner:
else:
logger.warning(f"{self.log_prefix}使用中的动作 {action_name} 未在已注册动作中找到")
# 将no_reply作为系统级特殊动作添加到可用动作中
# no_reply虽然是系统级决策但需要让规划器认为它是可用的
no_reply_info = ActionInfo(
name="no_reply",
component_type=ComponentType.ACTION,
description="系统级动作:选择不回复消息的决策",
action_parameters={},
activation_keywords=[],
plugin_name="SYSTEM",
enabled=True, # 始终启用
parallel_action=False,
)
current_available_actions["no_reply"] = no_reply_info
return is_group_chat, chat_target_info, current_available_actions