From 4b8beffe0185b9e3e77b515c06ea94a47a4bfdbf Mon Sep 17 00:00:00 2001 From: AgIzT <18535736920@163.com> Date: Fri, 17 Apr 2026 03:02:40 +0800 Subject: [PATCH 1/2] fix: preserve contexts for non-active group replies --- astrbot/builtin_stars/astrbot/long_term_memory.py | 5 +++-- astrbot/builtin_stars/astrbot/main.py | 4 +++- 2 files changed, 6 insertions(+), 3 deletions(-) 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..c1ea0d9f9d 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, ) + setattr(req, "_ltm_active_reply_trigger", True) + yield req except BaseException as e: logger.error(traceback.format_exc()) logger.error(f"主动回复失败: {e}") From 66b1338f66c1cec3b50e04a242ea9784096f5687 Mon Sep 17 00:00:00 2001 From: AgIzT <18535736920@163.com> Date: Fri, 17 Apr 2026 15:15:54 +0800 Subject: [PATCH 2/2] fix: avoid persisting proactive reply chatroom context --- astrbot/builtin_stars/astrbot/main.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/astrbot/builtin_stars/astrbot/main.py b/astrbot/builtin_stars/astrbot/main.py index c1ea0d9f9d..a0526d85db 100644 --- a/astrbot/builtin_stars/astrbot/main.py +++ b/astrbot/builtin_stars/astrbot/main.py @@ -78,7 +78,7 @@ async def on_message(self, event: AstrMessageEvent): 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