diff --git a/astrbot/core/pipeline/process_stage/method/llm_request.py b/astrbot/core/pipeline/process_stage/method/llm_request.py index e352953aa..d6542da88 100644 --- a/astrbot/core/pipeline/process_stage/method/llm_request.py +++ b/astrbot/core/pipeline/process_stage/method/llm_request.py @@ -89,6 +89,11 @@ class LLMRequestSubStage(Stage): "provider_request 必须是 ProviderRequest 类型。" ) + # 检查会话级别的LLM启停状态(防止事件钩子绕过会话级别限制) + if not SessionServiceManager.should_process_llm_request(event): + logger.debug(f"会话 {event.unified_msg_origin} 禁用了 LLM,拒绝事件钩子/插件的 LLM 请求。") + return + if req.conversation: all_contexts = json.loads(req.conversation.history) req.contexts = self._process_tool_message_pairs( @@ -189,6 +194,12 @@ class LLMRequestSubStage(Stage): need_loop = True while need_loop: need_loop = False + + # 在每次实际请求 LLM 前检查会话级别的启停状态,这可以防止插件或函数工具调用时绕过会话级别的限制 + if not SessionServiceManager.should_process_llm_request(event): + logger.debug(f"会话 {event.unified_msg_origin} 禁用了 LLM,终止 LLM 请求。") + return + logger.debug(f"提供商请求 Payload: {req}") final_llm_response = None @@ -303,6 +314,11 @@ class LLMRequestSubStage(Stage): async def _handle_webchat(self, event: AstrMessageEvent, req: ProviderRequest): """处理 WebChat 平台的特殊情况,包括第一次 LLM 对话时总结对话内容生成 title""" + # 检查会话级别的LLM启停状态,防止标题生成功能绕过会话级别限制 + if not SessionServiceManager.should_process_llm_request(event): + logger.debug(f"会话 {event.unified_msg_origin} 禁用了 LLM,跳过 WebChat 标题生成。") + return + conversation = await self.conv_manager.get_conversation( event.unified_msg_origin, req.conversation.cid )