重构:清理废弃代码 + 优化 Agent 架构
All checks were successful
构建并部署 AI Agent 服务 / deploy (push) Successful in 5m24s

主要变更:
- 删除 deprecated 文件夹(intent/hybrid_router/rag_nodes 等)
- 删除 intent_classifier.py(未使用)
- 删除 subgraph_wrapper.py(死代码)
- 重构 agent.py:简化工厂函数,支持动态模型切换
- 重构 prompts.py:添加信息获取优先级、思维链要求、工具调用约束
- 优化 tools:统一位置,rag_search 返回置信度评估
- 新增 RAG 置信度评估:embedding(25%) + rerank(25%) + LLM(50%)
- 添加循环检测:防止工具无限重复调用

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
This commit is contained in:
2026-05-08 00:29:12 +08:00
parent a155b6e5ea
commit 6dfa9f572e
27 changed files with 444 additions and 3874 deletions

View File

@@ -7,8 +7,7 @@ from langgraph.graph import StateGraph, START, END
from backend.app.main_graph.state import AgentState
from backend.app.main_graph.nodes.memory_trigger import memory_trigger_node, set_mem0_client
from backend.app.main_graph.nodes.agent import create_agent_node
from backend.app.logger import info, warning
from backend.app.tools import ALL_TOOLS
from backend.app.logger import info
def build_agent_graph(
@@ -27,9 +26,6 @@ def build_agent_graph(
Returns:
构建好的 StateGraph未编译
"""
# 获取主模型
primary_model = chat_services.get("primary", next(iter(chat_services.values())))
# ========== 设置全局客户端 ==========
if mem0_client:
set_mem0_client(mem0_client)
@@ -51,9 +47,8 @@ def build_agent_graph(
except Exception as e:
info(f"[Graph Builder] 记忆节点初始化失败: {e}")
# ========== 3. Agent 节点(包含完整 ReAct 循环) ==========
llm_with_tools = primary_model.bind_tools(ALL_TOOLS)
agent_node_fn = create_agent_node(llm_with_tools, primary_model)
# ========== 3. Agent 节点(包含完整 ReAct 循环,支持动态模型切换 ==========
agent_node_fn = create_agent_node(chat_services)
# ========== 4. 完成节点 ==========
async def finalize_node_simple(state: AgentState):