修复三个问题:1. 子图执行后的无限循环 2. llm_call没有输出 3. 思考打印两次

- 子图执行后直接进入finalize,避免回到react_reason循环
- llm_call节点检查是否已有final_result,避免重复调用LLM
- 直接在react_reason_node中通过adispatch_custom_event发送推理事件,避免通过state传递导致重复
This commit is contained in:
2026-05-02 09:00:34 +08:00
parent bd2c20d927
commit 2893accbc4
5 changed files with 139 additions and 86 deletions

View File

@@ -107,8 +107,27 @@ class ReactIntentReasoner:
"""
context = context or {}
result = ReasoningResult(original_query=query)
# 关键修复 1检查是否已经有检索结果或子图结果如果是直接回答
previous_actions = context.get("previous_actions", [])
if "subgraph_completed" in previous_actions:
result.action = ReasoningAction.DIRECT_RESPONSE
result.confidence = 1.0
result.reasoning = "子图已执行完成,直接回答"
return result
retrieved_docs = context.get("retrieved_docs", [])
messages = context.get("messages", [])
# 关键修复 2如果已经有 rag_context 或 web_search_results通过 messages 推断),直接回答
# 检查是否已经执行过 rag_retrieve 或 web_search
if "rag_retrieve" in previous_actions or "web_search" in previous_actions:
result.action = ReasoningAction.DIRECT_RESPONSE
result.confidence = 0.95
result.reasoning = "已获取信息,直接回答"
return result
# 策略1: 尝试使用 LLM 推理
# 策略1尝试使用 LLM 推理
try:
llm_result = await self._reason_with_llm(query, context)
if llm_result.confidence >= 0.6: # 置信度足够高,直接返回
@@ -116,7 +135,7 @@ class ReactIntentReasoner:
except Exception as e:
print(f"[ReactReasoner] LLM 推理失败: {e}, 回退到规则")
# 策略2: LLM 失败或置信度低,使用规则匹配
# 策略2LLM 失败或置信度低,使用规则匹配
return self._reason_with_rules(query, context)
async def _reason_with_llm(