重构架构:恢复统一的 llm_call 节点,移除错误的 final_response 节点
All checks were successful
构建并部署 AI Agent 服务 / deploy (push) Successful in 5m50s
All checks were successful
构建并部署 AI Agent 服务 / deploy (push) Successful in 5m50s
This commit is contained in:
@@ -10,11 +10,11 @@ from app.main_graph.state import MainGraphState, CurrentAction
|
||||
from app.main_graph.nodes.react_nodes import (
|
||||
init_state_node,
|
||||
react_reason_node,
|
||||
web_search_node, # ⭐ 新增
|
||||
web_search_node,
|
||||
error_handling_node,
|
||||
final_response_node,
|
||||
route_by_reasoning
|
||||
)
|
||||
from app.main_graph.nodes.llm_call import create_llm_call_node
|
||||
from app.main_graph.nodes.rag_nodes import rag_retrieve_node
|
||||
from app.subgraphs.contact import build_contact_subgraph
|
||||
from app.subgraphs.dictionary import build_dictionary_subgraph
|
||||
@@ -75,10 +75,10 @@ def wrap_subgraph_for_error_handling(subgraph, name: str):
|
||||
|
||||
|
||||
# ========== 主图构建 ==========
|
||||
def build_react_main_graph() -> StateGraph:
|
||||
def build_react_main_graph(llm=None, tools=None) -> StateGraph:
|
||||
"""
|
||||
构建完整的 React 模式主图
|
||||
|
||||
|
||||
流程:
|
||||
START
|
||||
↓
|
||||
@@ -87,18 +87,23 @@ def build_react_main_graph() -> StateGraph:
|
||||
react_reason (推理) ←──────────────┐
|
||||
↓ │
|
||||
条件路由 │
|
||||
├─→ rag_retrieve →───────────────┤
|
||||
├─→ contact_subgraph →───────────┤
|
||||
├─→ dictionary_subgraph →────────┤
|
||||
├─→ news_analysis_subgraph →─────┤
|
||||
├─→ handle_error → (重试或结束) ──┤
|
||||
└─→ final_response
|
||||
├─ rag_retrieve →───────────────┤
|
||||
├─ contact_subgraph →───────────┤
|
||||
├─ dictionary_subgraph →────────┤
|
||||
├─ news_analysis_subgraph →─────┤
|
||||
├─ handle_error → (重试或结束) ─┤
|
||||
└─ llm_call → END
|
||||
↓
|
||||
END
|
||||
"""
|
||||
# 创建图
|
||||
graph = StateGraph(MainGraphState)
|
||||
|
||||
# 创建 llm_call 节点
|
||||
llm_node = None
|
||||
if llm is not None:
|
||||
llm_node = create_llm_call_node(llm, tools or [])
|
||||
|
||||
# ========== 添加节点 ==========
|
||||
|
||||
# 1. 初始化节点
|
||||
@@ -110,14 +115,15 @@ def build_react_main_graph() -> StateGraph:
|
||||
# 3. RAG 检索节点
|
||||
graph.add_node("rag_retrieve", rag_retrieve_node)
|
||||
|
||||
# 4. 联网搜索节点 ⭐ 新增
|
||||
# 4. 联网搜索节点
|
||||
graph.add_node("web_search", web_search_node)
|
||||
|
||||
# 5. 错误处理节点
|
||||
graph.add_node("handle_error", error_handling_node)
|
||||
|
||||
# 6. 最终回答节点
|
||||
graph.add_node("final_response", final_response_node)
|
||||
# 6. LLM 调用节点(真正的大模型输出)
|
||||
if llm_node is not None:
|
||||
graph.add_node("llm_call", llm_node)
|
||||
|
||||
# ========== 添加子图节点 ==========
|
||||
|
||||
@@ -154,33 +160,34 @@ def build_react_main_graph() -> StateGraph:
|
||||
{
|
||||
# 检索分支 → 检索后回到推理
|
||||
"rag_retrieve": "rag_retrieve",
|
||||
|
||||
# 联网搜索分支 ⭐ 新增
|
||||
|
||||
# 联网搜索分支
|
||||
"web_search": "web_search",
|
||||
|
||||
|
||||
# 子图分支 → 子图后回到推理
|
||||
"contact_subgraph": "contact_subgraph",
|
||||
"dictionary_subgraph": "dictionary_subgraph",
|
||||
"news_analysis_subgraph": "news_analysis_subgraph",
|
||||
|
||||
|
||||
# 错误处理分支
|
||||
"handle_error": "handle_error",
|
||||
|
||||
# 最终回答分支
|
||||
"final_response": "final_response",
|
||||
|
||||
# LLM 调用分支 → 直接输出给用户
|
||||
"llm_call": "llm_call"
|
||||
}
|
||||
)
|
||||
|
||||
# 4. 循环边:检索/搜索/子图/错误处理 后 → 回到推理
|
||||
|
||||
# 4. 循环边:检索/搜索/子图/错误处理后 → 回到推理
|
||||
graph.add_edge("rag_retrieve", "react_reason")
|
||||
graph.add_edge("web_search", "react_reason") # ⭐ 新增
|
||||
graph.add_edge("web_search", "react_reason")
|
||||
graph.add_edge("contact_subgraph", "react_reason")
|
||||
graph.add_edge("dictionary_subgraph", "react_reason")
|
||||
graph.add_edge("news_analysis_subgraph", "react_reason")
|
||||
graph.add_edge("handle_error", "react_reason") # 错误处理后可能重试
|
||||
|
||||
# 5. 最终边:final_response → END
|
||||
graph.add_edge("final_response", END)
|
||||
graph.add_edge("handle_error", "react_reason")
|
||||
|
||||
# 5. 最终边:llm_call → END
|
||||
if llm_node is not None:
|
||||
graph.add_edge("llm_call", END)
|
||||
|
||||
return graph
|
||||
|
||||
|
||||
Reference in New Issue
Block a user