File size: 766 Bytes
63d1774
 
 
 
 
 
 
 
c22c05a
63d1774
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
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)