修复三个问题: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:
@@ -37,11 +37,11 @@ def create_llm_call_node(llm, tools: list):
|
||||
async def call_llm(state: MainGraphState, config: RunnableConfig) -> Dict[str, Any]:
|
||||
"""
|
||||
LLM 调用节点(异步方法)
|
||||
|
||||
|
||||
Args:
|
||||
state: 当前对话状态
|
||||
config: LangChain/LangGraph 自动注入的配置,包含 callbacks 等信息
|
||||
|
||||
|
||||
Returns:
|
||||
更新后的状态字典
|
||||
"""
|
||||
@@ -49,6 +49,19 @@ def create_llm_call_node(llm, tools: list):
|
||||
|
||||
memory_context = getattr(state, "memory_context", "暂无用户信息")
|
||||
start_time = time.time()
|
||||
|
||||
# 关键修复:如果 state.final_result 已经存在(比如子图执行完),直接返回
|
||||
if state.final_result:
|
||||
info(f"[llm_call] 检测到已有最终结果,直接返回: {state.final_result[:100]}...")
|
||||
elapsed_time = time.time() - start_time
|
||||
return {
|
||||
"final_result": state.final_result,
|
||||
"success": True,
|
||||
"current_phase": "done",
|
||||
"llm_calls": getattr(state, 'llm_calls', 0) + 1,
|
||||
"last_elapsed_time": elapsed_time,
|
||||
"turns_since_last_summary": getattr(state, 'turns_since_last_summary', 0) + 1,
|
||||
}
|
||||
|
||||
try:
|
||||
# 添加 RAG 上下文到消息
|
||||
|
||||
Reference in New Issue
Block a user