refactor(action_manager): 简化回复处理逻辑,移除多余的参与者信息获取

This commit is contained in:
Windpicker-owo
2025-11-12 16:23:39 +08:00
parent 20760db7ef
commit 59965bb1ee
3 changed files with 13 additions and 58 deletions

View File

@@ -301,7 +301,7 @@ class ChatterActionManager:
async def _after_reply():
# 发送并存储回复
loop_info, reply_text, cycle_timers_reply = await self._send_and_store_reply(
reply_text, cycle_timers_reply = await self._send_and_store_reply(
chat_stream,
response_set,
asyncio.get_event_loop().time(),
@@ -313,14 +313,14 @@ class ChatterActionManager:
)
# 记录回复动作到目标消息
asyncio.create_task(self._record_action_to_message(chat_stream, action_name, target_message, action_data))
await self._record_action_to_message(chat_stream, action_name, target_message, action_data)
# 回复成功,重置打断计数
await self._reset_interruption_count_after_action(chat_stream.stream_id)
return loop_info, reply_text, cycle_timers_reply
loop_info, reply_text, _ = await _after_reply()
return {"action_type": action_name, "success": True, "reply_text": reply_text, "loop_info": loop_info}
return reply_text
asyncio.create_task(_after_reply())
return {"action_type": action_name, "success": True}
except Exception as e:
logger.error(f"{log_prefix} 执行动作时出错: {e}")
@@ -477,7 +477,7 @@ class ChatterActionManager:
thinking_id,
actions,
should_quote_reply: bool | None = None,
) -> tuple[dict[str, Any], str, dict[str, float]]:
) -> tuple[str, dict[str, float]]:
"""
发送并存储回复信息
@@ -540,20 +540,7 @@ class ChatterActionManager:
action_name="reply",
)
# 构建循环信息
loop_info: dict[str, Any] = {
"loop_plan_info": {
"action_result": actions,
},
"loop_action_info": {
"action_taken": True,
"reply_text": reply_text,
"command": "",
"taken_time": time.time(),
},
}
return loop_info, reply_text, cycle_timers
return reply_text, cycle_timers
async def send_response(
self, chat_stream, reply_set, thinking_start_time, message_data, should_quote_reply: bool | None = None

View File

@@ -587,35 +587,6 @@ class DefaultReplyer:
if user_info_obj:
sender_name = getattr(user_info_obj, "user_nickname", "") or getattr(user_info_obj, "user_cardname", "")
# 获取参与者信息
participants = []
try:
# 尝试从聊天流中获取参与者信息
if hasattr(stream, "context_manager"):
history_manager = stream.context_manager
# 获取最近的参与者列表
recent_records = history_manager.get_memory_chat_history(
user_id=getattr(stream.user_info, "user_id", ""),
count=10,
memory_types=["chat_message", "system_message"]
)
# 提取唯一的参与者名称
for record in recent_records[:5]: # 最近5条记录
content = record.get("content", {})
participant = content.get("participant_name")
if participant and participant not in participants:
participants.append(participant)
# 如果消息包含发送者信息,也添加到参与者列表
if content.get("sender_name") and content.get("sender_name") not in participants:
participants.append(content.get("sender_name"))
except Exception as e:
logger.debug(f"获取参与者信息失败: {e}")
# 如果发送者不在参与者列表中,添加进去
if sender_name and sender_name not in participants:
participants.insert(0, sender_name)
# 格式化聊天历史为更友好的格式
formatted_history = ""
if chat_history:
@@ -627,7 +598,6 @@ class DefaultReplyer:
query_context = {
"chat_history": formatted_history,
"sender": sender_name,
"participants": participants,
}
# 使用记忆管理器的智能检索(多查询策略)