This commit is contained in:
@@ -364,20 +364,27 @@ def route_by_reasoning(state: MainGraphState) -> str:
|
||||
if "subgraph_completed" in previous_actions or state.final_result:
|
||||
return "llm_call"
|
||||
|
||||
# 检查是否刚刚执行完 rag 或 web search,应该继续推理一次然后去 llm_call
|
||||
# 但为了避免死循环,我们设置一个简单的规则
|
||||
if len(previous_actions) > 3:
|
||||
# 关键修复:如果已经执行过 rag_retrieve 并且又执行过推理,直接去 LLM_CALL
|
||||
# 这样的流程:推理1 → RAG → 推理2(判断 RAG 结果) → LLM_CALL
|
||||
rag_count = previous_actions.count("rag_retrieve")
|
||||
if rag_count >= 1 and len(previous_actions) >= rag_count + 1:
|
||||
info(f"[route_by_reasoning] 已完成 RAG 检索和结果判断,直接去 llm_call")
|
||||
return "llm_call"
|
||||
|
||||
|
||||
# 关键修复:限制最多 3 次推理,避免无限循环
|
||||
if len(previous_actions) >= 3:
|
||||
info(f"[route_by_reasoning] 已达到最大推理次数 ({len(previous_actions)}),直接去 llm_call")
|
||||
return "llm_call"
|
||||
|
||||
# 获取推理结果
|
||||
reasoning_result: Optional[ReasoningResult] = state.debug_info.get("reasoning_result")
|
||||
|
||||
|
||||
if not reasoning_result:
|
||||
return "llm_call"
|
||||
|
||||
|
||||
# 使用 intent.py 提供的路由函数
|
||||
route = get_route_by_reasoning(reasoning_result)
|
||||
|
||||
|
||||
# 映射到我们的节点名称
|
||||
# 注意:这些名称必须与 main_graph_builder.py 中定义的节点名称一致
|
||||
route_mapping = {
|
||||
@@ -391,7 +398,8 @@ def route_by_reasoning(state: MainGraphState) -> str:
|
||||
"dictionary": "dictionary_subgraph",
|
||||
"news_analysis": "news_analysis_subgraph",
|
||||
}
|
||||
|
||||
|
||||
info(f"[route_by_reasoning] 推理结果={reasoning_result.action.name}, 路由={route_mapping.get(route, 'llm_call')}, 历史动作={previous_actions}")
|
||||
return route_mapping.get(route, "llm_call")
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user