refactor: 重构快速路径流程,统一通过 llm_call 输出
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:
2026-05-05 04:32:42 +08:00
parent b64dade9e9
commit 128aad0c22
13 changed files with 533 additions and 716 deletions

View File

@@ -22,31 +22,39 @@ async def finalize_node(state: MainGraphState, config: RunnableConfig) -> Dict[s
config: 运行时配置
Returns:
空字典(完成节点,无状态更新
更新后的状态(包含 final_result
"""
log_state_change("finalize", state, "进入")
# 确保 final_result 被传递出去
result = {
"final_result": state.final_result,
"success": state.success,
"current_phase": "done"
}
try:
# 获取流式写入器并发送完成事件
from app.main_graph.config import get_stream_writer
writer = get_stream_writer()
# 只在 writer 存在且不是 noop 时才发送
if writer and hasattr(writer, '__call__'):
try:
writer({
"type": "custom",
"type": "custom",
"data": {
"type": "done",
"token_usage": state.last_token_usage,
"elapsed_time": state.last_elapsed_time
"elapsed_time": state.last_elapsed_time,
"final_result": state.final_result
}
})
info("🏁 [完成事件] 已发送完成事件包含token使用情况和耗时信息")
info("🏁 [完成事件] 已发送完成事件")
except Exception as e:
warning(f"⚠️ [完成事件] 发送完成事件失败 (非致命): {e}")
except Exception as e:
warning(f"⚠️ [完成事件] 处理失败 (非致命): {e}")
log_state_change("finalize", state, "离开")
return {}
return result