forked from CopilotKit/CopilotKit
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathutil.py
More file actions
32 lines (25 loc) · 967 Bytes
/
Copy pathutil.py
File metadata and controls
32 lines (25 loc) · 967 Bytes
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
27
28
29
30
31
32
from langchain_core.messages import ToolCall
def should_route_to_tool_node(tool_calls: list[ToolCall], fe_tools: list[ToolCall]):
"""
Returns True if none of the tool calls are frontend tools.
Args:
tool_calls: List of tool calls from the model response
fe_tools: List of frontend tool names
Returns:
bool: True if all tool calls are backend tools, False if any are frontend tools
"""
if not tool_calls:
return False
# Get the set of frontend tool names for faster lookup
fe_tool_names = {tool.get("name") for tool in fe_tools}
# Check if any tool call is a frontend tool
for tool_call in tool_calls:
tool_name = (
tool_call.get("name")
if isinstance(tool_call, dict)
else getattr(tool_call, "name", None)
)
if tool_name in fe_tool_names:
return False
# None of the tool calls are frontend tools
return True