refactor: 重构快速路径流程,统一通过 llm_call 输出
All checks were successful
构建并部署 AI Agent 服务 / deploy (push) Successful in 5m31s
All checks were successful
构建并部署 AI Agent 服务 / deploy (push) Successful in 5m31s
- 重构 fast_paths.py,让 fast_chitchat 和 fast_rag 都进入 llm_call 而不是直接设置 final_result - 修改 check_fast_path_success 函数返回 'llm_call' 而不是 'success' - 更新 main_graph_builder.py 的条件边配置,支持路由到 llm_call - 在快速路径节点中添加清除 state.final_result 的逻辑,避免复用旧结果 - 重构 RAG 工具初始化方式,使用模块级变量管理 - 修改 finalize.py 让它返回 final_result - 更新 agent_service.py 的 RAG 工具注入方式 - 简化 hybrid_router.py 的代码结构 - 清理 rag_nodes.py 的全局变量相关代码 - 更新相关测试文件
This commit is contained in:
@@ -48,9 +48,7 @@ class AIAgentService:
|
||||
if rag_tool:
|
||||
self.tools.append(rag_tool)
|
||||
self.tools_by_name[rag_tool.name] = rag_tool
|
||||
# 关键:设置全局 RAG 工具,供 rag_nodes.py 使用
|
||||
from ..main_graph.nodes.rag_nodes import set_global_rag_tool
|
||||
set_global_rag_tool(rag_tool)
|
||||
self.rag_tool = rag_tool # 保存到实例变量,供 config 注入
|
||||
|
||||
# 2. 构建各模型的 Graph(使用新版 React 模式)
|
||||
for name, llm in chat_services.items():
|
||||
@@ -82,7 +80,10 @@ class AIAgentService:
|
||||
|
||||
graph = self.graphs[model]
|
||||
config = {
|
||||
"configurable": {"thread_id": thread_id},
|
||||
"configurable": {
|
||||
"thread_id": thread_id,
|
||||
"rag_tool": getattr(self, "rag_tool", None), # 注入 RAG 工具
|
||||
},
|
||||
"metadata": {"user_id": user_id}
|
||||
}
|
||||
# 新版状态输入:传入完整的 MainGraphState,关键是 user_query
|
||||
@@ -136,7 +137,10 @@ class AIAgentService:
|
||||
raise ValueError(f"模型 '{model_name}' 未找到或未初始化")
|
||||
|
||||
config = {
|
||||
"configurable": {"thread_id": thread_id},
|
||||
"configurable": {
|
||||
"thread_id": thread_id,
|
||||
"rag_tool": getattr(self, "rag_tool", None), # 注入 RAG 工具
|
||||
},
|
||||
"metadata": {"user_id": user_id}
|
||||
}
|
||||
input_state = {
|
||||
@@ -250,9 +254,11 @@ class AIAgentService:
|
||||
|
||||
elif chunk_type == "updates":
|
||||
updates_data = chunk["data"]
|
||||
info(f"[Stream] updates 数据: {list(updates_data.keys()) if isinstance(updates_data, dict) else type(updates_data)}")
|
||||
# 特别检查 final_result
|
||||
if isinstance(updates_data, dict) and "final_result" in updates_data:
|
||||
info(f"[Stream] 收到 final_result: {str(updates_data['final_result'])[:100]}...")
|
||||
serialized_data = self._serialize_value(updates_data)
|
||||
|
||||
# 检查是否有人工审核请求
|
||||
if "review_pending" in serialized_data and serialized_data["review_pending"]:
|
||||
review_id = serialized_data.get("review_id", "")
|
||||
content_to_review = serialized_data.get("content_to_review", "")
|
||||
|
||||
Reference in New Issue
Block a user