diff --git a/kb_workflow/pipeline/processors/analyze.py b/kb_workflow/pipeline/processors/analyze.py index 8a49f7d..83439dc 100644 --- a/kb_workflow/pipeline/processors/analyze.py +++ b/kb_workflow/pipeline/processors/analyze.py @@ -13,11 +13,6 @@ import sys from pathlib import Path from typing import Optional, Dict, Any -# Add kb-deep-analyzer to path for import -_kb_deep_analyzer_path = Path(__file__).parent.parent.parent / "kb-deep-analyzer" -if str(_kb_deep_analyzer_path) not in sys.path: - sys.path.insert(0, str(_kb_deep_analyzer_path)) - from kb_workflow.pipeline.config import get_settings from kb_workflow.pipeline.schemas import AnalyzeInput, AnalyzeOutput from kb_workflow.pipeline.state import WorkflowStateManager @@ -25,6 +20,9 @@ from kb_workflow.pipeline.processors.base import BaseProcessor logger = logging.getLogger(__name__) +# Flag to ensure sys.path is only modified once for kb-deep-analyzer +_deep_analyzer_path_added = False + class AnalyzeProcessor(BaseProcessor): """Analyze 处理器 - AI 深度内容分析 @@ -201,7 +199,14 @@ class AnalyzeProcessor(BaseProcessor): Returns: AnalysisResult 对象 """ - # Lazy import to avoid dependency issues + # Lazy import with delayed sys.path modification for external kb-deep-analyzer + global _deep_analyzer_path_added + if not _deep_analyzer_path_added: + _kb_deep_analyzer_path = Path(__file__).parent.parent.parent / "kb-deep-analyzer" + if str(_kb_deep_analyzer_path) not in sys.path: + sys.path.insert(0, str(_kb_deep_analyzer_path)) + _deep_analyzer_path_added = True + from deep_analyzer import DeepAnalyzer, SimpleAIClient # 初始化 AI 客户端