From 7a08aacced98aac66d3ba5349e3d2e8f1976b7f5 Mon Sep 17 00:00:00 2001 From: root <953994191@qq.com> Date: Fri, 1 May 2026 00:24:00 +0800 Subject: [PATCH] =?UTF-8?q?refactor:=20=E9=87=8D=E5=91=BD=E5=90=8D?= =?UTF-8?q?=E6=96=87=E4=BB=B6=E6=9B=B4=E6=B8=85=E6=99=B0=EF=BC=8C=E8=B0=83?= =?UTF-8?q?=E6=95=B4=E6=9C=80=E5=A4=A7=E6=8E=A8=E7=90=86=E6=AD=A5=E6=95=B0?= =?UTF-8?q?=E4=B8=BA10=20-=20subgraph=5Fbuilder.py=20=E2=86=92=20main=5Fgr?= =?UTF-8?q?aph=5Fbuilder.py=20-=20service.py=20=E2=86=92=20agent=5Fservice?= =?UTF-8?q?.py=20-=20=E8=B0=83=E6=95=B4=20max=5Fsteps=20=E4=BB=8E=2040=20?= =?UTF-8?q?=E2=86=92=2010=20-=20=E6=9B=B4=E6=96=B0=E6=89=80=E6=9C=89?= =?UTF-8?q?=E7=9B=B8=E5=85=B3=E5=AF=BC=E5=85=A5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- backend/app/__init__.py | 2 +- backend/app/agent/{service.py => agent_service.py} | 2 +- backend/app/backend.py | 2 +- backend/app/main_graph/nodes/react_nodes.py | 2 +- backend/app/main_graph/state.py | 2 +- .../utils/{subgraph_builder.py => main_graph_builder.py} | 0 backend/app/main_graph/utils/visualize_graph.py | 2 +- test/test_backend.py | 2 +- 8 files changed, 7 insertions(+), 7 deletions(-) rename backend/app/agent/{service.py => agent_service.py} (99%) rename backend/app/main_graph/utils/{subgraph_builder.py => main_graph_builder.py} (100%) diff --git a/backend/app/__init__.py b/backend/app/__init__.py index 7b70c1a..5900015 100644 --- a/backend/app/__init__.py +++ b/backend/app/__init__.py @@ -2,7 +2,7 @@ AI Agent 应用模块 """ -from .agent.service import AIAgentService +from .agent.agent_service import AIAgentService from app.main_graph.tools.graph_tools import AVAILABLE_TOOLS, TOOLS_BY_NAME __all__ = ["AIAgentService", "AVAILABLE_TOOLS", "TOOLS_BY_NAME"] diff --git a/backend/app/agent/service.py b/backend/app/agent/agent_service.py similarity index 99% rename from backend/app/agent/service.py rename to backend/app/agent/agent_service.py index 5f6776a..552f711 100644 --- a/backend/app/agent/service.py +++ b/backend/app/agent/agent_service.py @@ -7,7 +7,7 @@ import json import asyncio # 本地模块 -from app.main_graph.utils.subgraph_builder import build_react_main_graph +from app.main_graph.utils.main_graph_builder import build_react_main_graph 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 diff --git a/backend/app/backend.py b/backend/app/backend.py index c8ea409..bbf33e3 100644 --- a/backend/app/backend.py +++ b/backend/app/backend.py @@ -15,7 +15,7 @@ from fastapi.middleware.cors import CORSMiddleware from fastapi.responses import StreamingResponse from pydantic import BaseModel from langgraph.checkpoint.postgres.aio import AsyncPostgresSaver -from .agent.service import AIAgentService +from .agent.agent_service import AIAgentService from .agent.history import ThreadHistoryService from app.core.human_review import ( ReviewManager, diff --git a/backend/app/main_graph/nodes/react_nodes.py b/backend/app/main_graph/nodes/react_nodes.py index 2843aa1..a55c4a8 100644 --- a/backend/app/main_graph/nodes/react_nodes.py +++ b/backend/app/main_graph/nodes/react_nodes.py @@ -325,7 +325,7 @@ def route_by_reasoning(state: MainGraphState) -> str: route = get_route_by_reasoning(reasoning_result) # 映射到我们的节点名称 - # 注意:这些名称必须与 subgraph_builder.py 中定义的节点名称一致 + # 注意:这些名称必须与 main_graph_builder.py 中定义的节点名称一致 route_mapping = { "direct_response": "final_response", "retrieve_rag": "rag_retrieve", diff --git a/backend/app/main_graph/state.py b/backend/app/main_graph/state.py index ed08255..44c90dd 100644 --- a/backend/app/main_graph/state.py +++ b/backend/app/main_graph/state.py @@ -79,7 +79,7 @@ class MainGraphState: # ========== React 推理专用字段 ========== reasoning_step: int = 0 # 当前推理步数 - max_steps: int = 40 # 最大推理步数(≤40) + max_steps: int = 10 # 最大推理步数(≤10) last_action: str = "" # 上一步动作 reasoning_history: List[Dict[str, Any]] = field(default_factory=list) # 推理历史 diff --git a/backend/app/main_graph/utils/subgraph_builder.py b/backend/app/main_graph/utils/main_graph_builder.py similarity index 100% rename from backend/app/main_graph/utils/subgraph_builder.py rename to backend/app/main_graph/utils/main_graph_builder.py diff --git a/backend/app/main_graph/utils/visualize_graph.py b/backend/app/main_graph/utils/visualize_graph.py index c50e72e..1743d47 100644 --- a/backend/app/main_graph/utils/visualize_graph.py +++ b/backend/app/main_graph/utils/visualize_graph.py @@ -23,7 +23,7 @@ if str(PROJECT_ROOT) not in sys.path: load_dotenv(PROJECT_ROOT / ".env") -from app.agent.service import AIAgentService +from app.agent.agent_service import AIAgentService from app.config import DB_URI from app.main_graph.checkpoint.postgres.aio import AsyncPostgresSaver import asyncio diff --git a/test/test_backend.py b/test/test_backend.py index 19af1ad..679af38 100644 --- a/test/test_backend.py +++ b/test/test_backend.py @@ -19,7 +19,7 @@ load_dotenv() from backend.app.config import DB_URI from langgraph.checkpoint.postgres.aio import AsyncPostgresSaver -from backend.app.agent.service import AIAgentService +from backend.app.agent.agent_service import AIAgentService from backend.app.agent.history import ThreadHistoryService from backend.app.logger import info, warning, error