diff --git a/08_langgraph_basics/03_conditional_router.py b/08_langgraph_basics/03_conditional_router.py index a835e31..46aef7d 100644 --- a/08_langgraph_basics/03_conditional_router.py +++ b/08_langgraph_basics/03_conditional_router.py @@ -41,7 +41,7 @@ tool_node = ToolNode(tools) # 工具节点函数,langgraph已封装 # ReAct Step4:Loop Controller(是否循环) def should_continue(state:MessagesState): last_msg = state["messages"][-1] - if hasattr(last_msg,"tool_calls") and len(last_msg.tool_calls) > 0: + if hasattr(last_msg,"tool_calls") and last_msg.tool_calls: return "tools" # 有工具调用 -> 执行工具 return END # 无工具调用 -> 返回答案 diff --git a/08_langgraph_basics/04_agent_with_memory.py b/08_langgraph_basics/04_agent_with_memory.py index 101e09f..542f902 100644 --- a/08_langgraph_basics/04_agent_with_memory.py +++ b/08_langgraph_basics/04_agent_with_memory.py @@ -49,7 +49,7 @@ tool_node = ToolNode(tools) # ReAct Step4:Loop Controller(是否循环) def should_continue(state:MessagesState): last_msg = state["messages"][-1] - if hasattr(last_msg,"tool_calls") and len(last_msg.tool_calls) > 0: + if hasattr(last_msg,"tool_calls") and last_msg.tool_calls: return "tools" # 有工具调用 -> 执行工具 return END # 无工具调用 -> 返回答案