diff --git a/astrbot/builtin_stars/astrbot/long_term_memory.py b/astrbot/builtin_stars/astrbot/long_term_memory.py index e08cdc5157..49c8ccb43d 100644 --- a/astrbot/builtin_stars/astrbot/long_term_memory.py +++ b/astrbot/builtin_stars/astrbot/long_term_memory.py @@ -156,7 +156,8 @@ async def on_req_llm(self, event: AstrMessageEvent, req: ProviderRequest) -> Non chats_str = "\n---\n".join(self.session_chats[event.unified_msg_origin]) cfg = self.cfg(event) - if cfg["enable_active_reply"]: + is_active_reply = getattr(req, "_ltm_active_reply_trigger", False) + if cfg["enable_active_reply"] and is_active_reply: prompt = req.prompt req.prompt = ( f"You are now in a chatroom. The chat history is as follows:\n{chats_str}" @@ -164,7 +165,7 @@ async def on_req_llm(self, event: AstrMessageEvent, req: ProviderRequest) -> Non "Please react to it. Only output your response and do not output any other information. " "You MUST use the SAME language as the chatroom is using." ) - req.contexts = [] # 清空上下文,当使用了主动回复,所有聊天记录都在一个prompt中。 + req.contexts = [] # Only clear contexts for proactive replies; chat history is embedded in the prompt. else: req.system_prompt += ( "You are now in a chatroom. The chat history is as follows: \n" diff --git a/astrbot/builtin_stars/astrbot/main.py b/astrbot/builtin_stars/astrbot/main.py index b4ba48264e..a0526d85db 100644 --- a/astrbot/builtin_stars/astrbot/main.py +++ b/astrbot/builtin_stars/astrbot/main.py @@ -75,11 +75,13 @@ async def on_message(self, event: AstrMessageEvent): logger.error("未找到对话,无法主动回复") return - yield event.request_llm( + req = event.request_llm( prompt=prompt, session_id=event.session_id, - conversation=conv, + conversation=None, # Proactive replies should not overwrite conversation history with chatroom context. ) + setattr(req, "_ltm_active_reply_trigger", True) + yield req except BaseException as e: logger.error(traceback.format_exc()) logger.error(f"主动回复失败: {e}")