From d6805d1db899e5a0f6399f0453f18a5240c1e379 Mon Sep 17 00:00:00 2001 From: root <953994191@qq.com> Date: Wed, 29 Apr 2026 17:23:20 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E9=87=8D=E6=9E=84=E5=90=8E?= =?UTF-8?q?=E7=9A=84=E5=AF=BC=E5=85=A5=E9=94=99=E8=AF=AF=E5=92=8C=E7=BC=BA?= =?UTF-8?q?=E5=A4=B1=E6=A8=A1=E5=9D=97?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- backend/app/agent/history.py | 2 +- backend/app/agent/service.py | 9 ++++---- backend/app/backend.py | 4 ++-- backend/app/logger.py | 2 +- backend/app/main_graph/config.py | 21 +++++++++++++++++++ backend/app/main_graph/graph.py | 8 +++++++ backend/app/main_graph/graph_builder.py | 6 +++--- backend/app/main_graph/nodes/__init__.py | 20 +++++++++++++++++- backend/app/main_graph/nodes/finalize.py | 4 ++-- backend/app/main_graph/nodes/llm_call.py | 6 +++--- .../app/main_graph/nodes/memory_trigger.py | 4 ++-- backend/app/main_graph/nodes/rag_nodes.py | 6 +++--- backend/app/main_graph/nodes/react_nodes.py | 2 +- .../app/main_graph/nodes/retrieve_memory.py | 8 +++---- backend/app/main_graph/nodes/router.py | 4 ++-- backend/app/main_graph/nodes/summarize.py | 6 +++--- backend/app/main_graph/nodes/tool_call.py | 4 ++-- backend/app/main_graph/tools/__init__.py | 9 ++++++++ .../app/main_graph/utils/rag_initializer.py | 6 +++--- backend/app/main_graph/utils/retry_utils.py | 2 +- .../app/main_graph/utils/subgraph_builder.py | 4 ++-- backend/app/memory/mem0_client.py | 4 ++-- backend/app/model_services/chat_services.py | 2 +- .../app/model_services/embedding_services.py | 2 +- backend/app/model_services/rerank_services.py | 2 +- backend/app/subgraphs/contact/__init__.py | 4 ++-- backend/app/subgraphs/contact/api_client.py | 2 +- backend/app/subgraphs/contact/graph.py | 2 +- backend/app/subgraphs/contact/nodes.py | 2 +- backend/app/subgraphs/dictionary/__init__.py | 4 ++-- backend/app/subgraphs/dictionary/graph.py | 2 +- backend/app/subgraphs/dictionary/nodes.py | 2 +- .../app/subgraphs/news_analysis/__init__.py | 4 ++-- backend/app/subgraphs/news_analysis/graph.py | 2 +- backend/app/subgraphs/news_analysis/nodes.py | 2 +- backend/app/utils/logging.py | 4 ++-- 36 files changed, 117 insertions(+), 60 deletions(-) create mode 100644 backend/app/main_graph/config.py create mode 100644 backend/app/main_graph/graph.py diff --git a/backend/app/agent/history.py b/backend/app/agent/history.py index e619da9..09f7124 100644 --- a/backend/app/agent/history.py +++ b/backend/app/agent/history.py @@ -4,7 +4,7 @@ """ from typing import List, Dict, Any -from ..logger import error # 保持兼容,或者替换为 logger +from app.logger import error # 保持兼容,或者替换为 logger class ThreadHistoryService: """线程历史查询服务""" diff --git a/backend/app/agent/service.py b/backend/app/agent/service.py index affa401..31e6893 100644 --- a/backend/app/agent/service.py +++ b/backend/app/agent/service.py @@ -8,11 +8,12 @@ import asyncio # 本地模块 from app.main_graph.graph_builder import GraphBuilder, GraphContext -from app.main_graph.graph_tools import AVAILABLE_TOOLS, TOOLS_BY_NAME +from app.main_graph.tools.graph_tools import AVAILABLE_TOOLS, TOOLS_BY_NAME +from app.main_graph.config import set_stream_writer from ..model_services.chat_services import get_all_chat_services, LocalVLLMChatProvider -from .rag_initializer import init_rag_tool -from .intent_classifier import get_intent_classifier -from ..logger import info, warning +from app.main_graph.utils.rag_initializer import init_rag_tool +from app.core.intent_classifier import get_intent_classifier +from app.logger import info, warning class AIAgentService: def __init__(self, checkpointer): diff --git a/backend/app/backend.py b/backend/app/backend.py index 1977f60..7ce11af 100644 --- a/backend/app/backend.py +++ b/backend/app/backend.py @@ -4,7 +4,7 @@ FastAPI 后端 - 支持动态模型切换,使用 PostgreSQL 持久化记忆 """ import os -from .config import DB_URI, BACKEND_PORT +from app.config import DB_URI, BACKEND_PORT import uuid import json from contextlib import asynccontextmanager @@ -28,7 +28,7 @@ from app.subgraphs.dictionary.api_client import DictionaryAPIClient from app.subgraphs.news_analysis.api_client import NewsAPIClient from .db.init_db import init_subgraph_tables from .db.models import ContactRepository, DictionaryRepository, NewsRepository -from .logger import info, error +from app.logger import info, error @asynccontextmanager async def lifespan(app: FastAPI): diff --git a/backend/app/logger.py b/backend/app/logger.py index 8b263c6..2f99040 100644 --- a/backend/app/logger.py +++ b/backend/app/logger.py @@ -4,7 +4,7 @@ """ import os -from .config import LOG_LEVEL, DEBUG +from app.config import LOG_LEVEL, DEBUG import logging from typing import Any # 根据环境变量控制是否显示详细调试信息 diff --git a/backend/app/main_graph/config.py b/backend/app/main_graph/config.py new file mode 100644 index 0000000..8046743 --- /dev/null +++ b/backend/app/main_graph/config.py @@ -0,0 +1,21 @@ +""" +Main Graph Configuration - Streaming Writer +""" +from typing import Optional, Callable, Any + +_stream_writer: Optional[Callable[[Any], None]] = None + +def set_stream_writer(writer: Callable[[Any], None]): + """Set the global stream writer""" + global _stream_writer + _stream_writer = writer + +def get_stream_writer() -> Callable[[Any], None]: + """Get the global stream writer""" + global _stream_writer + if _stream_writer is None: + # Default no-op writer + def noop(_): + pass + return noop + return _stream_writer diff --git a/backend/app/main_graph/graph.py b/backend/app/main_graph/graph.py new file mode 100644 index 0000000..e46b75a --- /dev/null +++ b/backend/app/main_graph/graph.py @@ -0,0 +1,8 @@ +""" +LangGraph 核心组件重新导出 +统一导入入口,避免直接依赖 langgraph +""" + +from langgraph.graph import StateGraph, START, END, add_messages + +__all__ = ["StateGraph", "START", "END", "add_messages"] diff --git a/backend/app/main_graph/graph_builder.py b/backend/app/main_graph/graph_builder.py index 18cb28a..64ec787 100644 --- a/backend/app/main_graph/graph_builder.py +++ b/backend/app/main_graph/graph_builder.py @@ -5,8 +5,8 @@ LangGraph 状态图构建模块 - 精简版,仅负责组装图 from langchain_core.language_models import BaseLLM from app.main_graph.graph import StateGraph, START, END -from .state import MessagesState, GraphContext -from ..nodes import ( +from app.main_graph.state import MessagesState, GraphContext +from .nodes import ( should_continue, create_llm_call_node, create_tool_call_node, @@ -15,7 +15,7 @@ from ..nodes import ( finalize_node, ) from app.main_graph.nodes.memory_trigger import memory_trigger_node, set_mem0_client -from ..memory import Mem0Client +from app.memory import Mem0Client class GraphBuilder: diff --git a/backend/app/main_graph/nodes/__init__.py b/backend/app/main_graph/nodes/__init__.py index ae9de0f..9401c40 100644 --- a/backend/app/main_graph/nodes/__init__.py +++ b/backend/app/main_graph/nodes/__init__.py @@ -1 +1,19 @@ -"""主图节点""" +""" +主图节点模块导出 +""" + +from .router import should_continue +from .llm_call import create_llm_call_node +from .tool_call import create_tool_call_node +from .retrieve_memory import create_retrieve_memory_node +from .summarize import create_summarize_node +from .finalize import finalize_node + +__all__ = [ + "should_continue", + "create_llm_call_node", + "create_tool_call_node", + "create_retrieve_memory_node", + "create_summarize_node", + "finalize_node", +] diff --git a/backend/app/main_graph/nodes/finalize.py b/backend/app/main_graph/nodes/finalize.py index dd52a2c..134379a 100644 --- a/backend/app/main_graph/nodes/finalize.py +++ b/backend/app/main_graph/nodes/finalize.py @@ -8,8 +8,8 @@ from app.main_graph.config import get_stream_writer # 本地模块 from app.main_graph.state import MessagesState -from ..utils.logging import log_state_change -from ..logger import info, error +from app.utils.logging import log_state_change +from app.logger import info, error from langchain_core.runnables.config import RunnableConfig diff --git a/backend/app/main_graph/nodes/llm_call.py b/backend/app/main_graph/nodes/llm_call.py index 207b64d..c391fef 100644 --- a/backend/app/main_graph/nodes/llm_call.py +++ b/backend/app/main_graph/nodes/llm_call.py @@ -10,9 +10,9 @@ from langchain_core.messages import AIMessage # 本地模块 from app.main_graph.state import MessagesState -from ..agent.prompts import create_system_prompt -from ..utils.logging import log_state_change -from ..logger import debug, info, error +from app.agent.prompts import create_system_prompt +from app.utils.logging import log_state_change +from app.logger import debug, info, error def create_llm_call_node(llm: BaseLLM, tools: list): """ diff --git a/backend/app/main_graph/nodes/memory_trigger.py b/backend/app/main_graph/nodes/memory_trigger.py index 0784dd6..523e52c 100644 --- a/backend/app/main_graph/nodes/memory_trigger.py +++ b/backend/app/main_graph/nodes/memory_trigger.py @@ -1,8 +1,8 @@ from typing import Any, Dict from langchain_core.runnables.config import RunnableConfig from app.main_graph.state import MessagesState -from ..memory.mem0_client import Mem0Client -from ..logger import info +from app.memory.mem0_client import Mem0Client +from app.logger import info # 全局变量,在 GraphBuilder 中注入 _mem0_client: Mem0Client = None diff --git a/backend/app/main_graph/nodes/rag_nodes.py b/backend/app/main_graph/nodes/rag_nodes.py index 4dd2bde..deeb949 100644 --- a/backend/app/main_graph/nodes/rag_nodes.py +++ b/backend/app/main_graph/nodes/rag_nodes.py @@ -11,7 +11,7 @@ import asyncio from typing import Dict, Any, Optional from datetime import datetime -from .state import MainGraphState, ErrorRecord, ErrorSeverity +from app.main_graph.state import MainGraphState, ErrorRecord, ErrorSeverity from .retry_utils import ( RetryConfig, RAG_RETRY_CONFIG, @@ -19,8 +19,8 @@ from .retry_utils import ( ) # 真正导入和利用已有 RAG 代码 -from ..rag.tools import create_rag_tool_sync -from ..rag.pipeline import RAGPipeline +from app.rag.tools import create_rag_tool_sync +from app.rag.pipeline import RAGPipeline # ========== 全局 RAG 工具实例(延迟初始化)========== diff --git a/backend/app/main_graph/nodes/react_nodes.py b/backend/app/main_graph/nodes/react_nodes.py index d2fecb1..b0338c0 100644 --- a/backend/app/main_graph/nodes/react_nodes.py +++ b/backend/app/main_graph/nodes/react_nodes.py @@ -22,7 +22,7 @@ from app.core.intent import ( ReasoningResult ) from app.core.state_base import StateUtils -from .state import MainGraphState, ErrorRecord, ErrorSeverity +from app.main_graph.state import MainGraphState, ErrorRecord, ErrorSeverity from .retry_utils import ( RetryConfig, SUBGRAPH_RETRY_CONFIG diff --git a/backend/app/main_graph/nodes/retrieve_memory.py b/backend/app/main_graph/nodes/retrieve_memory.py index 36453b0..ec85655 100644 --- a/backend/app/main_graph/nodes/retrieve_memory.py +++ b/backend/app/main_graph/nodes/retrieve_memory.py @@ -6,10 +6,10 @@ from typing import Any, Dict # 本地模块 -from .state import MessagesState -from ..memory.mem0_client import Mem0Client -from ..utils.logging import log_state_change -from ..logger import debug +from app.main_graph.state import MessagesState +from app.memory.mem0_client import Mem0Client +from app.utils.logging import log_state_change +from app.logger import debug def create_retrieve_memory_node(mem0_client: Mem0Client): """ diff --git a/backend/app/main_graph/nodes/router.py b/backend/app/main_graph/nodes/router.py index b703adb..552dce9 100644 --- a/backend/app/main_graph/nodes/router.py +++ b/backend/app/main_graph/nodes/router.py @@ -7,9 +7,9 @@ from typing import Literal from langchain_core.messages import AIMessage # 本地模块 -from ..config import ENABLE_GRAPH_TRACE, MEMORY_SUMMARIZE_INTERVAL +from app.config import ENABLE_GRAPH_TRACE, MEMORY_SUMMARIZE_INTERVAL from app.main_graph.state import MessagesState -from ..logger import info +from app.logger import info def should_continue(state: MessagesState) -> Literal['tool_node', 'summarize', 'finalize']: diff --git a/backend/app/main_graph/nodes/summarize.py b/backend/app/main_graph/nodes/summarize.py index a2c7f9e..fc9ac02 100644 --- a/backend/app/main_graph/nodes/summarize.py +++ b/backend/app/main_graph/nodes/summarize.py @@ -7,9 +7,9 @@ from typing import Any, Dict # 本地模块 from app.main_graph.state import MessagesState -from ..memory.mem0_client import Mem0Client -from ..utils.logging import log_state_change -from ..logger import debug, info, error, warning +from app.memory.mem0_client import Mem0Client +from app.utils.logging import log_state_change +from app.logger import debug, info, error, warning def create_summarize_node(mem0_client: Mem0Client): """ diff --git a/backend/app/main_graph/nodes/tool_call.py b/backend/app/main_graph/nodes/tool_call.py index e23e3d6..0f9a9c3 100644 --- a/backend/app/main_graph/nodes/tool_call.py +++ b/backend/app/main_graph/nodes/tool_call.py @@ -10,8 +10,8 @@ from app.main_graph.config import get_stream_writer # 本地模块 from app.main_graph.state import MessagesState -from ..utils.logging import log_state_change -from ..logger import debug, info +from app.utils.logging import log_state_change +from app.logger import debug, info def create_tool_call_node(tools_by_name: Dict[str, Any]): """ diff --git a/backend/app/main_graph/tools/__init__.py b/backend/app/main_graph/tools/__init__.py index 72f9f49..3244249 100644 --- a/backend/app/main_graph/tools/__init__.py +++ b/backend/app/main_graph/tools/__init__.py @@ -1 +1,10 @@ """主图工具""" +from .graph_tools import AVAILABLE_TOOLS, TOOLS_BY_NAME +from .subgraph_tools import SUBGRAPH_TOOLS, SUBGRAPH_TOOLS_BY_NAME + +__all__ = [ + "AVAILABLE_TOOLS", + "TOOLS_BY_NAME", + "SUBGRAPH_TOOLS", + "SUBGRAPH_TOOLS_BY_NAME", +] diff --git a/backend/app/main_graph/utils/rag_initializer.py b/backend/app/main_graph/utils/rag_initializer.py index 95b8b59..5ab6833 100644 --- a/backend/app/main_graph/utils/rag_initializer.py +++ b/backend/app/main_graph/utils/rag_initializer.py @@ -1,8 +1,8 @@ # app/rag_initializer.py -from ..rag.tools import create_rag_tool_sync +from app.rag.tools import create_rag_tool_sync from rag_core import create_parent_retriever -from ..model_services import get_embedding_service -from ..logger import info, warning +from app.model_services import get_embedding_service +from app.logger import info, warning async def init_rag_tool(local_llm_creator): """初始化 RAG 工具,失败返回 None""" diff --git a/backend/app/main_graph/utils/retry_utils.py b/backend/app/main_graph/utils/retry_utils.py index a883d02..1b77844 100644 --- a/backend/app/main_graph/utils/retry_utils.py +++ b/backend/app/main_graph/utils/retry_utils.py @@ -287,7 +287,7 @@ def create_retry_wrapper_for_node( time.sleep(delay) # 所有重试都失败,更新状态错误信息 - from .state import ErrorRecord, ErrorSeverity + from app.main_graph.state import ErrorRecord, ErrorSeverity error_record = ErrorRecord( error_type=f"{node_name}TimeoutError", diff --git a/backend/app/main_graph/utils/subgraph_builder.py b/backend/app/main_graph/utils/subgraph_builder.py index 5199ec8..9d3868f 100644 --- a/backend/app/main_graph/utils/subgraph_builder.py +++ b/backend/app/main_graph/utils/subgraph_builder.py @@ -6,7 +6,7 @@ Main Graph Builder - Full React Mode with Loop Reasoning from app.main_graph.graph import StateGraph, START, END from typing import Dict, Any -from .state import MainGraphState, CurrentAction +from app.main_graph.state import MainGraphState, CurrentAction from .react_nodes import ( init_state_node, react_reason_node, @@ -50,7 +50,7 @@ def wrap_subgraph_for_error_handling(subgraph, name: str): except Exception as e: # 捕获子图错误,传递给主图 - from .state import ErrorRecord, ErrorSeverity + from app.main_graph.state import ErrorRecord, ErrorSeverity from datetime import datetime error_record = ErrorRecord( diff --git a/backend/app/memory/mem0_client.py b/backend/app/memory/mem0_client.py index cbc114a..f004fe6 100644 --- a/backend/app/memory/mem0_client.py +++ b/backend/app/memory/mem0_client.py @@ -1,11 +1,11 @@ -from ..config import ( +from app.config import ( LLM_API_KEY, ZHIPUAI_API_KEY, VLLM_BASE_URL, QDRANT_URL, QDRANT_COLLECTION_NAME, QDRANT_API_KEY, LLAMACPP_EMBEDDING_URL, LLAMACPP_API_KEY, ZHIPU_EMBEDDING_MODEL, ZHIPU_API_BASE ) from ..model_services import get_embedding_service -from ..logger import info, warning, error +from app.logger import info, warning, error import time """ Mem0 记忆层客户端封装模块 diff --git a/backend/app/model_services/chat_services.py b/backend/app/model_services/chat_services.py index 3bf0184..552a74b 100644 --- a/backend/app/model_services/chat_services.py +++ b/backend/app/model_services/chat_services.py @@ -23,7 +23,7 @@ from .base import ( FallbackServiceChain, SingletonServiceManager ) -from ..config import ( +from app.config import ( VLLM_BASE_URL, LLM_API_KEY, ZHIPUAI_API_KEY, diff --git a/backend/app/model_services/embedding_services.py b/backend/app/model_services/embedding_services.py index baef33e..d830015 100644 --- a/backend/app/model_services/embedding_services.py +++ b/backend/app/model_services/embedding_services.py @@ -21,7 +21,7 @@ from .base import ( FallbackServiceChain, SingletonServiceManager ) -from ..config import ( +from app.config import ( LLAMACPP_EMBEDDING_URL, LLAMACPP_API_KEY, ZHIPUAI_API_KEY, diff --git a/backend/app/model_services/rerank_services.py b/backend/app/model_services/rerank_services.py index 56a5736..c1fff27 100644 --- a/backend/app/model_services/rerank_services.py +++ b/backend/app/model_services/rerank_services.py @@ -23,7 +23,7 @@ from .base import ( FallbackServiceChain, SingletonServiceManager ) -from ..config import ( +from app.config import ( LLAMACPP_RERANKER_URL, LLAMACPP_API_KEY, ZHIPUAI_API_KEY, diff --git a/backend/app/subgraphs/contact/__init__.py b/backend/app/subgraphs/contact/__init__.py index cb55dd4..009e7a7 100644 --- a/backend/app/subgraphs/contact/__init__.py +++ b/backend/app/subgraphs/contact/__init__.py @@ -3,13 +3,13 @@ Contact Subgraph Module - Complete """ -from .state import ( +from app.main_graph.state import ( ContactState, Contact, Email, ContactAction ) -from .graph import build_contact_subgraph +from app.main_graph.graph import build_contact_subgraph from .nodes import ( parse_intent, list_contacts, diff --git a/backend/app/subgraphs/contact/api_client.py b/backend/app/subgraphs/contact/api_client.py index ea6b3f3..ac76d81 100644 --- a/backend/app/subgraphs/contact/api_client.py +++ b/backend/app/subgraphs/contact/api_client.py @@ -6,7 +6,7 @@ from typing import Dict, Any, Optional, List from datetime import datetime from dataclasses import dataclass -from .state import Contact, Email +from app.main_graph.state import Contact, Email # ========== 模拟数据(保留作为备选)========== diff --git a/backend/app/subgraphs/contact/graph.py b/backend/app/subgraphs/contact/graph.py index 4026179..474d9f0 100644 --- a/backend/app/subgraphs/contact/graph.py +++ b/backend/app/subgraphs/contact/graph.py @@ -6,7 +6,7 @@ Contact Subgraph Builder from app.main_graph.graph import StateGraph, START, END -from .state import ContactState +from app.main_graph.state import ContactState from .nodes import create_contact_nodes diff --git a/backend/app/subgraphs/contact/nodes.py b/backend/app/subgraphs/contact/nodes.py index c8a62ba..3d2918e 100644 --- a/backend/app/subgraphs/contact/nodes.py +++ b/backend/app/subgraphs/contact/nodes.py @@ -10,7 +10,7 @@ from datetime import datetime # 公共工具 from ..common import MarkdownFormatter -from .state import ContactState, ContactAction, Contact, Email +from app.main_graph.state import ContactState, ContactAction, Contact, Email from .api_client import ContactAPIClient diff --git a/backend/app/subgraphs/dictionary/__init__.py b/backend/app/subgraphs/dictionary/__init__.py index 600f1b0..10e34e5 100644 --- a/backend/app/subgraphs/dictionary/__init__.py +++ b/backend/app/subgraphs/dictionary/__init__.py @@ -3,13 +3,13 @@ Dictionary Subgraph Module - Complete """ -from .state import ( +from app.main_graph.state import ( DictionaryState, DictionaryAction, WordEntry, ExtractedTerm ) -from .graph import build_dictionary_subgraph +from app.main_graph.graph import build_dictionary_subgraph from .nodes import ( parse_intent, query_word, diff --git a/backend/app/subgraphs/dictionary/graph.py b/backend/app/subgraphs/dictionary/graph.py index bc65340..a3cebbc 100644 --- a/backend/app/subgraphs/dictionary/graph.py +++ b/backend/app/subgraphs/dictionary/graph.py @@ -5,7 +5,7 @@ Dictionary Subgraph Builder - Complete from app.main_graph.graph import StateGraph, START, END -from .state import DictionaryState +from app.main_graph.state import DictionaryState from .nodes import ( parse_intent, query_word, diff --git a/backend/app/subgraphs/dictionary/nodes.py b/backend/app/subgraphs/dictionary/nodes.py index faf06c3..a839f07 100644 --- a/backend/app/subgraphs/dictionary/nodes.py +++ b/backend/app/subgraphs/dictionary/nodes.py @@ -12,7 +12,7 @@ from ..common import ( MarkdownFormatter ) -from .state import ( +from app.main_graph.state import ( DictionaryState, DictionaryAction, WordEntry, diff --git a/backend/app/subgraphs/news_analysis/__init__.py b/backend/app/subgraphs/news_analysis/__init__.py index 4b1e7dd..e66c4e9 100644 --- a/backend/app/subgraphs/news_analysis/__init__.py +++ b/backend/app/subgraphs/news_analysis/__init__.py @@ -3,13 +3,13 @@ News Analysis Subgraph Module - Complete """ -from .state import ( +from app.main_graph.state import ( NewsAnalysisState, NewsAction, NewsItem, NewsSource ) -from .graph import build_news_analysis_subgraph +from app.main_graph.graph import build_news_analysis_subgraph from .nodes import ( parse_intent, query_news, diff --git a/backend/app/subgraphs/news_analysis/graph.py b/backend/app/subgraphs/news_analysis/graph.py index 1aa07c8..b5a016f 100644 --- a/backend/app/subgraphs/news_analysis/graph.py +++ b/backend/app/subgraphs/news_analysis/graph.py @@ -5,7 +5,7 @@ News Analysis Subgraph Builder from app.main_graph.graph import StateGraph, START, END -from .state import NewsAnalysisState +from app.main_graph.state import NewsAnalysisState from .nodes import ( parse_intent, query_news, diff --git a/backend/app/subgraphs/news_analysis/nodes.py b/backend/app/subgraphs/news_analysis/nodes.py index bd8e9d9..0f38654 100644 --- a/backend/app/subgraphs/news_analysis/nodes.py +++ b/backend/app/subgraphs/news_analysis/nodes.py @@ -9,7 +9,7 @@ from datetime import datetime # 公共工具 from ..common import MarkdownFormatter -from .state import ( +from app.main_graph.state import ( NewsAnalysisState, NewsAction, NewsItem, diff --git a/backend/app/utils/logging.py b/backend/app/utils/logging.py index ae513fd..8228366 100644 --- a/backend/app/utils/logging.py +++ b/backend/app/utils/logging.py @@ -3,8 +3,8 @@ LangGraph 节点日志工具模块 提供状态流转追踪和 LLM 输入输出打印功能 """ -from ..config import ENABLE_GRAPH_TRACE -from ..logger import debug, info +from app.config import ENABLE_GRAPH_TRACE +from app.logger import debug, info def log_state_change(node_name: str, state: dict, prefix: str = "进入"):