refactor: 整理文件夹结构,修复 create_serde 导入问题
Some checks failed
构建并部署 AI Agent 服务 / deploy (push) Failing after 6m50s
Some checks failed
构建并部署 AI Agent 服务 / deploy (push) Failing after 6m50s
- 移动 main_graph/tools/ 到 deprecated/main_graph_tools/(旧架构工具) - 移动 rag_initializer.py 和 retry_utils.py 到 core/ - 清理 main_graph/nodes/ 里的旧节点到 deprecated/ - 修复 backend.py 中 create_serde 导入问题
This commit is contained in:
59
backend/app/deprecated/finalize_new.py
Normal file
59
backend/app/deprecated/finalize_new.py
Normal file
@@ -0,0 +1,59 @@
|
||||
"""
|
||||
完成事件节点模块(新架构版本)
|
||||
负责发送完成事件
|
||||
"""
|
||||
|
||||
from typing import Any, Dict
|
||||
from datetime import datetime
|
||||
|
||||
# 本地模块
|
||||
from .state import AgentState
|
||||
from backend.app.logger import info, warning
|
||||
|
||||
from langchain_core.runnables.config import RunnableConfig
|
||||
|
||||
|
||||
async def finalize_node(state: AgentState, config: RunnableConfig) -> Dict[str, Any]:
|
||||
"""
|
||||
完成事件节点(新架构版本)
|
||||
|
||||
Args:
|
||||
state: 当前对话状态
|
||||
config: 运行时配置
|
||||
|
||||
Returns:
|
||||
空(不修改状态)
|
||||
"""
|
||||
info("[Finalize] 进入完成节点")
|
||||
|
||||
try:
|
||||
# 获取流式写入器并发送完成事件
|
||||
from backend.app.main_graph.config import get_stream_writer
|
||||
writer = get_stream_writer()
|
||||
|
||||
# 提取最后的回复
|
||||
final_reply = ""
|
||||
if state.messages:
|
||||
last_msg = state.messages[-1]
|
||||
final_reply = last_msg.content if hasattr(last_msg, 'content') else str(last_msg)
|
||||
|
||||
# 只在 writer 存在且不是 noop 时才发送
|
||||
if writer and hasattr(writer, '__call__'):
|
||||
try:
|
||||
writer({
|
||||
"type": "custom",
|
||||
"data": {
|
||||
"type": "done",
|
||||
"token_usage": state.last_token_usage,
|
||||
"elapsed_time": state.last_elapsed_time,
|
||||
"final_result": final_reply
|
||||
}
|
||||
})
|
||||
info("🏁 [完成事件] 已发送完成事件")
|
||||
except Exception as e:
|
||||
warning(f"⚠️ [完成事件] 发送完成事件失败 (非致命): {e}")
|
||||
except Exception as e:
|
||||
warning(f"⚠️ [完成事件] 处理失败 (非致命): {e}")
|
||||
|
||||
info("[Finalize] 离开完成节点")
|
||||
return {}
|
||||
Reference in New Issue
Block a user