citu_agent.py 27 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612
  1. # agent/citu_agent.py
  2. from typing import Dict, Any, Literal
  3. from langgraph.graph import StateGraph, END
  4. from langchain.agents import AgentExecutor, create_openai_tools_agent
  5. from langchain.prompts import ChatPromptTemplate, MessagesPlaceholder
  6. from langchain_core.messages import SystemMessage, HumanMessage
  7. from agent.state import AgentState
  8. from agent.classifier import QuestionClassifier
  9. from agent.tools import TOOLS, generate_sql, execute_sql, generate_summary, general_chat
  10. from agent.utils import get_compatible_llm
  11. from app_config import ENABLE_RESULT_SUMMARY
  12. class CituLangGraphAgent:
  13. """Citu LangGraph智能助手主类 - 使用@tool装饰器 + Agent工具调用"""
  14. def __init__(self):
  15. # 加载配置
  16. try:
  17. from agent.config import get_current_config, get_nested_config
  18. self.config = get_current_config()
  19. print("[CITU_AGENT] 加载Agent配置完成")
  20. except ImportError:
  21. self.config = {}
  22. print("[CITU_AGENT] 配置文件不可用,使用默认配置")
  23. self.classifier = QuestionClassifier()
  24. self.tools = TOOLS
  25. self.llm = get_compatible_llm()
  26. # 注意:现在使用直接工具调用模式,不再需要预创建Agent执行器
  27. print("[CITU_AGENT] 使用直接工具调用模式")
  28. self.workflow = self._create_workflow()
  29. print("[CITU_AGENT] LangGraph Agent with Direct Tools初始化完成")
  30. def _create_workflow(self) -> StateGraph:
  31. """根据路由模式创建不同的工作流"""
  32. try:
  33. from app_config import QUESTION_ROUTING_MODE
  34. print(f"[CITU_AGENT] 创建工作流,路由模式: {QUESTION_ROUTING_MODE}")
  35. except ImportError:
  36. QUESTION_ROUTING_MODE = "hybrid"
  37. print(f"[CITU_AGENT] 配置导入失败,使用默认路由模式: {QUESTION_ROUTING_MODE}")
  38. workflow = StateGraph(AgentState)
  39. # 根据路由模式创建不同的工作流
  40. if QUESTION_ROUTING_MODE == "database_direct":
  41. # 直接数据库模式:跳过分类,直接进入数据库处理
  42. workflow.add_node("init_direct_database", self._init_direct_database_node)
  43. workflow.add_node("agent_database", self._agent_database_node)
  44. workflow.add_node("format_response", self._format_response_node)
  45. workflow.set_entry_point("init_direct_database")
  46. workflow.add_edge("init_direct_database", "agent_database")
  47. workflow.add_edge("agent_database", "format_response")
  48. workflow.add_edge("format_response", END)
  49. elif QUESTION_ROUTING_MODE == "chat_direct":
  50. # 直接聊天模式:跳过分类,直接进入聊天处理
  51. workflow.add_node("init_direct_chat", self._init_direct_chat_node)
  52. workflow.add_node("agent_chat", self._agent_chat_node)
  53. workflow.add_node("format_response", self._format_response_node)
  54. workflow.set_entry_point("init_direct_chat")
  55. workflow.add_edge("init_direct_chat", "agent_chat")
  56. workflow.add_edge("agent_chat", "format_response")
  57. workflow.add_edge("format_response", END)
  58. else:
  59. # 其他模式(hybrid, llm_only):使用原有的分类工作流
  60. workflow.add_node("classify_question", self._classify_question_node)
  61. workflow.add_node("agent_chat", self._agent_chat_node)
  62. workflow.add_node("agent_database", self._agent_database_node)
  63. workflow.add_node("format_response", self._format_response_node)
  64. workflow.set_entry_point("classify_question")
  65. # 添加条件边:分类后的路由
  66. workflow.add_conditional_edges(
  67. "classify_question",
  68. self._route_after_classification,
  69. {
  70. "DATABASE": "agent_database",
  71. "CHAT": "agent_chat"
  72. }
  73. )
  74. workflow.add_edge("agent_chat", "format_response")
  75. workflow.add_edge("agent_database", "format_response")
  76. workflow.add_edge("format_response", END)
  77. return workflow.compile()
  78. def _init_direct_database_node(self, state: AgentState) -> AgentState:
  79. """初始化直接数据库模式的状态"""
  80. try:
  81. from app_config import QUESTION_ROUTING_MODE
  82. # 设置直接数据库模式的分类状态
  83. state["question_type"] = "DATABASE"
  84. state["classification_confidence"] = 1.0
  85. state["classification_reason"] = "配置为直接数据库查询模式"
  86. state["classification_method"] = "direct_database"
  87. state["routing_mode"] = QUESTION_ROUTING_MODE
  88. state["current_step"] = "direct_database_init"
  89. state["execution_path"].append("init_direct_database")
  90. print(f"[DIRECT_DATABASE] 直接数据库模式初始化完成")
  91. return state
  92. except Exception as e:
  93. print(f"[ERROR] 直接数据库模式初始化异常: {str(e)}")
  94. state["error"] = f"直接数据库模式初始化失败: {str(e)}"
  95. state["error_code"] = 500
  96. state["execution_path"].append("init_direct_database_error")
  97. return state
  98. def _init_direct_chat_node(self, state: AgentState) -> AgentState:
  99. """初始化直接聊天模式的状态"""
  100. try:
  101. from app_config import QUESTION_ROUTING_MODE
  102. # 设置直接聊天模式的分类状态
  103. state["question_type"] = "CHAT"
  104. state["classification_confidence"] = 1.0
  105. state["classification_reason"] = "配置为直接聊天模式"
  106. state["classification_method"] = "direct_chat"
  107. state["routing_mode"] = QUESTION_ROUTING_MODE
  108. state["current_step"] = "direct_chat_init"
  109. state["execution_path"].append("init_direct_chat")
  110. print(f"[DIRECT_CHAT] 直接聊天模式初始化完成")
  111. return state
  112. except Exception as e:
  113. print(f"[ERROR] 直接聊天模式初始化异常: {str(e)}")
  114. state["error"] = f"直接聊天模式初始化失败: {str(e)}"
  115. state["error_code"] = 500
  116. state["execution_path"].append("init_direct_chat_error")
  117. return state
  118. def _classify_question_node(self, state: AgentState) -> AgentState:
  119. """问题分类节点 - 支持路由模式"""
  120. try:
  121. from app_config import QUESTION_ROUTING_MODE
  122. print(f"[CLASSIFY_NODE] 开始分类问题: {state['question']}")
  123. classification_result = self.classifier.classify(state["question"])
  124. # 更新状态
  125. state["question_type"] = classification_result.question_type
  126. state["classification_confidence"] = classification_result.confidence
  127. state["classification_reason"] = classification_result.reason
  128. state["classification_method"] = classification_result.method
  129. state["routing_mode"] = QUESTION_ROUTING_MODE
  130. state["current_step"] = "classified"
  131. state["execution_path"].append("classify")
  132. print(f"[CLASSIFY_NODE] 分类结果: {classification_result.question_type}, 置信度: {classification_result.confidence}")
  133. print(f"[CLASSIFY_NODE] 路由模式: {QUESTION_ROUTING_MODE}, 分类方法: {classification_result.method}")
  134. return state
  135. except Exception as e:
  136. print(f"[ERROR] 问题分类异常: {str(e)}")
  137. state["error"] = f"问题分类失败: {str(e)}"
  138. state["error_code"] = 500
  139. state["execution_path"].append("classify_error")
  140. return state
  141. def _agent_database_node(self, state: AgentState) -> AgentState:
  142. """数据库Agent节点 - 直接工具调用模式"""
  143. try:
  144. print(f"[DATABASE_AGENT] 开始处理数据库查询: {state['question']}")
  145. question = state["question"]
  146. # 步骤1:生成SQL
  147. print(f"[DATABASE_AGENT] 步骤1:生成SQL")
  148. sql_result = generate_sql.invoke({"question": question, "allow_llm_to_see_data": True})
  149. if not sql_result.get("success"):
  150. print(f"[DATABASE_AGENT] SQL生成失败: {sql_result.get('error')}")
  151. state["error"] = sql_result.get("error", "SQL生成失败")
  152. state["error_code"] = 500
  153. state["current_step"] = "database_error"
  154. state["execution_path"].append("agent_database_error")
  155. return state
  156. sql = sql_result.get("sql")
  157. state["sql"] = sql
  158. print(f"[DATABASE_AGENT] SQL生成成功: {sql}")
  159. # 步骤1.5:检查是否为解释性响应而非SQL
  160. error_type = sql_result.get("error_type")
  161. if error_type == "llm_explanation":
  162. # LLM返回了解释性文本,直接作为最终答案
  163. explanation = sql_result.get("error", "")
  164. state["chat_response"] = explanation + " 请尝试提问其它问题。"
  165. state["current_step"] = "database_completed"
  166. state["execution_path"].append("agent_database")
  167. print(f"[DATABASE_AGENT] 返回LLM解释性答案: {explanation}")
  168. return state
  169. # 额外验证:检查SQL格式(防止工具误判)
  170. from agent.utils import _is_valid_sql_format
  171. if not _is_valid_sql_format(sql):
  172. # 内容看起来不是SQL,当作解释性响应处理
  173. state["chat_response"] = sql + " 请尝试提问其它问题。"
  174. state["current_step"] = "database_completed"
  175. state["execution_path"].append("agent_database")
  176. print(f"[DATABASE_AGENT] 内容不是有效SQL,当作解释返回: {sql}")
  177. return state
  178. # 步骤2:执行SQL
  179. print(f"[DATABASE_AGENT] 步骤2:执行SQL")
  180. execute_result = execute_sql.invoke({"sql": sql})
  181. if not execute_result.get("success"):
  182. print(f"[DATABASE_AGENT] SQL执行失败: {execute_result.get('error')}")
  183. state["error"] = execute_result.get("error", "SQL执行失败")
  184. state["error_code"] = 500
  185. state["current_step"] = "database_error"
  186. state["execution_path"].append("agent_database_error")
  187. return state
  188. query_result = execute_result.get("data_result")
  189. state["query_result"] = query_result
  190. print(f"[DATABASE_AGENT] SQL执行成功,返回 {query_result.get('row_count', 0)} 行数据")
  191. # 步骤3:生成摘要(可通过配置控制,仅在有数据时生成)
  192. if ENABLE_RESULT_SUMMARY and query_result.get('row_count', 0) > 0:
  193. print(f"[DATABASE_AGENT] 步骤3:生成摘要")
  194. # 重要:提取原始问题用于摘要生成,避免历史记录循环嵌套
  195. original_question = self._extract_original_question(question)
  196. print(f"[DATABASE_AGENT] 原始问题: {original_question}")
  197. summary_result = generate_summary.invoke({
  198. "question": original_question, # 使用原始问题而不是enhanced_question
  199. "query_result": query_result,
  200. "sql": sql
  201. })
  202. if not summary_result.get("success"):
  203. print(f"[DATABASE_AGENT] 摘要生成失败: {summary_result.get('message')}")
  204. # 摘要生成失败不是致命错误,使用默认摘要
  205. state["summary"] = f"查询执行完成,共返回 {query_result.get('row_count', 0)} 条记录。"
  206. else:
  207. state["summary"] = summary_result.get("summary")
  208. print(f"[DATABASE_AGENT] 摘要生成成功")
  209. else:
  210. print(f"[DATABASE_AGENT] 跳过摘要生成(ENABLE_RESULT_SUMMARY={ENABLE_RESULT_SUMMARY},数据行数={query_result.get('row_count', 0)})")
  211. # 不生成摘要时,不设置summary字段,让格式化响应节点决定如何处理
  212. state["current_step"] = "database_completed"
  213. state["execution_path"].append("agent_database")
  214. print(f"[DATABASE_AGENT] 数据库查询完成")
  215. return state
  216. except Exception as e:
  217. print(f"[ERROR] 数据库Agent异常: {str(e)}")
  218. import traceback
  219. print(f"[ERROR] 详细错误信息: {traceback.format_exc()}")
  220. state["error"] = f"数据库查询失败: {str(e)}"
  221. state["error_code"] = 500
  222. state["current_step"] = "database_error"
  223. state["execution_path"].append("agent_database_error")
  224. return state
  225. def _agent_chat_node(self, state: AgentState) -> AgentState:
  226. """聊天Agent节点 - 直接工具调用模式"""
  227. try:
  228. print(f"[CHAT_AGENT] 开始处理聊天: {state['question']}")
  229. question = state["question"]
  230. # 构建上下文 - 仅使用真实的对话历史上下文
  231. # 注意:不要将分类原因传递给LLM,那是系统内部的路由信息
  232. enable_context_injection = self.config.get("chat_agent", {}).get("enable_context_injection", True)
  233. context = None
  234. if enable_context_injection:
  235. # TODO: 在这里可以添加真实的对话历史上下文
  236. # 例如从Redis或其他存储中获取最近的对话记录
  237. # context = get_conversation_history(state.get("session_id"))
  238. pass
  239. # 直接调用general_chat工具
  240. print(f"[CHAT_AGENT] 调用general_chat工具")
  241. chat_result = general_chat.invoke({
  242. "question": question,
  243. "context": context
  244. })
  245. if chat_result.get("success"):
  246. state["chat_response"] = chat_result.get("response", "")
  247. print(f"[CHAT_AGENT] 聊天处理成功")
  248. else:
  249. # 处理失败,使用备用响应
  250. state["chat_response"] = chat_result.get("response", "抱歉,我暂时无法处理您的问题。请稍后再试。")
  251. print(f"[CHAT_AGENT] 聊天处理失败,使用备用响应: {chat_result.get('error')}")
  252. state["current_step"] = "chat_completed"
  253. state["execution_path"].append("agent_chat")
  254. print(f"[CHAT_AGENT] 聊天处理完成")
  255. return state
  256. except Exception as e:
  257. print(f"[ERROR] 聊天Agent异常: {str(e)}")
  258. import traceback
  259. print(f"[ERROR] 详细错误信息: {traceback.format_exc()}")
  260. state["chat_response"] = "抱歉,我暂时无法处理您的问题。请稍后再试,或者尝试询问数据相关的问题。"
  261. state["current_step"] = "chat_error"
  262. state["execution_path"].append("agent_chat_error")
  263. return state
  264. def _format_response_node(self, state: AgentState) -> AgentState:
  265. """格式化最终响应节点"""
  266. try:
  267. print(f"[FORMAT_NODE] 开始格式化响应,问题类型: {state['question_type']}")
  268. state["current_step"] = "completed"
  269. state["execution_path"].append("format_response")
  270. # 根据问题类型和执行状态格式化响应
  271. if state.get("error"):
  272. # 有错误的情况
  273. state["final_response"] = {
  274. "success": False,
  275. "error": state["error"],
  276. "error_code": state.get("error_code", 500),
  277. "question_type": state["question_type"],
  278. "execution_path": state["execution_path"],
  279. "classification_info": {
  280. "confidence": state.get("classification_confidence", 0),
  281. "reason": state.get("classification_reason", ""),
  282. "method": state.get("classification_method", "")
  283. }
  284. }
  285. elif state["question_type"] == "DATABASE":
  286. # 数据库查询类型
  287. if state.get("chat_response"):
  288. # SQL生成失败的解释性响应(不受ENABLE_RESULT_SUMMARY配置影响)
  289. state["final_response"] = {
  290. "success": True,
  291. "response": state["chat_response"],
  292. "type": "DATABASE",
  293. "sql": state.get("sql"),
  294. "query_result": state.get("query_result"), # 获取query_result字段
  295. "execution_path": state["execution_path"],
  296. "classification_info": {
  297. "confidence": state["classification_confidence"],
  298. "reason": state["classification_reason"],
  299. "method": state["classification_method"]
  300. }
  301. }
  302. elif state.get("summary"):
  303. # 正常的数据库查询结果,有摘要的情况
  304. # 不将summary复制到response,让response保持为空
  305. state["final_response"] = {
  306. "success": True,
  307. "type": "DATABASE",
  308. "sql": state.get("sql"),
  309. "query_result": state.get("query_result"), # 获取query_result字段
  310. "summary": state["summary"],
  311. "execution_path": state["execution_path"],
  312. "classification_info": {
  313. "confidence": state["classification_confidence"],
  314. "reason": state["classification_reason"],
  315. "method": state["classification_method"]
  316. }
  317. }
  318. elif state.get("query_result"):
  319. # 有数据但没有摘要(摘要被配置禁用)
  320. query_result = state.get("query_result")
  321. row_count = query_result.get("row_count", 0)
  322. # 构建基本响应,不包含summary字段和response字段
  323. # 用户应该直接从query_result.columns和query_result.rows获取数据
  324. state["final_response"] = {
  325. "success": True,
  326. "type": "DATABASE",
  327. "sql": state.get("sql"),
  328. "query_result": query_result, # 获取query_result字段
  329. "execution_path": state["execution_path"],
  330. "classification_info": {
  331. "confidence": state["classification_confidence"],
  332. "reason": state["classification_reason"],
  333. "method": state["classification_method"]
  334. }
  335. }
  336. else:
  337. # 数据库查询失败,没有任何结果
  338. state["final_response"] = {
  339. "success": False,
  340. "error": state.get("error", "数据库查询未完成"),
  341. "type": "DATABASE",
  342. "sql": state.get("sql"),
  343. "execution_path": state["execution_path"]
  344. }
  345. else:
  346. # 聊天类型
  347. state["final_response"] = {
  348. "success": True,
  349. "response": state.get("chat_response", ""),
  350. "type": "CHAT",
  351. "execution_path": state["execution_path"],
  352. "classification_info": {
  353. "confidence": state["classification_confidence"],
  354. "reason": state["classification_reason"],
  355. "method": state["classification_method"]
  356. }
  357. }
  358. print(f"[FORMAT_NODE] 响应格式化完成")
  359. return state
  360. except Exception as e:
  361. print(f"[ERROR] 响应格式化异常: {str(e)}")
  362. state["final_response"] = {
  363. "success": False,
  364. "error": f"响应格式化异常: {str(e)}",
  365. "error_code": 500,
  366. "execution_path": state["execution_path"]
  367. }
  368. return state
  369. def _route_after_classification(self, state: AgentState) -> Literal["DATABASE", "CHAT"]:
  370. """
  371. 分类后的路由决策
  372. 完全信任QuestionClassifier的决策:
  373. - DATABASE类型 → 数据库Agent
  374. - CHAT和UNCERTAIN类型 → 聊天Agent
  375. 这样避免了双重决策的冲突,所有分类逻辑都集中在QuestionClassifier中
  376. """
  377. question_type = state["question_type"]
  378. confidence = state["classification_confidence"]
  379. print(f"[ROUTE] 分类路由: {question_type}, 置信度: {confidence} (完全信任分类器决策)")
  380. if question_type == "DATABASE":
  381. return "DATABASE"
  382. else:
  383. # 将 "CHAT" 和 "UNCERTAIN" 类型都路由到聊天流程
  384. # 聊天Agent可以处理不确定的情况,并在必要时引导用户提供更多信息
  385. return "CHAT"
  386. def process_question(self, question: str, session_id: str = None) -> Dict[str, Any]:
  387. """
  388. 统一的问题处理入口
  389. Args:
  390. question: 用户问题
  391. session_id: 会话ID
  392. Returns:
  393. Dict包含完整的处理结果
  394. """
  395. try:
  396. print(f"[CITU_AGENT] 开始处理问题: {question}")
  397. # 初始化状态
  398. initial_state = self._create_initial_state(question, session_id)
  399. # 执行工作流
  400. final_state = self.workflow.invoke(
  401. initial_state,
  402. config={
  403. "configurable": {"session_id": session_id}
  404. } if session_id else None
  405. )
  406. # 提取最终结果
  407. result = final_state["final_response"]
  408. print(f"[CITU_AGENT] 问题处理完成: {result.get('success', False)}")
  409. return result
  410. except Exception as e:
  411. print(f"[ERROR] Agent执行异常: {str(e)}")
  412. return {
  413. "success": False,
  414. "error": f"Agent系统异常: {str(e)}",
  415. "error_code": 500,
  416. "execution_path": ["error"]
  417. }
  418. def _create_initial_state(self, question: str, session_id: str = None) -> AgentState:
  419. """创建初始状态 - 支持路由模式"""
  420. try:
  421. from app_config import QUESTION_ROUTING_MODE
  422. except ImportError:
  423. QUESTION_ROUTING_MODE = "hybrid"
  424. return AgentState(
  425. # 输入信息
  426. question=question,
  427. session_id=session_id,
  428. # 分类结果 (初始值,会在分类节点或直接模式初始化节点中更新)
  429. question_type="UNCERTAIN",
  430. classification_confidence=0.0,
  431. classification_reason="",
  432. classification_method="",
  433. # 数据库查询流程状态
  434. sql=None,
  435. sql_generation_attempts=0,
  436. query_result=None,
  437. summary=None,
  438. # 聊天响应
  439. chat_response=None,
  440. # 最终输出
  441. final_response={},
  442. # 错误处理
  443. error=None,
  444. error_code=None,
  445. # 流程控制
  446. current_step="initialized",
  447. execution_path=["start"],
  448. retry_count=0,
  449. max_retries=3,
  450. # 调试信息
  451. debug_info={},
  452. # 路由模式
  453. routing_mode=QUESTION_ROUTING_MODE
  454. )
  455. def _extract_original_question(self, question: str) -> str:
  456. """
  457. 从enhanced_question中提取原始问题
  458. Args:
  459. question: 可能包含上下文的问题
  460. Returns:
  461. str: 原始问题
  462. """
  463. try:
  464. # 检查是否为enhanced_question格式
  465. if "\n[CONTEXT]\n" in question and "\n[CURRENT]\n" in question:
  466. # 提取[CURRENT]标签后的内容
  467. current_start = question.find("\n[CURRENT]\n")
  468. if current_start != -1:
  469. original_question = question[current_start + len("\n[CURRENT]\n"):].strip()
  470. return original_question
  471. # 如果不是enhanced_question格式,直接返回原问题
  472. return question.strip()
  473. except Exception as e:
  474. print(f"[WARNING] 提取原始问题失败: {str(e)}")
  475. return question.strip()
  476. def health_check(self) -> Dict[str, Any]:
  477. """健康检查"""
  478. try:
  479. # 从配置获取健康检查参数
  480. from agent.config import get_nested_config
  481. test_question = get_nested_config(self.config, "health_check.test_question", "你好")
  482. enable_full_test = get_nested_config(self.config, "health_check.enable_full_test", True)
  483. if enable_full_test:
  484. # 完整流程测试
  485. test_result = self.process_question(test_question, "health_check")
  486. return {
  487. "status": "healthy" if test_result.get("success") else "degraded",
  488. "test_result": test_result.get("success", False),
  489. "workflow_compiled": self.workflow is not None,
  490. "tools_count": len(self.tools),
  491. "agent_reuse_enabled": False,
  492. "message": "Agent健康检查完成"
  493. }
  494. else:
  495. # 简单检查
  496. return {
  497. "status": "healthy",
  498. "test_result": True,
  499. "workflow_compiled": self.workflow is not None,
  500. "tools_count": len(self.tools),
  501. "agent_reuse_enabled": False,
  502. "message": "Agent简单健康检查完成"
  503. }
  504. except Exception as e:
  505. return {
  506. "status": "unhealthy",
  507. "error": str(e),
  508. "workflow_compiled": self.workflow is not None,
  509. "tools_count": len(self.tools) if hasattr(self, 'tools') else 0,
  510. "agent_reuse_enabled": False,
  511. "message": "Agent健康检查失败"
  512. }