refactor:use truthy check instead of len() for tool_calls

This commit is contained in:
Annyfee
2025-11-23 16:27:30 +08:00
parent 26529362fb
commit 1029260dcc
2 changed files with 2 additions and 2 deletions
+1 -1
View File
@@ -41,7 +41,7 @@ tool_node = ToolNode(tools) # 工具节点函数,langgraph已封装
# ReAct Step4:Loop Controller(是否循环) # ReAct Step4:Loop Controller(是否循环)
def should_continue(state:MessagesState): def should_continue(state:MessagesState):
last_msg = state["messages"][-1] 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 "tools" # 有工具调用 -> 执行工具
return END # 无工具调用 -> 返回答案 return END # 无工具调用 -> 返回答案
+1 -1
View File
@@ -49,7 +49,7 @@ tool_node = ToolNode(tools)
# ReAct Step4:Loop Controller(是否循环) # ReAct Step4:Loop Controller(是否循环)
def should_continue(state:MessagesState): def should_continue(state:MessagesState):
last_msg = state["messages"][-1] 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 "tools" # 有工具调用 -> 执行工具
return END # 无工具调用 -> 返回答案 return END # 无工具调用 -> 返回答案