优化:统一意图分类逻辑,复用 intent.py,删除冗余的 intent_classifier.py
All checks were successful
构建并部署 AI Agent 服务 / deploy (push) Successful in 5m44s

This commit is contained in:
2026-05-06 18:41:14 +08:00
parent 1dc1ecad62
commit 000af774a3
3 changed files with 64 additions and 143 deletions

View File

@@ -16,7 +16,6 @@ from ..main_graph.main_graph_builder import build_react_main_graph
from ..main_graph.tools.graph_tools import AVAILABLE_TOOLS, TOOLS_BY_NAME
from ..main_graph.config import set_stream_writer
from ..main_graph.utils.rag_initializer import init_rag_tool
from backend.app.core.intent_classifier import get_intent_classifier
from backend.app.logger import debug, info, warning, error
from ..main_graph.state import MainGraphState, CurrentAction
@@ -66,8 +65,6 @@ class AIAgentService:
self.chat_services = None # 缓存的模型字典
self.tools = AVAILABLE_TOOLS.copy()
self.tools_by_name = TOOLS_BY_NAME.copy()
# 添加:意图分类器
self.intent_classifier = get_intent_classifier()
# RAG 管道(可选,需要时设置)
self.rag_pipeline = None
# Mem0 客户端
@@ -350,31 +347,6 @@ class AIAgentService:
# 构建调用参数
config, input_state = self._build_invocation(message, thread_id, resolved_model, user_id)
# ========== 意图识别(保留用于日志和后续路由)==========
intent_result = await self.intent_classifier.classify(message)
info(f"🧠 意图识别: {intent_result.intent_type} (置信度: {intent_result.confidence:.2f})")
info(f"📝 推理: {intent_result.reasoning}")
# 注入意图到状态(让 hybrid_router 可以利用)
input_state["intent_type"] = intent_result.intent_type.value
input_state["intent_confidence"] = intent_result.confidence
# 发送意图分类事件
yield {
"type": "intent_classified",
"intent": intent_result.intent_type.value,
"confidence": intent_result.confidence,
"reasoning": intent_result.reasoning
}
# 发送路径决策事件(目前硬编码,但状态中有意图信息供后续使用)
yield {
"type": "path_decision",
"path": "react_loop",
"intent": intent_result.intent_type.value
}
# =============================================
# ========== React 循环路径 ==========
info(f"🚀 开始执行单图,指定模型: {resolved_model}")
current_node = None