Self-improving AI Employees for everyone
Python ai-agentsai-employeeai-employeesassistantautonomous-agentsco-employeescompanygrok-botinstinctloop-agentsmuseown-your-datapersonalself-hosted
Fix Tool Nodes
trohitg9fbcac7c8b78
diff --git a/client/src/components/ModelNode.tsx b/client/src/components/ModelNode.tsxindex ab23cc24..0bcafee5 100644--- a/client/src/components/ModelNode.tsx+++ b/client/src/components/ModelNode.tsx@@ -2,8 +2,8 @@ import React, { useMemo } from 'react';import { Handle, Position, NodeProps } from 'reactflow';import { NodeData } from '../types/NodeTypes';import { useAppStore } from '../store/useAppStore';-import { nodeDefinitions, TOOL_NODES } from '../nodeDefinitions';-import { useWebSocket, useNodeStatus, useIsToolExecuting } from '../contexts/WebSocketContext';+import { nodeDefinitions } from '../nodeDefinitions';+import { useWebSocket, useNodeStatus } from '../contexts/WebSocketContext';import { useAppTheme } from '../hooks/useAppTheme';// Map credential names to provider keys@@ -29,21 +29,8 @@ const ModelNode: React.FC<NodeProps<NodeData>> = ({ id, type, data, isConnectablconst definition = nodeDefinitions[type as keyof typeof nodeDefinitions];- // Check if this is a tool node and if it's being executed by an AI Agent- const isToolNode = TOOL_NODES.includes(type || '');- // Get tool name from node data or definition defaults- const toolName = useMemo(() => {- if (!isToolNode) return '';- // Check node data first, then definition defaults- const nameFromData = data?.toolName;- if (nameFromData) return nameFromData;- // Get default from definition properties- const toolNameProp = definition?.properties?.find((p: any) => p.name === 'toolName');- return toolNameProp?.default || '';- }, [isToolNode, data?.toolName, definition?.properties]);- const isToolBeingExecuted = useIsToolExecuting(toolName);- // Tool is "executing" when AI Agent is using it- const isToolActive = isToolNode && isToolBeingExecuted;+ // Check if this is a tool node+ const isToolNode = type ? ['calculatorTool', 'currentTimeTool', 'webSearchTool'].includes(type) : false;// Determine provider from node definition or typeconst provider = useMemo(() => {@@ -135,7 +122,7 @@ const ModelNode: React.FC<NodeProps<NodeData>> = ({ id, type, data, isConnectablbackground: theme.isDarkMode? `linear-gradient(135deg, ${nodeColor}20 0%, ${theme.colors.backgroundAlt} 100%)`: `linear-gradient(145deg, #ffffff 0%, ${nodeColor}10 100%)`,- border: `2px solid ${(isExecuting || isToolActive)+ border: `2px solid ${isExecuting? (theme.isDarkMode ? theme.dracula.cyan : '#2563eb'): selected? theme.colors.focus@@ -149,7 +136,7 @@ const ModelNode: React.FC<NodeProps<NodeData>> = ({ id, type, data, isConnectablfontSize: type === 'aiAgent' ? theme.fontSize.lg : theme.iconSize.xl,fontWeight: theme.fontWeight.semibold,transition: theme.transitions.fast,- boxShadow: (isExecuting || isToolActive)+ boxShadow: isExecuting? theme.isDarkMode? `0 4px 12px ${theme.dracula.cyan}66, 0 0 0 3px ${theme.dracula.cyan}4D`: `0 0 0 3px rgba(37, 99, 235, 0.5), 0 4px 16px rgba(37, 99, 235, 0.35)`@@ -160,29 +147,9 @@ const ModelNode: React.FC<NodeProps<NodeData>> = ({ id, type, data, isConnectabl? `0 2px 8px ${nodeColor}30`: `0 2px 8px ${nodeColor}25, 0 4px 12px rgba(0,0,0,0.06)`): `0 2px 8px ${theme.dracula.red}4D`,- animation: (isExecuting || isToolActive) ? 'pulse 1.5s ease-in-out infinite' : 'none',+ animation: isExecuting ? 'pulse 1.5s ease-in-out infinite' : 'none',}}>- {/* Spinning Arrow Ring - shows when tool is being executed by AI Agent */}- {isToolActive && (- <div- style={{- position: 'absolute',- top: -8,- left: -8,- right: -8,- bottom: -8,- borderRadius: '50%',- border: '3px solid transparent',- borderTopColor: theme.dracula.cyan,- borderRightColor: theme.dracula.purple,- borderBottomColor: theme.dracula.cyan,- animation: 'spin 1s linear infinite',- zIndex: 50,- pointerEvents: 'none',- }}- />- )}{/* AI Text */}{getProviderDisplay()}@@ -226,7 +193,7 @@ const ModelNode: React.FC<NodeProps<NodeData>> = ({ id, type, data, isConnectablwidth: theme.nodeSize.statusIndicator,height: theme.nodeSize.statusIndicator,borderRadius: '50%',- backgroundColor: (isExecuting || isToolActive)+ backgroundColor: isExecuting? theme.dracula.cyan: executionStatus === 'success'? theme.dracula.green@@ -238,7 +205,7 @@ const ModelNode: React.FC<NodeProps<NodeData>> = ({ id, type, data, isConnectabl? theme.dracula.orange: theme.dracula.red,border: `2px solid ${theme.isDarkMode ? theme.colors.background : '#ffffff'}`,- boxShadow: (isExecuting || isToolActive)+ boxShadow: isExecuting? theme.isDarkMode? `0 0 6px ${theme.dracula.cyan}80`: '0 0 4px rgba(37, 99, 235, 0.5)'@@ -246,22 +213,20 @@ const ModelNode: React.FC<NodeProps<NodeData>> = ({ id, type, data, isConnectabl? `0 1px 3px ${theme.colors.shadow}`: '0 1px 3px rgba(0,0,0,0.15)',zIndex: 30,- animation: (isExecuting || isToolActive) ? 'pulse 1s ease-in-out infinite' : 'none',+ animation: isExecuting ? 'pulse 1s ease-in-out infinite' : 'none',}}title={- isToolActive- ? 'Tool executing...'- : isExecuting- ? 'Executing...'- : isMemoryNode- ? 'Memory node ready'- : isToolNode- ? 'Tool ready'- : isConfigured- ? 'Model configured and ready'- : hasApiKey- ? 'API key found, model needs configuration'- : 'API key required'+ isExecuting+ ? 'Executing...'+ : isMemoryNode+ ? 'Memory node ready'+ : isToolNode+ ? 'Tool ready'+ : isConfigured+ ? 'Model configured and ready'+ : hasApiKey+ ? 'API key found, model needs configuration'+ : 'API key required'}/>diff --git a/client/src/components/SquareNode.tsx b/client/src/components/SquareNode.tsxindex 9a4850a4..54e64381 100644--- a/client/src/components/SquareNode.tsx+++ b/client/src/components/SquareNode.tsx@@ -572,35 +572,6 @@ const SquareNode: React.FC<NodeProps<NodeData>> = ({ id, type, data, isConnectab</div>)}- {/* Animated Border - shows when tool-capable node is being executed via toolkit */}- {isExecuting && isToolCapable && (- <div- style={{- position: 'absolute',- top: -3,- left: -3,- right: -3,- bottom: -3,- borderRadius: `calc(${theme.borderRadius.lg} + 1px)`,- border: `2px solid ${theme.dracula.purple}`,- animation: 'toolPulse 0.8s ease-in-out infinite',- zIndex: 50,- pointerEvents: 'none',- }}- />- )}- <style>{`- @keyframes toolPulse {- 0%, 100% {- border-color: ${theme.dracula.cyan};- box-shadow: 0 0 8px ${theme.dracula.cyan}80, inset 0 0 4px ${theme.dracula.cyan}40;- }- 50% {- border-color: ${theme.dracula.purple};- box-shadow: 0 0 12px ${theme.dracula.purple}80, inset 0 0 6px ${theme.dracula.purple}40;- }- }- `}</style>{/* Service Icon */}{getServiceIcon()}diff --git a/client/src/contexts/WebSocketContext.tsx b/client/src/contexts/WebSocketContext.tsxindex 1bd7e1ab..c4c0f2fa 100644--- a/client/src/contexts/WebSocketContext.tsx+++ b/client/src/contexts/WebSocketContext.tsx@@ -485,26 +485,19 @@ export const WebSocketProvider: React.FC<{ children: React.ReactNode }> = ({ chi// Store status under workflow_id -> node_id structureif (node_id) {const statusWorkflowId = message.workflow_id || 'unknown';- const phase = data?.phase;+ // Phase and tool_name are inside data.data (nested structure from broadcaster)+ const innerData = data?.data || {};- // Use flushSync for tool execution phases to force immediate re-render- // This ensures the spinning animation appears before tool_completed arrives- const isToolPhase = phase === 'executing_tool' || phase === 'tool_completed';- const updateFn = () => {- setAllNodeStatuses((prev: Record<string, Record<string, NodeStatus>>) => ({- ...prev,- [statusWorkflowId]: {- ...(prev[statusWorkflowId] || {}),- [node_id]: { ...data, workflow_id: statusWorkflowId }- }- }));- };+ // Flatten the structure: merge inner data with outer data for easier access+ const flattenedData = { ...data, ...innerData, workflow_id: statusWorkflowId };- if (isToolPhase) {- flushSync(updateFn);- } else {- updateFn();- }+ setAllNodeStatuses((prev: Record<string, Record<string, NodeStatus>>) => ({+ ...prev,+ [statusWorkflowId]: {+ ...(prev[statusWorkflowId] || {}),+ [node_id]: flattenedData+ }+ }));}break;@@ -1723,11 +1716,24 @@ export const useWhatsAppMessages = (): {export const useIsToolExecuting = (toolName: string): boolean => {const { nodeStatuses } = useWebSocket();+ // Debug: Log what we're checking+ if (toolName) {+ const statusCount = Object.keys(nodeStatuses).length;+ if (statusCount > 0) {+ console.log(`[useIsToolExecuting] Checking for tool '${toolName}', nodeStatuses count:`, statusCount, nodeStatuses);+ }+ }+// Scan all node statuses to find if any AI Agent is executing this tool+ // The status object contains phase and tool_name directly (not nested under data)for (const nodeId in nodeStatuses) {- const status = nodeStatuses[nodeId];- if (status?.data?.phase === 'executing_tool' && status?.data?.tool_name === toolName) {- return true;+ const status = nodeStatuses[nodeId] as Record<string, any>;+ if (status?.phase === 'executing_tool') {+ console.log(`[useIsToolExecuting] Found executing_tool phase for node ${nodeId}:`, status);+ if (status?.tool_name === toolName) {+ console.log(`[useIsToolExecuting] MATCH! Tool '${toolName}' is executing`);+ return true;+ }}}return false;diff --git a/server/services/ai.py b/server/services/ai.pyindex a2c7049c..275e2f04 100644--- a/server/services/ai.py+++ b/server/services/ai.py@@ -608,25 +608,47 @@ class AIService:"""Execute a tool by name."""from services.handlers.tools import execute_tool- logger.info(f"[LangGraph] tool_executor called for: {tool_name}, broadcasting executing_tool status")+ config = tool_configs.get(tool_name, {})+ tool_node_id = config.get('node_id')++ logger.info(f"[LangGraph] tool_executor called for: {tool_name} (node_id: {tool_node_id})")++ # Broadcast executing status to the AI Agent nodeawait broadcast_status("executing_tool", {"message": f"Executing tool: {tool_name}","tool_name": tool_name,"tool_args": tool_args})- logger.info(f"[LangGraph] broadcast_status completed for executing_tool: {tool_name}")- config = tool_configs.get(tool_name, {})+ # Also broadcast executing status directly to the tool node so it glows+ if tool_node_id and broadcaster:+ await broadcaster.update_node_status(+ tool_node_id,+ "executing",+ {"message": f"Executing {tool_name}"},+ workflow_id=workflow_id+ )+# Include workflow_id in config so tool handlers can broadcast with proper scopingconfig['workflow_id'] = workflow_idresult = await execute_tool(tool_name, tool_args, config)+ # Broadcast completion to AI Agent nodeawait broadcast_status("tool_completed", {"message": f"Tool completed: {tool_name}","tool_name": tool_name,"result_preview": str(result)[:100]})+ # Broadcast success status to the tool node+ if tool_node_id and broadcaster:+ await broadcaster.update_node_status(+ tool_node_id,+ "success",+ {"message": f"{tool_name} completed", "result": result},+ workflow_id=workflow_id+ )+return result# Broadcast: Building graph