添加详细日志: 在关键节点加日志以便定位卡住问题
All checks were successful
构建并部署 AI Agent 服务 / deploy (push) Successful in 6m26s

This commit is contained in:
2026-05-06 16:02:53 +08:00
parent e70a2919dd
commit 13499ecf2a
3 changed files with 62 additions and 12 deletions

View File

@@ -45,7 +45,7 @@ def _get_rag_tool() -> Optional[callable]:
# ========== RAG 检索核心逻辑 ==========
async def _rag_retrieve_core(state: MainGraphState, pipeline) -> MainGraphState:
"""执行 RAG 检索的核心逻辑"""
info(f"[RAG Core] _rag_retrieve_core 开始")
retrieval_query = state.user_query
# 优先使用推理结果中的优化查询 - 从新的结构化字段获取
@@ -55,9 +55,14 @@ async def _rag_retrieve_core(state: MainGraphState, pipeline) -> MainGraphState:
if cfg and cfg.retrieval_query:
retrieval_query = cfg.retrieval_query
info(f"[RAG Core] 使用检索查询: {retrieval_query[:50]}...")
# 直接调用 pipeline 获取文档和上下文
info(f"[RAG Core] 调用 pipeline.aretrieve")
documents = await pipeline.aretrieve(retrieval_query)
info(f"[RAG Core] pipeline.aretrieve 返回,得到 {len(documents)} 个文档")
info(f"[RAG Core] 调用 pipeline.format_context")
rag_context = pipeline.format_context(documents)
info(f"[RAG Core] pipeline.format_context 返回")
info(f"[RAG Core] 获取到 rag_context: {type(rag_context)}, 长度={len(rag_context) if rag_context else 0}")
info(f"[RAG Core] 获取到 rag_docs: {len(documents)} 个文档")
@@ -69,15 +74,17 @@ async def _rag_retrieve_core(state: MainGraphState, pipeline) -> MainGraphState:
state.rag_attempts = getattr(state, 'rag_attempts', 0) + 1
# 移除对 debug_info 的依赖,不再保存 rag_scores
info(f"[RAG Core] _rag_retrieve_core 结束")
return state
# ========== RAG 检索节点 ==========
async def rag_retrieve_node(state: MainGraphState, config: Optional[RunnableConfig] = None) -> MainGraphState:
"""RAG 检索节点:检索 + 置信度评估"""
info(f"[RAG] rag_retrieve_node 开始")
state.current_phase = "rag_retrieving"
start_time = time.time()
info(f"[RAG] 调用 _get_rag_pipeline")
pipeline = _get_rag_pipeline()
await dispatch_custom_event(
@@ -87,9 +94,12 @@ async def rag_retrieve_node(state: MainGraphState, config: Optional[RunnableConf
)
try:
info(f"[RAG] 调用 _rag_retrieve_core")
state = await _rag_retrieve_core(state, pipeline)
info(f"[RAG] _rag_retrieve_core 返回")
# 评估置信度
info(f"[RAG] 调用 _evaluate_rag_confidence")
confidence = await _evaluate_rag_confidence(state)
state.rag_confidence = confidence
@@ -111,10 +121,11 @@ async def rag_retrieve_node(state: MainGraphState, config: Optional[RunnableConf
)
except Exception as e:
info(f"[RAG] 检索失败: {e}")
info(f"[RAG] 检索失败: {e}", exc_info=True)
state.rag_confidence = 0.0
state.rag_retrieved = False
info(f"[RAG] rag_retrieve_node 结束")
return state