sanatan_ai / modules /nodes /conditions.py
vikramvasudevan's picture
Upload folder using huggingface_hub
c22c05a verified
raw
history blame contribute delete
766 Bytes
from modules.nodes.state import ChatState
def _check_debug_condition(state: ChatState) -> str:
if state["debug_mode"]:
return "validator"
else:
return "__end__"
MAX_TOOL_CALLS = 10
def branching_condition(state: ChatState) -> str:
# hard stop after MAX_TOOL_CALLS
if state.get("tool_calls", 0) >= MAX_TOOL_CALLS:
return _check_debug_condition(state)
last_msg = state["messages"][-1]
if hasattr(last_msg, "tool_calls") and last_msg.tool_calls:
if state.get("skip_tool", False):
# remove tool_calls from the last assistant message
last_msg.tool_calls = []
return _check_debug_condition(state)
return "tools"
else:
return _check_debug_condition(state)