Skip to content

Self-improving AI Employees for everyone

Add WhatsApp nodes as dual-purpose AI Agent tools

trohitg0a8ac57015b1
diff --git a/client/src/Dashboard.tsx b/client/src/Dashboard.tsx
index 4125dfbe..58026c91 100644
--- a/client/src/Dashboard.tsx
+++ b/client/src/Dashboard.tsx
@@ -29,6 +29,7 @@ import { CODE_NODE_TYPES } from './nodeDefinitions/codeNodes';
import { UTILITY_NODE_TYPES } from './nodeDefinitions/utilityNodes';
import { TOOL_NODE_TYPES } from './nodeDefinitions/toolNodes';
import { SKILL_NODE_TYPES } from './nodeDefinitions/skillNodes';
+import { DOCUMENT_NODE_TYPES } from './nodeDefinitions/documentNodes';
import ParameterPanel from './ParameterPanel';
import LocationParameterPanel from './components/LocationParameterPanel';
import { useAppStore } from './store/useAppStore';
@@ -107,8 +108,11 @@ const createNodeTypes = (): Record<string, React.ComponentType<any>> => {
types[type] = ModelNode;
}
} else if (SKILL_NODE_TYPES.includes(type)) {
- // Skill nodes use circular ModelNode design (connect to Chat Agent's input-skill handle)
- types[type] = ModelNode;
+ // Skill nodes use ToolkitNode (vertical handle layout like Android Toolkit)
+ types[type] = ToolkitNode;
+ } else if (DOCUMENT_NODE_TYPES.includes(type)) {
+ // Document processing nodes use SquareNode component
+ types[type] = SquareNode;
} else if (definition?.group?.includes('model')) {
// Fallback for other model nodes
types[type] = ModelNode;
diff --git a/client/src/components/AIAgentNode.tsx b/client/src/components/AIAgentNode.tsx
index a7f6bed7..9a2f6a6c 100644
--- a/client/src/components/AIAgentNode.tsx
+++ b/client/src/components/AIAgentNode.tsx
@@ -62,11 +62,11 @@ const AGENT_CONFIGS: Record<string, AgentConfig> = {
chatAgent: {
icon: <ChatAgentIcon />,
title: 'Chat Agent',
- subtitle: 'Conversational Agent',
+ subtitle: 'Skill-based Agent',
accentColor: '#3B82F6',
bottomHandles: [
- { id: 'input-memory', label: 'Memory', position: '35%' },
- { id: 'input-skill', label: 'Skill', position: '65%' },
+ { id: 'input-skill', label: 'Skill', position: '35%' },
+ { id: 'input-tools', label: 'Tool', position: '65%' },
],
},
};
diff --git a/client/src/components/SquareNode.tsx b/client/src/components/SquareNode.tsx
index a27697c7..9d2aaa11 100644
--- a/client/src/components/SquareNode.tsx
+++ b/client/src/components/SquareNode.tsx
@@ -17,6 +17,12 @@ const ALL_ANDROID_NODE_TYPES = [...ANDROID_SERVICE_NODE_TYPES, ...ANDROID_DEVICE
// Android service nodes that can connect to Android Toolkit as tools
const ANDROID_TOOL_CAPABLE_NODES = ANDROID_SERVICE_NODE_TYPES;
+// Nodes with 'tool' in their group can connect to AI Agent/Chat Agent tool handles
+const hasToolGroup = (definition: any): boolean => {
+ const groups = definition?.group || [];
+ return groups.includes('tool');
+};
+
// Google Maps node types
const GOOGLE_MAPS_NODE_TYPES = ['createMap', 'addLocations', 'showNearbyPlaces'];
@@ -68,8 +74,8 @@ const SquareNode: React.FC<NodeProps<NodeData>> = ({ id, type, data, isConnectab
// Check if this is an Android node
const isAndroidNode = type ? ALL_ANDROID_NODE_TYPES.includes(type) : false;
- // Check if this node can be used as a tool (connects to Android Toolkit)
- const isToolCapable = type ? ANDROID_TOOL_CAPABLE_NODES.includes(type) : false;
+ // Check if this node can be used as a tool (connects to Android Toolkit or AI Agent/Chat Agent tool handle)
+ const isToolCapable = type ? (ANDROID_TOOL_CAPABLE_NODES.includes(type) || hasToolGroup(definition)) : false;
// Android connection status from WebSocket (real-time updates)
// Service nodes need a paired device to execute, not just relay connection
@@ -680,7 +686,7 @@ const SquareNode: React.FC<NodeProps<NodeData>> = ({ id, type, data, isConnectab
/>
)}
- {/* Top Tool Output Handle - only for Android service nodes that can connect to Toolkit */}
+ {/* Top Tool Output Handle - for nodes that can connect to AI Agent/Chat Agent tool handle */}
{isToolCapable && (
<Handle
id="output-tool"
@@ -694,12 +700,12 @@ const SquareNode: React.FC<NodeProps<NodeData>> = ({ id, type, data, isConnectab
transform: 'translateX(-50%)',
width: theme.nodeSize.handle,
height: theme.nodeSize.handle,
- backgroundColor: '#3DDC84', // Android green to match Toolkit
+ backgroundColor: ANDROID_TOOL_CAPABLE_NODES.includes(type || '') ? '#3DDC84' : nodeColor, // Android green for Android nodes, node color for others
border: `2px solid ${theme.isDarkMode ? theme.colors.background : '#ffffff'}`,
borderRadius: '50%',
zIndex: 20
}}
- title="Connect to Android Toolkit"
+ title={ANDROID_TOOL_CAPABLE_NODES.includes(type || '') ? 'Connect to Android Toolkit' : 'Connect to AI Agent/Chat Agent tool handle'}
/>
)}
diff --git a/client/src/components/ToolkitNode.tsx b/client/src/components/ToolkitNode.tsx
index db1c649b..342e6c12 100644
--- a/client/src/components/ToolkitNode.tsx
+++ b/client/src/components/ToolkitNode.tsx
@@ -14,6 +14,7 @@ import { useAppStore } from '../store/useAppStore';
import { nodeDefinitions } from '../nodeDefinitions';
import { useAppTheme } from '../hooks/useAppTheme';
import { useWebSocket } from '../contexts/WebSocketContext';
+import { SKILL_NODE_TYPES } from '../nodeDefinitions/skillNodes';
const ToolkitNode: React.FC<NodeProps<NodeData>> = ({ id, type, data, isConnectable, selected }) => {
const theme = useAppTheme();
@@ -31,6 +32,9 @@ const ToolkitNode: React.FC<NodeProps<NodeData>> = ({ id, type, data, isConnecta
const definition = nodeDefinitions[type as keyof typeof nodeDefinitions];
+ // Check if this is a skill node (skill nodes don't have bottom input handle)
+ const isSkillNode = type ? SKILL_NODE_TYPES.includes(type) : false;
+
// Execution state
const isExecuting = executionStatus === 'executing' || executionStatus === 'waiting';
@@ -204,7 +208,7 @@ const ToolkitNode: React.FC<NodeProps<NodeData>> = ({ id, type, data, isConnecta
title={isExecuting ? 'Executing...' : 'Toolkit ready'}
/>
- {/* TOP Output Handle - connects to AI Agent */}
+ {/* TOP Output Handle - connects to AI Agent/Chat Agent */}
<Handle
id="output-main"
type="source"
@@ -222,29 +226,31 @@ const ToolkitNode: React.FC<NodeProps<NodeData>> = ({ id, type, data, isConnecta
borderRadius: '50%',
zIndex: 20
}}
- title="Connect to AI Agent's tool input"
+ title={isSkillNode ? "Connect to Chat Agent's skill input" : "Connect to AI Agent's tool input"}
/>
- {/* BOTTOM Input Handle - receives from Android nodes */}
- <Handle
- id="input-main"
- type="target"
- position={Position.Bottom}
- isConnectable={isConnectable}
- style={{
- position: 'absolute',
- bottom: '-6px',
- left: '50%',
- transform: 'translateX(-50%)',
- width: theme.nodeSize.handle,
- height: theme.nodeSize.handle,
- backgroundColor: theme.isDarkMode ? theme.colors.background : '#ffffff',
- border: `2px solid ${theme.isDarkMode ? theme.colors.textSecondary : '#6b7280'}`,
- borderRadius: '50%',
- zIndex: 20
- }}
- title="Connect Android service nodes here"
- />
+ {/* BOTTOM Input Handle - receives from Android nodes (not shown for skill nodes) */}
+ {!isSkillNode && (
+ <Handle
+ id="input-main"
+ type="target"
+ position={Position.Bottom}
+ isConnectable={isConnectable}
+ style={{
+ position: 'absolute',
+ bottom: '-6px',
+ left: '50%',
+ transform: 'translateX(-50%)',
+ width: theme.nodeSize.handle,
+ height: theme.nodeSize.handle,
+ backgroundColor: theme.isDarkMode ? theme.colors.background : '#ffffff',
+ border: `2px solid ${theme.isDarkMode ? theme.colors.textSecondary : '#6b7280'}`,
+ borderRadius: '50%',
+ zIndex: 20
+ }}
+ title="Connect Android service nodes here"
+ />
+ )}
{/* Output Data Indicator */}
{executionStatus === 'success' && nodeStatus?.data && (
diff --git a/client/src/components/parameterPanel/InputSection.tsx b/client/src/components/parameterPanel/InputSection.tsx
index 557f0501..ce11dfa8 100644
--- a/client/src/components/parameterPanel/InputSection.tsx
+++ b/client/src/components/parameterPanel/InputSection.tsx
@@ -331,6 +331,40 @@ const InputSection: React.FC<InputSectionProps> = ({ nodeId, visible = true }) =
message: 'string',
timestamp: 'string',
session_id: 'string'
+ },
+ // Document processing schemas
+ httpScraper: {
+ items: 'array',
+ item_count: 'number',
+ errors: 'array'
+ },
+ fileDownloader: {
+ downloaded: 'number',
+ skipped: 'number',
+ failed: 'number',
+ files: 'array',
+ output_dir: 'string'
+ },
+ documentParser: {
+ documents: 'array',
+ parsed_count: 'number',
+ failed: 'array'
+ },
+ textChunker: {
+ chunks: 'array',
+ chunk_count: 'number'
+ },
+ embeddingGenerator: {
+ embeddings: 'array',
+ embedding_count: 'number',
+ dimensions: 'number',
+ chunks: 'array'
+ },
+ vectorStore: {
+ stored_count: 'number',
+ matches: 'array',
+ collection_name: 'string',
+ backend: 'string'
}
};
@@ -349,6 +383,10 @@ const InputSection: React.FC<InputSectionProps> = ({ nodeId, visible = true }) =
const isCronScheduler = nodeType === 'cronScheduler';
const isChatTrigger = nodeType === 'chatTrigger';
+ // Document processing node detection
+ const documentNodeTypes = ['httpScraper', 'fileDownloader', 'documentParser', 'textChunker', 'embeddingGenerator', 'vectorStore'];
+ const isDocumentNode = documentNodeTypes.includes(nodeType);
+
// Android service node detection - check for specific Android node types
const androidNodeTypes = [
'batteryMonitor', 'systemInfo', 'networkMonitor',
@@ -369,6 +407,8 @@ const InputSection: React.FC<InputSectionProps> = ({ nodeId, visible = true }) =
outputSchema = sampleSchemas.androidLocation;
} else if (isAndroidNode && sampleSchemas[nodeType as keyof typeof sampleSchemas]) {
outputSchema = sampleSchemas[nodeType as keyof typeof sampleSchemas];
+ } else if (isDocumentNode && sampleSchemas[nodeType as keyof typeof sampleSchemas]) {
+ outputSchema = sampleSchemas[nodeType as keyof typeof sampleSchemas];
} else {
outputSchema = isLocationNode || isGoogleMaps ? sampleSchemas.location :
isMemory ? sampleSchemas.memory :
diff --git a/client/src/nodeDefinitions.ts b/client/src/nodeDefinitions.ts
index aed2e61d..c6da822b 100644
--- a/client/src/nodeDefinitions.ts
+++ b/client/src/nodeDefinitions.ts
@@ -15,6 +15,7 @@ import { chatNodes, CHAT_NODE_TYPES } from './nodeDefinitions/chatNodes';
import { codeNodes, CODE_NODE_TYPES } from './nodeDefinitions/codeNodes';
import { utilityNodes, UTILITY_NODE_TYPES } from './nodeDefinitions/utilityNodes';
import { skillNodes, SKILL_NODE_TYPES } from './nodeDefinitions/skillNodes';
+import { documentNodes, DOCUMENT_NODE_TYPES } from './nodeDefinitions/documentNodes';
// ============================================================================
// MAIN NODE REGISTRY - Combining all modular definitions
@@ -34,7 +35,8 @@ export const nodeDefinitions: Record<string, INodeTypeDescription> = {
...chatNodes,
...codeNodes,
...utilityNodes,
- ...skillNodes
+ ...skillNodes,
+ ...documentNodes
};
// ============================================================================
@@ -94,5 +96,9 @@ export const SKILL_NODES = [
...SKILL_NODE_TYPES
];
+export const DOCUMENT_NODES = [
+ ...DOCUMENT_NODE_TYPES
+];
+
// Re-export types and utilities from modular files for external access
export { createBaseChatModel } from './nodeDefinitions/aiModelNodes';
\ No newline at end of file
diff --git a/client/src/nodeDefinitions/aiAgentNodes.ts b/client/src/nodeDefinitions/aiAgentNodes.ts
index 867e8050..ae7e6a4a 100644
--- a/client/src/nodeDefinitions/aiAgentNodes.ts
+++ b/client/src/nodeDefinitions/aiAgentNodes.ts
@@ -153,7 +153,7 @@ export const aiAgentNodes: Record<string, INodeTypeDescription> = {
]
},
- // Chat Agent Node - Conversational AI agent with memory and skill support (no tools)
+ // Chat Agent Node - Conversational AI agent with skill-based tool calling
chatAgent: {
displayName: 'Chat Agent',
name: 'chatAgent',
@@ -161,7 +161,7 @@ export const aiAgentNodes: Record<string, INodeTypeDescription> = {
group: ['agent'],
version: 1,
subtitle: 'Conversational Agent',
- description: 'Conversational AI agent with memory and skill support for multi-turn chat interactions',
+ description: 'Conversational AI agent with skill-based tool calling for multi-turn chat interactions',
defaults: { name: 'Chat Agent', color: '#3B82F6' },
inputs: [
{
@@ -171,16 +171,16 @@ export const aiAgentNodes: Record<string, INodeTypeDescription> = {
description: 'Chat input'
},
{
- name: 'memory',
- displayName: 'Memory',
+ name: 'skill',
+ displayName: 'Skill',
type: 'main' as NodeConnectionType,
- description: 'Memory node connection for conversation history'
+ description: 'Skill nodes that provide context and instructions via SKILL.md'
},
{
- name: 'skill',
- displayName: 'Skill',
+ name: 'tools',
+ displayName: 'Tool',
type: 'main' as NodeConnectionType,
- description: 'AI Skill node connection'
+ description: 'Tool nodes (httpRequest, etc.) for LangGraph tool calling'
}
],
outputs: [{
diff --git a/client/src/nodeDefinitions/documentNodes.ts b/client/src/nodeDefinitions/documentNodes.ts
new file mode 100644
index 00000000..d5f249f7
--- /dev/null
+++ b/client/src/nodeDefinitions/documentNodes.ts
@@ -0,0 +1,379 @@
+// Document Processing Nodes - HTTP Scraper, File Downloader, Document Parser, Text Chunker, Embedding Generator, Vector Store
+import {
+ INodeTypeDescription,
+ NodeConnectionType
+} from '../types/INodeProperties';
+
+export const documentNodes: Record<string, INodeTypeDescription> = {
+ httpScraper: {
+ displayName: 'HTTP Scraper',
+ name: 'httpScraper',
+ icon: '🔍',
+ group: ['document'],
+ version: 1,
+ description: 'Scrape links from web pages with date/page pagination support',
+ defaults: { name: 'HTTP Scraper', color: '#DC2626' },
+ inputs: [{ name: 'main', displayName: 'Input', type: 'main' as NodeConnectionType, description: 'Trigger input' }],
+ outputs: [{
+ name: 'main',
+ displayName: 'Items',
+ type: 'main' as NodeConnectionType,
+ description: 'items, item_count, errors'
+ }],
+ properties: [
+ {
+ displayName: 'URL',
+ name: 'url',
+ type: 'string',
+ default: '',
+ required: true,
+ placeholder: 'https://example.com/api?date={date}',
+ description: 'URL with optional placeholders: {date}, {page}'
+ },
+ {
+ displayName: 'Iteration Mode',
+ name: 'iterationMode',
+ type: 'options',
+ default: 'single',
+ options: [
+ { name: 'Single Request', value: 'single' },
+ { name: 'Date Range', value: 'date' },
+ { name: 'Page Pagination', value: 'page' }
+ ]
+ },
+ {
+ displayName: 'Start Date',
+ name: 'startDate',
+ type: 'string',
+ default: '',
+ placeholder: 'YYYY-MM-DD',
+ displayOptions: { show: { iterationMode: ['date'] } }
+ },
+ {
+ displayName: 'End Date',
+ name: 'endDate',
+ type: 'string',
+ default: '',
+ placeholder: 'YYYY-MM-DD',
+ displayOptions: { show: { iterationMode: ['date'] } }
+ },
+ {
+ displayName: 'Date Placeholder',
+ name: 'datePlaceholder',
+ type: 'string',
+ default: '{date}',
+ displayOptions: { show: { iterationMode: ['date'] } }
+ },
+ {
+ displayName: 'Start Page',
+ name: 'startPage',
+ type: 'number',
+ default: 1,
+ displayOptions: { show: { iterationMode: ['page'] } }
+ },
+ {
+ displayName: 'End Page',
+ name: 'endPage',
+ type: 'number',
+ default: 10,
+ displayOptions: { show: { iterationMode: ['page'] } }
+ },
+ {
+ displayName: 'Link Selector',
+ name: 'linkSelector',
+ type: 'string',
+ default: 'a[href$=".pdf"]',
+ description: 'CSS selector for extracting links'
+ },
+ {
+ displayName: 'Headers (JSON)',
+ name: 'headers',
+ type: 'string',
+ default: '{}',
+ typeOptions: { rows: 2 },
+ placeholder: '{"Authorization": "Bearer token"}'
+ }
+ ]
+ },
+
+ fileDownloader: {
+ displayName: 'File Downloader',
+ name: 'fileDownloader',
+ icon: '⬇️',
+ group: ['document'],
+ version: 1,
+ description: 'Download files from URLs in parallel',
+ defaults: { name: 'Downloader', color: '#2563EB' },
+ inputs: [{ name: 'main', displayName: 'Items', type: 'main' as NodeConnectionType, description: 'Array of items with url field' }],
+ outputs: [{
+ name: 'main',
+ displayName: 'Files',
+ type: 'main' as NodeConnectionType,
+ description: 'downloaded, skipped, failed, files, output_dir'
+ }],
+ properties: [
+ {
+ displayName: 'Output Directory',
+ name: 'outputDir',
+ type: 'string',
+ default: './data/downloads',
+ description: 'Directory to save downloaded files'
+ },
+ {
+ displayName: 'Max Workers',
+ name: 'maxWorkers',
+ type: 'number',
+ default: 8,
+ typeOptions: { minValue: 1, maxValue: 32 },
+ description: 'Number of parallel download workers'
+ },
+ {
+ displayName: 'Skip Existing',
+ name: 'skipExisting',
+ type: 'boolean',
+ default: true,
+ description: 'Skip files that already exist'
+ },
+ {
+ displayName: 'Timeout (seconds)',
+ name: 'timeout',
+ type: 'number',
+ default: 60,
+ typeOptions: { minValue: 10, maxValue: 600 }
+ }
+ ]
+ },
+
+ documentParser: {
+ displayName: 'Document Parser',
+ name: 'documentParser',
+ icon: '📄',
+ group: ['document'],
+ version: 1,
+ description: 'Parse documents to text using various parsers',
+ defaults: { name: 'Parser', color: '#059669' },
+ inputs: [{ name: 'main', displayName: 'Files', type: 'main' as NodeConnectionType, description: 'Array of files with path field' }],
+ outputs: [{
+ name: 'main',
+ displayName: 'Documents',
+ type: 'main' as NodeConnectionType,
+ description: 'documents, parsed_count, failed'
+ }],
+ properties: [
+ {
+ displayName: 'Parser',
+ name: 'parser',
+ type: 'options',
+ default: 'pypdf',
+ options: [
+ { name: 'PyPDF (Fast)', value: 'pypdf' },
+ { name: 'Marker (GPU OCR)', value: 'marker' },
+ { name: 'Unstructured (Multi-format)', value: 'unstructured' },
+ { name: 'BeautifulSoup (HTML)', value: 'beautifulsoup' }
+ ]
+ },
+ {
+ displayName: 'Input Directory',
+ name: 'inputDir',
+ type: 'string',
+ default: '',
+ description: 'Directory to scan for files (optional, in addition to input)'
+ },
+ {
+ displayName: 'File Pattern',
+ name: 'filePattern',
+ type: 'string',
+ default: '*.pdf',
+ description: 'Glob pattern for files in inputDir'
+ }
+ ]
+ },
+
+ textChunker: {
+ displayName: 'Text Chunker',
+ name: 'textChunker',
+ icon: '✂️',
+ group: ['document'],
+ version: 1,
+ description: 'Split text into overlapping chunks for embedding',
+ defaults: { name: 'Chunker', color: '#7C3AED' },
+ inputs: [{ name: 'main', displayName: 'Documents', type: 'main' as NodeConnectionType, description: 'Array of documents with content field' }],
+ outputs: [{
+ name: 'main',
+ displayName: 'Chunks',
+ type: 'main' as NodeConnectionType,
+ description: 'chunks, chunk_count'
+ }],
+ properties: [
+ {
+ displayName: 'Chunk Size',
+ name: 'chunkSize',
+ type: 'number',
+ default: 1024,
+ typeOptions: { minValue: 100, maxValue: 8000 },
+ description: 'Target size of each chunk in characters'
+ },
+ {
+ displayName: 'Chunk Overlap',
+ name: 'chunkOverlap',
+ type: 'number',
+ default: 200,
+ typeOptions: { minValue: 0, maxValue: 1000 },
+ description: 'Number of overlapping characters between chunks'
+ },
+ {
+ displayName: 'Strategy',
+ name: 'strategy',
+ type: 'options',
+ default: 'recursive',
+ options: [
+ { name: 'Recursive (Recommended)', value: 'recursive' },
+ { name: 'Markdown', value: 'markdown' },
+ { name: 'Token', value: 'token' }
+ ]
+ }
+ ]
+ },
+
+ embeddingGenerator: {
+ displayName: 'Embedding Generator',
+ name: 'embeddingGenerator',
+ icon: '🧠',
+ group: ['document'],
+ version: 1,
+ description: 'Generate vector embeddings from text chunks',
+ defaults: { name: 'Embedder', color: '#F59E0B' },
+ inputs: [{ name: 'main', displayName: 'Chunks', type: 'main' as NodeConnectionType, description: 'Array of chunks with content field' }],
+ outputs: [{
+ name: 'main',
+ displayName: 'Embeddings',
+ type: 'main' as NodeConnectionType,
+ description: 'embeddings, embedding_count, dimensions, chunks'
+ }],
+ properties: [
+ {
+ displayName: 'Provider',
+ name: 'provider',
+ type: 'options',
+ default: 'huggingface',
+ options: [
+ { name: 'HuggingFace (Local)', value: 'huggingface' },
+ { name: 'OpenAI', value: 'openai' },
+ { name: 'Ollama (Local)', value: 'ollama' }
+ ]
+ },
+ {
+ displayName: 'Model',
+ name: 'model',
+ type: 'string',
+ default: 'BAAI/bge-small-en-v1.5',
+ description: 'Embedding model name'
+ },
+ {
+ displayName: 'Batch Size',
+ name: 'batchSize',
+ type: 'number',
+ default: 32,
+ typeOptions: { minValue: 1, maxValue: 256 }
+ },
+ {
+ displayName: 'API Key',
+ name: 'apiKey',
+ type: 'string',
+ default: '',
+ typeOptions: { password: true },
+ displayOptions: { show: { provider: ['openai'] } },
+ description: 'OpenAI API key (if using OpenAI provider)'
+ }
+ ]
+ },
+
+ vectorStore: {
+ displayName: 'Vector Store',
+ name: 'vectorStore',
+ icon: '🗄️',
+ group: ['document'],
+ version: 1,
+ description: 'Store and query vector embeddings',
+ defaults: { name: 'Vector Store', color: '#8B5CF6' },
+ inputs: [{ name: 'main', displayName: 'Embeddings', type: 'main' as NodeConnectionType, description: 'Array of embeddings or query embedding' }],
+ outputs: [{
+ name: 'main',
+ displayName: 'Result',
+ type: 'main' as NodeConnectionType,
+ description: 'stored_count/matches, collection_name, backend'
+ }],
+ properties: [
+ {
+ displayName: 'Operation',
+ name: 'operation',
+ type: 'options',
+ default: 'store',
+ options: [
+ { name: 'Store', value: 'store' },
+ { name: 'Query', value: 'query' },
+ { name: 'Delete', value: 'delete' }
+ ]
+ },
+ {
+ displayName: 'Backend',
+ name: 'backend',
+ type: 'options',
+ default: 'chroma',
+ options: [
+ { name: 'ChromaDB (Local)', value: 'chroma' },
+ { name: 'Qdrant (Production)', value: 'qdrant' },
+ { name: 'Pinecone (Cloud)', value: 'pinecone' }
+ ]
+ },
+ {
+ displayName: 'Collection Name',
+ name: 'collectionName',
+ type: 'string',
+ default: 'documents',
+ description: 'Name of the vector collection'
+ },
+ {
+ displayName: 'Persist Directory',
+ name: 'persistDir',
+ type: 'string',
+ default: './data/vectors',
+ displayOptions: { show: { backend: ['chroma'] } },
+ description: 'Directory to persist ChromaDB data'
+ },
+ {
+ displayName: 'Qdrant URL',
+ name: 'qdrantUrl',
+ type: 'string',
+ default: 'http://localhost:6333',
+ displayOptions: { show: { backend: ['qdrant'] } }
+ },
+ {
+ displayName: 'Pinecone API Key',
+ name: 'pineconeApiKey',
+ type: 'string',
+ default: '',
+ typeOptions: { password: true },
+ displayOptions: { show: { backend: ['pinecone'] } }
+ },
+ {
+ displayName: 'Top K',
+ name: 'topK',
+ type: 'number',
+ default: 5,
+ typeOptions: { minValue: 1, maxValue: 100 },
+ displayOptions: { show: { operation: ['query'] } },
+ description: 'Number of results to return for queries'
+ }
+ ]
+ }
+};
+
+export const DOCUMENT_NODE_TYPES = [
+ 'httpScraper',
+ 'fileDownloader',
+ 'documentParser',
+ 'textChunker',
+ 'embeddingGenerator',
+ 'vectorStore'
+];
diff --git a/client/src/nodeDefinitions/index.ts b/client/src/nodeDefinitions/index.ts
index 50089ce5..ffbdffc3 100644
--- a/client/src/nodeDefinitions/index.ts
+++ b/client/src/nodeDefinitions/index.ts
@@ -5,6 +5,7 @@ export { locationNodes, LOCATION_NODE_TYPES } from './locationNodes';
export { workflowNodes, WORKFLOW_NODE_TYPES } from './workflowNodes';
export { schedulerNodes, SCHEDULER_NODE_TYPES } from './schedulerNodes';
export { chatNodes, CHAT_NODE_TYPES } from './chatNodes';
+export { documentNodes, DOCUMENT_NODE_TYPES } from './documentNodes';
// Re-export types for convenience
export type {
diff --git a/client/src/nodeDefinitions/skillNodes.ts b/client/src/nodeDefinitions/skillNodes.ts
index 2da2256c..89717d8a 100644
--- a/client/src/nodeDefinitions/skillNodes.ts
+++ b/client/src/nodeDefinitions/skillNodes.ts
@@ -64,12 +64,12 @@ function createSkillNode(config: {
export const skillNodes: Record<string, INodeTypeDescription> = {
// Assistant Personality Skill - Default assistant personality
- claudeSkill: createSkillNode({
- name: 'claudeSkill',
+ assistantPersonality: createSkillNode({
+ name: 'assistantPersonality',
displayName: 'Assistant Personality',
icon: '✨',
color: '#D97706',
- skillName: 'claude-assistant',
+ skillName: 'assistant-personality',
subtitle: 'AI Personality',
description: 'Default assistant personality with helpful, harmless, and honest responses'
}),
@@ -195,7 +195,7 @@ export const skillNodes: Record<string, INodeTypeDescription> = {
// List of skill node types for easy identification
export const SKILL_NODE_TYPES = [
- 'claudeSkill',
+ 'assistantPersonality',
'whatsappSkill',
'memorySkill',
'mapsSkill',
diff --git a/client/src/nodeDefinitions/utilityNodes.ts b/client/src/nodeDefinitions/utilityNodes.ts
index 6331ca3b..37ab176e 100644
--- a/client/src/nodeDefinitions/utilityNodes.ts
+++ b/client/src/nodeDefinitions/utilityNodes.ts
@@ -9,7 +9,7 @@ export const utilityNodes: Record<string, INodeTypeDescription> = {
displayName: 'HTTP Request',
name: 'httpRequest',
icon: '🌐',
- group: ['utility'],
+ group: ['utility', 'tool'],
version: 1,
description: 'Make HTTP requests to external APIs',
defaults: { name: 'HTTP Request', color: '#6366f1' },
diff --git a/client/src/nodeDefinitions/whatsappNodes.ts b/client/src/nodeDefinitions/whatsappNodes.ts
index ac4c2c35..c39a6f12 100644
--- a/client/src/nodeDefinitions/whatsappNodes.ts
+++ b/client/src/nodeDefinitions/whatsappNodes.ts
@@ -80,7 +80,7 @@ export const whatsappNodes: Record<string, INodeTypeDescription> = {
displayName: 'WhatsApp Send',
name: 'whatsappSend',
icon: WHATSAPP_SEND_ICON,
- group: ['whatsapp'],
+ group: ['whatsapp', 'tool'],
version: 1,
subtitle: 'Send WhatsApp Message',
description: 'Send text, media, location, or contact messages via WhatsApp',
@@ -91,12 +91,20 @@ export const whatsappNodes: Record<string, INodeTypeDescription> = {
type: 'main' as NodeConnectionType,
description: 'Message input'
}],
- outputs: [{
- name: 'main',
- displayName: 'Output',
- type: 'main' as NodeConnectionType,
- description: 'Message output'
- }],
+ outputs: [
+ {
+ name: 'main',
+ displayName: 'Output',
+ type: 'main' as NodeConnectionType,
+ description: 'Message output'
+ },
+ {
+ name: 'tool',
+ displayName: 'Tool',
+ type: 'main' as NodeConnectionType,
+ description: 'Connect to AI Agent tool handle'
+ }
+ ],
properties: [
// ===== RECIPIENT =====
{
@@ -618,11 +626,12 @@ export const whatsappNodes: Record<string, INodeTypeDescription> = {
},
// WhatsApp Chat History Node - Retrieve stored messages
+ // Can be used as workflow node OR as AI Agent tool (group includes 'tool')
whatsappChatHistory: {
displayName: 'WhatsApp Chat History',
name: 'whatsappChatHistory',
icon: WHATSAPP_HISTORY_ICON,
- group: ['whatsapp'],
+ group: ['whatsapp', 'tool'],
version: 1,
subtitle: 'Get Messages',
description: 'Retrieve chat history from WhatsApp conversations. Messages are synced on first login and stored for later retrieval.',
@@ -633,12 +642,20 @@ export const whatsappNodes: Record<string, INodeTypeDescription> = {
type: 'main' as NodeConnectionType,
description: 'Trigger input'
}],
- outputs: [{
- name: 'main',
- displayName: 'Messages',
- type: 'main' as NodeConnectionType,
- description: 'Chat history messages (messages, total, has_more)'
- }],
+ outputs: [
+ {
+ name: 'main',
+ displayName: 'Messages',
+ type: 'main' as NodeConnectionType,
+ description: 'Chat history messages (messages, total, has_more)'
+ },
+ {
+ name: 'tool',
+ displayName: 'Tool',
+ type: 'main' as NodeConnectionType,
+ description: 'Connect to AI Agent tool handle'
+ }
+ ],
properties: [
// ===== CHAT TYPE =====
{
diff --git a/client/src/services/executionService.ts b/client/src/services/executionService.ts
index 783e0e68..040c4f98 100644
--- a/client/src/services/executionService.ts
+++ b/client/src/services/executionService.ts
@@ -4,6 +4,7 @@ import { ANDROID_DEVICE_NODE_TYPES } from '../nodeDefinitions/androidDeviceNodes
import { SCHEDULER_NODE_TYPES } from '../nodeDefinitions/schedulerNodes';
import { CODE_NODE_TYPES } from '../nodeDefinitions/codeNodes';
import { UTILITY_NODE_TYPES } from '../nodeDefinitions/utilityNodes';
+import { DOCUMENT_NODE_TYPES } from '../nodeDefinitions/documentNodes';
import { Node, Edge } from 'reactflow';
import { INodeExecutionData } from '../types/INodeProperties';
import { API_CONFIG } from '../config/api';
@@ -221,7 +222,9 @@ export class ExecutionService {
// Code Execution Nodes
...CODE_NODE_TYPES,
// Utility Nodes (HTTP, Webhooks)
- ...UTILITY_NODE_TYPES
+ ...UTILITY_NODE_TYPES,
+ // Document Processing Nodes
+ ...DOCUMENT_NODE_TYPES
];
return supportedTypes.includes(nodeType);
diff --git a/server/constants.py b/server/constants.py
index 1db10e89..edf442ad 100644
--- a/server/constants.py
+++ b/server/constants.py
@@ -36,6 +36,20 @@ AI_TOOL_TYPES: FrozenSet[str] = frozenset([
'androidTool',
])
+# Skill node types (connect to Chat Agent's input-skill handle)
+# Skills provide SKILL.md context/instructions, not executed as workflow nodes
+SKILL_NODE_TYPES: FrozenSet[str] = frozenset([
+ 'assistantPersonality',
+ 'whatsappSkill',
+ 'memorySkill',
+ 'mapsSkill',
+ 'httpSkill',
+ 'schedulerSkill',
+ 'androidSkill',
+ 'codeSkill',
+ 'customSkill',
+])
+
# Toolkit node types (aggregate sub-nodes, n8n Sub-Node pattern)
# Sub-nodes connected to toolkits should not execute independently -
# they only execute when called via the toolkit's tool interface
@@ -51,11 +65,13 @@ AI_MODEL_TYPES: FrozenSet[str] = AI_AGENT_TYPES | AI_CHAT_MODEL_TYPES
# =============================================================================
# Config nodes provide configuration to other nodes via special handles
-# (input-memory, input-tools, input-model). They don't execute independently.
+# (input-memory, input-tools, input-model, input-skill).
+# They don't execute independently - they're used by their parent nodes.
CONFIG_NODE_TYPES: FrozenSet[str] = (
- AI_MEMORY_TYPES | # Memory nodes (connect to input-memory)
- AI_TOOL_TYPES | # Tool nodes (connect to input-tools)
- AI_CHAT_MODEL_TYPES # Model config nodes (connect to input-model)
+ AI_MEMORY_TYPES | # Memory nodes (connect to input-memory)
+ AI_TOOL_TYPES | # Tool nodes (connect to AI Agent's input-tools)
+ AI_CHAT_MODEL_TYPES | # Model config nodes (connect to input-model)
+ SKILL_NODE_TYPES # Skill nodes (connect to Chat Agent's input-skill)
)
# =============================================================================
diff --git a/server/models/nodes.py b/server/models/nodes.py
index 499be008..37f22767 100644
--- a/server/models/nodes.py
+++ b/server/models/nodes.py
@@ -65,6 +65,14 @@ class AIAgentParams(BaseNodeParams):
api_key: Optional[str] = Field(default=None, alias="apiKey")
+class ChatAgentParams(BaseNodeParams):
+ """Parameters for chat agent node (skill-based)."""
+ type: Literal["chatAgent"]
+ provider: Literal["openai", "anthropic", "gemini", "groq", "openrouter", "cerebras"] = "openai"
+ model: str = ""
+ api_key: Optional[str] = Field(default=None, alias="apiKey")
+
+
class SimpleMemoryParams(BaseNodeParams):
"""Parameters for simple memory node."""
type: Literal["simpleMemory"]
@@ -273,7 +281,7 @@ class ChatHistoryParams(BaseNodeParams):
# AI Nodes
AINodeParams = Annotated[
- Union[AIChatModelParams, AIAgentParams, SimpleMemoryParams],
+ Union[AIChatModelParams, AIAgentParams, ChatAgentParams, SimpleMemoryParams],
Field(discriminator="type")
]
@@ -323,7 +331,7 @@ ChatNodeParams = Annotated[
KnownNodeParams = Annotated[
Union[
# AI
- AIChatModelParams, AIAgentParams, SimpleMemoryParams,
+ AIChatModelParams, AIAgentParams, ChatAgentParams, SimpleMemoryParams,
# Maps
CreateMapParams, AddLocationsParams, ShowNearbyPlacesParams,
# Android Setup
diff --git a/server/requirements.txt b/server/requirements.txt
index e67d8f5b..10c3a807 100644
--- a/server/requirements.txt
+++ b/server/requirements.txt
@@ -70,3 +70,14 @@ email-validator>=2.0.0
# Timezone support
pytz>=2024.1
+# Document Processing Nodes
+beautifulsoup4>=4.12.0
+langchain-text-splitters>=0.3.0
+langchain-huggingface>=0.1.0
+chromadb>=0.5.0
+qdrant-client>=1.12.0
+sentence-transformers>=3.0.0
+pypdf>=4.0.0
+# marker-pdf>=1.0.0 # Optional: GPU OCR (requires CUDA)
+# unstructured>=0.16.0 # Optional: Multi-format document parsing
+
diff --git a/server/services/ai.py b/server/services/ai.py
index d82b7cde..dfd31f08 100644
--- a/server/services/ai.py
+++ b/server/services/ai.py
@@ -1457,18 +1457,21 @@ class AIService:
async def execute_chat_agent(self, node_id: str, parameters: Dict[str, Any],
memory_data: Optional[Dict[str, Any]] = None,
skill_data: Optional[List[Dict[str, Any]]] = None,
+ tool_data: Optional[List[Dict[str, Any]]] = None,
broadcaster=None,
workflow_id: Optional[str] = None) -> Dict[str, Any]:
- """Execute Chat Agent - conversational AI with skill support.
+ """Execute Chat Agent - conversational AI with skill-based tool calling.
- Chat Agent supports conversation with memory and skills. When skills are
- connected, the agent can use LangGraph for tool calling (like AI Agent).
+ Chat Agent supports:
+ - Skills (input-skill): Provide context/instructions via SKILL.md
+ - Tools (input-tools): Tool nodes (httpRequest, etc.) for LangGraph tool calling
Args:
node_id: The node identifier
parameters: Node parameters including prompt, model, etc.
- memory_data: Optional memory data from connected simpleMemory node
+ memory_data: Optional memory data (deprecated - use skills for memory)
skill_data: Optional skill configurations from connected skill nodes
+ tool_data: Optional tool configurations from connected tool nodes (httpRequest, etc.)
broadcaster: Optional StatusBroadcaster for real-time UI updates
workflow_id: Optional workflow ID for scoped status broadcasts
"""
@@ -1476,7 +1479,7 @@ class AIService:
provider = 'unknown'
model = 'unknown'
- logger.info(f"[ChatAgent] execute_chat_agent called: node_id={node_id}, workflow_id={workflow_id}, skill_count={len(skill_data) if skill_data else 0}")
+ logger.info(f"[ChatAgent] execute_chat_agent called: node_id={node_id}, workflow_id={workflow_id}, skill_count={len(skill_data) if skill_data else 0}, tool_count={len(tool_data) if tool_data else 0}")
async def broadcast_status(phase: str, details: Dict[str, Any] = None):
if broadcaster:
@@ -1491,17 +1494,16 @@ class AIService:
prompt = parameters.get('prompt', 'Hello')
system_message = parameters.get('systemMessage', 'You are a helpful assistant')
- # Load skills and enhance system message
- skill_names = []
- skill_tools = []
+ # Load skills and enhance system message with SKILL.md context
+ # Skills only provide instructions/context - actual tools come from direct tool nodes
if skill_data:
from services.skill_loader import get_skill_loader
- from services.skill_executor import get_skill_executor, init_skill_executor
skill_loader = get_skill_loader()
skill_loader.scan_skills()
# Extract skill names from connected skill nodes
+ skill_names = []
for skill_info in skill_data:
skill_name = skill_info.get('skill_name') or skill_info.get('node_type', '').replace('Skill', '-skill').lower()
# Convert node type to skill name (e.g., 'whatsappSkill' -> 'whatsapp-skill')
@@ -1510,25 +1512,33 @@ class AIService:
skill_names.append(skill_name)
logger.debug(f"[ChatAgent] Skill detected: {skill_name}")
- # Add skill registry to system message
+ # Add skill SKILL.md content to system message
skill_prompt = skill_loader.get_registry_prompt(skill_names)
if skill_prompt:
system_message = f"{system_message}\n\n{skill_prompt}"
- logger.info(f"[ChatAgent] Enhanced system message with {len(skill_names)} skills")
+ logger.info(f"[ChatAgent] Enhanced system message with {len(skill_names)} skill contexts")
- # Build tools from skills
- skill_executor = get_skill_executor()
- if not skill_executor:
- # Initialize skill executor with node executor callback
- async def node_executor_callback(node_id, node_type, parameters, context):
- from services.node_executor import NodeExecutor
- executor = NodeExecutor(self, self.database)
- return await executor.execute_node(node_id, node_type, parameters, context)
+ # Build tools from tool_data using same method as AI Agent
+ # This supports ALL tool types: calculatorTool, currentTimeTool, webSearchTool, androidTool, httpRequest
+ all_tools = []
+ tool_node_configs = {} # Map tool name to node config (same as AI Agent's tool_configs)
+ if tool_data:
+ await broadcast_status("building_tools", {
+ "message": f"Building {len(tool_data)} tool(s)...",
+ "tool_count": len(tool_data)
+ })
- skill_executor = init_skill_executor(skill_loader, node_executor_callback, self.database)
+ for tool_info in tool_data:
+ # Use AI Agent's _build_tool_from_node for all tool types
+ tool, config = await self._build_tool_from_node(tool_info)
+ if tool:
+ all_tools.append(tool)
+ tool_node_configs[tool.name] = config
+ logger.info(f"[ChatAgent] Built tool: {tool.name} (type={config.get('node_type')}, node_id={config.get('node_id')})")
- skill_tools = skill_executor.build_tools_for_skills(skill_names)
- logger.info(f"[ChatAgent] Built {len(skill_tools)} tools from skills")
+ logger.info(f"[ChatAgent] Built {len(all_tools)} tools from tool_data")
+
+ logger.info(f"[ChatAgent] Total tools available: {len(all_tools)}")
# Flatten options collection from frontend
options = parameters.get('options', {})
@@ -1621,41 +1631,70 @@ class AIService:
"message": "Generating response...",
"has_memory": session_id is not None,
"history_count": history_count,
- "skill_count": len(skill_names) if skill_data else 0
+ "skill_count": len(skill_data) if skill_data else 0
})
- # Execute with or without skill tools
+ # Execute with or without tools
thinking_content = None
iterations = 1
- if skill_tools:
- # Use LangGraph for skill tool execution (like AI Agent)
- logger.info(f"[ChatAgent] Using LangGraph with {len(skill_tools)} skill tools")
-
- # Create skill tool executor callback
- async def skill_tool_executor(tool_name: str, tool_args: Dict) -> Any:
- """Execute a skill tool by name."""
- from services.skill_executor import get_skill_executor
-
- # Convert tool name back to skill tool format (underscores to hyphens)
- skill_tool_name = tool_name.replace('_', '-')
- logger.info(f"[ChatAgent] Executing skill tool: {skill_tool_name}")
-
- executor = get_skill_executor()
- if executor:
- try:
- result = await executor.execute_tool(skill_tool_name, tool_args)
- return result
- except Exception as e:
- logger.error(f"[ChatAgent] Skill tool execution failed: {skill_tool_name}", error=str(e))
- return {"error": str(e)}
- return {"error": "Skill executor not initialized"}
-
- # Build LangGraph agent
+ if all_tools:
+ # Use LangGraph for tool execution (like AI Agent)
+ logger.info(f"[ChatAgent] Using LangGraph with {len(all_tools)} tools")
+
+ # Create tool executor callback - same pattern as AI Agent
+ # Uses handlers/tools.py execute_tool() for actual execution
+ async def chat_tool_executor(tool_name: str, tool_args: Dict) -> Any:
+ """Execute a tool by name using handlers/tools.py (same as AI Agent)."""
+ from services.handlers.tools import execute_tool
+
+ logger.info(f"[ChatAgent] Executing tool: {tool_name}, args={tool_args}")
+
+ # Get tool node config (contains node_id, node_type, parameters)
+ config = tool_node_configs.get(tool_name, {})
+ tool_node_id = config.get('node_id')
+
+ # Broadcast executing status to tool node for glow effect
+ if tool_node_id and broadcaster:
+ await broadcaster.update_node_status(
+ tool_node_id,
+ "executing",
+ {"message": f"Executing {tool_name}"},
+ workflow_id=workflow_id
+ )
+
+ try:
+ # Execute via handlers/tools.py - same pattern as AI Agent
+ result = await execute_tool(tool_name, tool_args, config)
+ logger.info(f"[ChatAgent] Tool executed successfully: {tool_name}")
+
+ # Broadcast success to 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
+
+ except Exception as e:
+ logger.error(f"[ChatAgent] Tool execution failed: {tool_name}", error=str(e))
+ # Broadcast error to tool node
+ if tool_node_id and broadcaster:
+ await broadcaster.update_node_status(
+ tool_node_id,
+ "error",
+ {"message": f"{tool_name} failed", "error": str(e)},
+ workflow_id=workflow_id
+ )
+ return {"error": str(e)}
+
+ # Build LangGraph agent with all tools
agent_graph = build_agent_graph(
chat_model,
- tools=skill_tools,
- tool_executor=skill_tool_executor
+ tools=all_tools,
+ tool_executor=chat_tool_executor
)
# Create initial state
@@ -1708,13 +1747,22 @@ class AIService:
await self.database.add_conversation_message(session_id, 'ai', response_content)
logger.info(f"[ChatAgent] Saved exchange to session '{session_id}'")
+ # Determine agent type based on configuration
+ agent_type = "chat"
+ if skill_data and all_tools:
+ agent_type = "chat_with_skills_and_tools"
+ elif skill_data:
+ agent_type = "chat_with_skills"
+ elif all_tools:
+ agent_type = "chat_with_tools"
+
result = {
"response": response_content,
"thinking": thinking_content,
"thinking_enabled": thinking_config.enabled if thinking_config else False,
"model": model,
"provider": provider,
- "agent_type": "chat_with_skills" if skill_tools else "chat",
+ "agent_type": agent_type,
"iterations": iterations,
"finish_reason": "stop",
"timestamp": datetime.now().isoformat(),
@@ -1730,10 +1778,16 @@ class AIService:
"history_loaded": history_count
}
- if skill_names:
+ if skill_data:
result["skills"] = {
- "connected": skill_names,
- "tools_available": len(skill_tools) if skill_tools else 0
+ "connected": [s.get('skill_name', s.get('node_type', '')) for s in skill_data],
+ "count": len(skill_data)
+ }
+
+ if all_tools:
+ result["tools"] = {
+ "connected": [t.name for t in all_tools],
+ "count": len(all_tools)
}
log_execution_time(logger, "chat_agent", start_time, time.time())
@@ -1932,12 +1986,69 @@ class AIService:
# WhatsApp send schema (existing node used as tool)
if node_type == 'whatsappSend':
class WhatsAppSendSchema(BaseModel):
- """Schema for WhatsApp send tool arguments."""
- phone_number: str = Field(description="Phone number to send message to (e.g., +1234567890)")
- message: str = Field(description="Message text to send")
+ """Send WhatsApp messages to contacts or groups."""
+ recipient_type: str = Field(
+ default="phone",
+ description="Send to: 'phone' for individual or 'group' for group chat"
+ )
+ phone: Optional[str] = Field(
+ default=None,
+ description="Phone number without + prefix (e.g., 1234567890). Required for recipient_type='phone'"
+ )
+ group_id: Optional[str] = Field(
+ default=None,
+ description="Group JID (e.g., [email protected]). Required for recipient_type='group'"
+ )
+ message_type: str = Field(
+ default="text",
+ description="Message type: 'text', 'image', 'video', 'audio', 'document', 'sticker', 'location', 'contact'"
+ )
+ message: Optional[str] = Field(
+ default=None,
+ description="Text message content. Required for message_type='text'"
+ )
+ media_url: Optional[str] = Field(
+ default=None,
+ description="URL for media (image/video/audio/document/sticker)"
+ )
+ caption: Optional[str] = Field(
+ default=None,
+ description="Caption for media messages (image, video, document)"
+ )
+ latitude: Optional[float] = Field(default=None, description="Latitude for location message")
+ longitude: Optional[float] = Field(default=None, description="Longitude for location message")
+ location_name: Optional[str] = Field(default=None, description="Display name for location")
+ address: Optional[str] = Field(default=None, description="Address text for location")
+ contact_name: Optional[str] = Field(default=None, description="Contact card display name")
+ vcard: Optional[str] = Field(default=None, description="vCard 3.0 format string for contact")
return WhatsAppSendSchema
+ # WhatsApp chat history schema (existing node used as tool)
+ if node_type == 'whatsappChatHistory':
+ class WhatsAppChatHistorySchema(BaseModel):
+ """Retrieve WhatsApp chat history."""
+ chat_type: str = Field(
+ default="individual",
+ description="Chat type: 'individual' or 'group'"
+ )
+ phone: Optional[str] = Field(
+ default=None,
+ description="Phone number without + prefix. Required for chat_type='individual'"
+ )
+ group_id: Optional[str] = Field(
+ default=None,
+ description="Group JID. Required for chat_type='group'"
+ )
+ message_filter: str = Field(
+ default="all",
+ description="Filter: 'all' or 'text_only'"
+ )
+ limit: int = Field(default=50, description="Max messages to retrieve (1-500)")
+ offset: int = Field(default=0, description="Messages to skip for pagination")
+
+ return WhatsAppChatHistorySchema
+
# Android toolkit schema - dynamic based on connected services
# Follows LangChain dynamic tool binding pattern
if node_type == 'androidTool':
diff --git a/server/services/execution/executor.py b/server/services/execution/executor.py
index 6884569b..db45017c 100644
--- a/server/services/execution/executor.py
+++ b/server/services/execution/executor.py
@@ -896,13 +896,26 @@ class WorkflowExecutor:
# Find toolkit sub-nodes (nodes that connect TO a toolkit)
toolkit_node_ids = {n.get("id") for n in nodes if n.get("type") in TOOLKIT_NODE_TYPES}
+
+ # Find AI Agent nodes (both aiAgent and chatAgent have config handles)
+ ai_agent_node_ids = {n.get("id") for n in nodes if n.get("type") in ('aiAgent', 'chatAgent')}
+
subnode_ids: set = set()
for edge in edges:
source = edge.get("source")
target = edge.get("target")
+ target_handle = edge.get("targetHandle")
+
+ # Any node that connects TO a toolkit is a sub-node
if target in toolkit_node_ids and source:
subnode_ids.add(source)
+ # Nodes connected to AI Agent/Chat Agent config handles are sub-nodes
+ # These handles: input-memory, input-tools, input-skill
+ if target in ai_agent_node_ids and source and target_handle:
+ if target_handle in ('input-memory', 'input-tools', 'input-skill'):
+ subnode_ids.add(source)
+
# Filter out config nodes and sub-nodes from execution
excluded_ids = set()
for node in nodes:
diff --git a/server/services/execution/models.py b/server/services/execution/models.py
index 2fc2ad4d..82882483 100644
--- a/server/services/execution/models.py
+++ b/server/services/execution/models.py
@@ -323,14 +323,26 @@ class ExecutionContext:
# Find toolkit sub-nodes (nodes that connect TO a toolkit node)
# These should only execute when called via the toolkit, not as workflow nodes
toolkit_node_ids = {n.get("id") for n in (nodes or []) if n.get("type") in TOOLKIT_NODE_TYPES}
+
+ # Find AI Agent nodes (both aiAgent and chatAgent have config handles)
+ ai_agent_node_ids = {n.get("id") for n in (nodes or []) if n.get("type") in ('aiAgent', 'chatAgent')}
+
subnode_ids: set = set()
for edge in (edges or []):
source = edge.get("source")
target = edge.get("target")
+ target_handle = edge.get("targetHandle")
+
# Any node that connects TO a toolkit is a sub-node
if target in toolkit_node_ids and source:
subnode_ids.add(source)
+ # Nodes connected to AI Agent/Chat Agent config handles are sub-nodes
+ # These handles: input-memory, input-tools, input-skill
+ if target in ai_agent_node_ids and source and target_handle:
+ if target_handle in ('input-memory', 'input-tools', 'input-skill'):
+ subnode_ids.add(source)
+
# Initialize node executions for all nodes (excluding config nodes and sub-nodes)
for node in (nodes or []):
node_id = node.get("id")
diff --git a/server/services/handlers/__init__.py b/server/services/handlers/__init__.py
index 3a759d22..b5b986fa 100644
--- a/server/services/handlers/__init__.py
+++ b/server/services/handlers/__init__.py
@@ -4,11 +4,13 @@ This package contains all node execution handlers organized by category:
- ai.py: AI Agent, AI Chat Model, Simple Memory
- android.py: Android Device Setup, Android Services
- code.py: Python Executor, JavaScript Executor
+- document.py: HTTP Scraper, File Downloader, Document Parser, Text Chunker, Embedding Generator, Vector Store
- http.py: HTTP Request, Webhook Response
- tools.py: Tool execution handlers for AI Agent tool calling
- triggers.py: Generic trigger node handler
- utility.py: Maps, Text, Chat, Cron, Start
- whatsapp.py: WhatsApp Send, WhatsApp Connect
+- polyglot.py: Polyglot server integration (standalone, not auto-imported)
"""
# AI handlers
@@ -64,6 +66,16 @@ from .whatsapp import (
handle_whatsapp_chat_history,
)
+# Document processing handlers
+from .document import (
+ handle_http_scraper,
+ handle_file_downloader,
+ handle_document_parser,
+ handle_text_chunker,
+ handle_embedding_generator,
+ handle_vector_store,
+)
+
# Tool execution handlers (for AI Agent tool calling)
from .tools import (
execute_tool,
@@ -102,6 +114,13 @@ __all__ = [
'handle_whatsapp_send',
'handle_whatsapp_connect',
'handle_whatsapp_chat_history',
+ # Document processing
+ 'handle_http_scraper',
+ 'handle_file_downloader',
+ 'handle_document_parser',
+ 'handle_text_chunker',
+ 'handle_embedding_generator',
+ 'handle_vector_store',
# Tools
'execute_tool',
]
diff --git a/server/services/handlers/ai.py b/server/services/handlers/ai.py
index ae0388c4..46ad1f68 100644
--- a/server/services/handlers/ai.py
+++ b/server/services/handlers/ai.py
@@ -156,10 +156,11 @@ async def handle_chat_agent(
ai_service: "AIService",
database: "Database"
) -> Dict[str, Any]:
- """Handle Chat Agent node execution with memory and skill support.
+ """Handle Chat Agent node execution with skill-based tool calling.
- Chat Agent is a conversational AI agent without tool calling capabilities.
- It supports memory for conversation history and skills for extended capabilities.
+ Chat Agent supports:
+ - Skills (input-skill): Provide context/instructions via SKILL.md
+ - Tools (input-tool): Tool nodes (httpRequest, etc.) for LangGraph tool calling
Args:
node_id: The node ID
@@ -175,8 +176,8 @@ async def handle_chat_agent(
nodes = context.get('nodes')
edges = context.get('edges')
workflow_id = context.get('workflow_id')
- memory_data: Optional[Dict[str, Any]] = None
skill_data: List[Dict[str, Any]] = []
+ tool_data: List[Dict[str, Any]] = [] # Tools for LangGraph
input_data: Optional[Dict[str, Any]] = None
logger.info(f"[Chat Agent] Processing node {node_id}, workflow_id={workflow_id}")
@@ -196,39 +197,44 @@ async def handle_chat_agent(
if not source_node:
continue
- # Memory detection
- if target_handle == 'input-memory':
- if source_node.get('type') == 'simpleMemory':
- memory_params = await database.get_node_parameters(source_node_id) or {}
- memory_session_id = memory_params.get('sessionId', 'default')
- memory_type = memory_params.get('memoryType', 'buffer')
- window_size = int(memory_params.get('windowSize', 10)) if memory_type == 'window' else None
- memory_data = {
- 'session_id': memory_session_id,
- 'memory_type': memory_type,
- 'window_size': window_size
- }
- logger.debug(f"Chat Agent connected memory node, session={memory_session_id}")
-
# Skill detection - nodes connected to input-skill handle
- elif target_handle == 'input-skill':
+ if target_handle == 'input-skill':
skill_type = source_node.get('type')
skill_params = await database.get_node_parameters(source_node_id) or {}
skill_entry = {
'node_id': source_node_id,
'node_type': skill_type,
+ 'skill_name': skill_params.get('skillName', skill_type),
'parameters': skill_params,
'label': source_node.get('data', {}).get('label', skill_type)
}
skill_data.append(skill_entry)
- logger.debug(f"Chat Agent connected skill: {skill_type}")
+ logger.debug(f"[Chat Agent] Connected skill: {skill_type}")
+
+ # Tool detection - nodes connected to input-tools handle (for LangGraph)
+ elif target_handle == 'input-tools':
+ tool_type = source_node.get('type')
+ tool_params = await database.get_node_parameters(source_node_id) or {}
+ tool_entry = {
+ 'node_id': source_node_id,
+ 'node_type': tool_type,
+ 'parameters': tool_params,
+ 'label': source_node.get('data', {}).get('label', tool_type)
+ }
+ tool_data.append(tool_entry)
+ logger.info(f"[Chat Agent] Connected tool: {tool_type} ({tool_entry['label']})")
# Input data detection - nodes connected to input-main
elif target_handle == 'input-main' or target_handle is None:
source_output = context.get('outputs', {}).get(source_node_id)
if source_output:
input_data = source_output
- logger.debug(f"Chat Agent input from {source_node.get('type')}: {list(source_output.keys())}")
+ logger.debug(f"[Chat Agent] Input from {source_node.get('type')}: {list(source_output.keys())}")
+
+ # Log discovered skills and tools
+ logger.info(f"[Chat Agent] Discovered: {len(skill_data)} skills, {len(tool_data)} tools")
+ for td in tool_data:
+ logger.debug(f"[Chat Agent] Tool: type={td.get('node_type')}, label={td.get('label')}")
# Auto-use input data if prompt is empty (fallback for trigger nodes)
if not parameters.get('prompt') and input_data:
@@ -245,12 +251,13 @@ async def handle_chat_agent(
from services.status_broadcaster import get_status_broadcaster
broadcaster = get_status_broadcaster()
- # Execute as chat (no tool calling) with memory support
+ # Execute Chat Agent with skills and tools
return await ai_service.execute_chat_agent(
node_id,
parameters,
- memory_data=memory_data,
+ memory_data=None, # Memory removed - use skill-based conversation management
skill_data=skill_data if skill_data else None,
+ tool_data=tool_data if tool_data else None,
broadcaster=broadcaster,
workflow_id=workflow_id
)
diff --git a/server/services/handlers/document.py b/server/services/handlers/document.py
new file mode 100644
index 00000000..9b47c14d
--- /dev/null
+++ b/server/services/handlers/document.py
@@ -0,0 +1,598 @@
+"""Document processing handlers for MachinaOs workflow nodes.
+
+Each handler is an independent async function that can be executed by
+the Temporal worker system for distributed processing.
+
+Handlers:
+- handle_http_scraper: Scrape links from web pages with pagination
+- handle_file_downloader: Download files in parallel
+- handle_document_parser: Parse documents (PyPDF, Marker, Unstructured)
+- handle_text_chunker: Split text into chunks (LangChain)
+- handle_embedding_generator: Generate embeddings (HF, OpenAI, Ollama)
+- handle_vector_store: Store/query vectors (ChromaDB, Qdrant, Pinecone)
+"""
+
+import asyncio
+import json
+import time
+from datetime import datetime, timedelta
+from pathlib import Path
+from typing import Dict, Any
+from urllib.parse import urljoin, urlparse, unquote
+
+from core.logging import get_logger
+
+logger = get_logger(__name__)
+
+
+# =============================================================================
+# HTTP Scraper
+# =============================================================================
+
+async def handle_http_scraper(
+ node_id: str,
+ node_type: str,
+ parameters: Dict[str, Any],
+ context: Dict[str, Any]
+) -> Dict[str, Any]:
+ """Scrape links from web pages with date/page pagination support."""
+ import httpx
+ from bs4 import BeautifulSoup
+ start_time = time.time()
+
+ try:
+ url = parameters.get('url', '')
+ iteration_mode = parameters.get('iterationMode', 'single')
+ link_selector = parameters.get('linkSelector', 'a[href$=".pdf"]')
+ headers_str = parameters.get('headers', '{}')
+
+ if not url:
+ raise ValueError("URL is required")
+
+ headers = json.loads(headers_str) if headers_str else {}
+ items, errors = [], []
+ urls_to_fetch = []
+
+ if iteration_mode == 'date':
+ start_date = parameters.get('startDate', '')
+ end_date = parameters.get('endDate', '')
+ placeholder = parameters.get('datePlaceholder', '{date}')
+ if not start_date or not end_date:
+ raise ValueError("Start/end dates required for date mode")
+ start = datetime.strptime(start_date, "%Y-%m-%d")
+ end = datetime.strptime(end_date, "%Y-%m-%d")
+ current = start
+ while current <= end:
+ urls_to_fetch.append((
+ url.replace(placeholder, current.strftime("%Y-%m-%d")),
+ {'date': current.isoformat()}
+ ))
+ current += timedelta(days=1)
+ elif iteration_mode == 'page':
+ start_page = int(parameters.get('startPage', 1))
+ end_page = int(parameters.get('endPage', 10))
+ for page in range(start_page, end_page + 1):
+ urls_to_fetch.append((url.replace('{page}', str(page)), {'page': page}))
+ else:
+ urls_to_fetch.append((url, {}))
+
+ logger.info("[httpScraper] Starting", node_id=node_id, urls=len(urls_to_fetch))
+
+ async with httpx.AsyncClient(timeout=30, follow_redirects=True) as client:
+ for fetch_url, meta in urls_to_fetch:
+ try:
+ response = await client.get(fetch_url, headers=headers)
+ response.raise_for_status()
+ soup = BeautifulSoup(response.text, 'html.parser')
+ for el in soup.select(link_selector):
+ href = el.get('href', '')
+ if href:
+ items.append({
+ 'url': urljoin(fetch_url, href),
+ 'text': el.get_text(strip=True),
+ 'source_url': fetch_url,
+ **meta
+ })
+ except Exception as e:
+ errors.append(f"{fetch_url}: {str(e)}")
+
+ return {
+ "success": True,
+ "node_id": node_id,
+ "node_type": node_type,
+ "result": {"items": items, "item_count": len(items), "errors": errors},
+ "execution_time": time.time() - start_time,
+ "timestamp": datetime.now().isoformat()
+ }
+ except Exception as e:
+ logger.error("[httpScraper] Failed", node_id=node_id, error=str(e))
+ return {
+ "success": False, "node_id": node_id, "node_type": node_type,
+ "error": str(e), "execution_time": time.time() - start_time,
+ "timestamp": datetime.now().isoformat()
+ }
+
+
+# =============================================================================
+# File Downloader
+# =============================================================================
+
+async def handle_file_downloader(
+ node_id: str,
+ node_type: str,
+ parameters: Dict[str, Any],
+ context: Dict[str, Any]
+) -> Dict[str, Any]:
+ """Download files from URLs in parallel using semaphore for concurrency."""
+ import httpx
+ start_time = time.time()
+
+ try:
+ items = parameters.get('items', [])
+ output_dir = Path(parameters.get('outputDir', './data/downloads'))
+ max_workers = int(parameters.get('maxWorkers', 8))
+ skip_existing = parameters.get('skipExisting', True)
+ timeout = float(parameters.get('timeout', 60))
+
+ if not items:
+ return {
+ "success": True, "node_id": node_id, "node_type": node_type,
+ "result": {"downloaded": 0, "skipped": 0, "failed": 0, "files": []},
+ "execution_time": time.time() - start_time,
+ "timestamp": datetime.now().isoformat()
+ }
+
+ output_dir.mkdir(parents=True, exist_ok=True)
+ downloaded, skipped, failed = [], [], []
+ semaphore = asyncio.Semaphore(max_workers)
+
+ async def download_file(item):
+ async with semaphore:
+ url = item.get('url', '') if isinstance(item, dict) else str(item)
+ if not url:
+ return {'status': 'failed', 'error': 'Empty URL'}
+ filename = unquote(Path(urlparse(url).path).name or 'download')
+ file_path = output_dir / filename
+ if skip_existing and file_path.exists():
+ return {'status': 'skipped', 'path': str(file_path), 'url': url}
+ try:
+ async with httpx.AsyncClient(timeout=timeout, follow_redirects=True) as client:
+ response = await client.get(url)
+ response.raise_for_status()
+ file_path.write_bytes(response.content)
+ return {'status': 'downloaded', 'path': str(file_path), 'url': url,
+ 'size': len(response.content), 'filename': filename}
+ except Exception as e:
+ return {'status': 'failed', 'url': url, 'error': str(e)}
+
+ logger.info("[fileDownloader] Starting", node_id=node_id, items=len(items))
+ results = await asyncio.gather(*[download_file(i) for i in items], return_exceptions=True)
+
+ for r in results:
+ if isinstance(r, Exception):
+ failed.append({'error': str(r)})
+ elif r.get('status') == 'downloaded':
+ downloaded.append(r)
+ elif r.get('status') == 'skipped':
+ skipped.append(r)
+ else:
+ failed.append(r)
+
+ return {
+ "success": True, "node_id": node_id, "node_type": node_type,
+ "result": {"downloaded": len(downloaded), "skipped": len(skipped),
+ "failed": len(failed), "files": downloaded, "output_dir": str(output_dir)},
+ "execution_time": time.time() - start_time,
+ "timestamp": datetime.now().isoformat()
+ }
+ except Exception as e:
+ logger.error("[fileDownloader] Failed", node_id=node_id, error=str(e))
+ return {
+ "success": False, "node_id": node_id, "node_type": node_type,
+ "error": str(e), "execution_time": time.time() - start_time,
+ "timestamp": datetime.now().isoformat()
+ }
+
+
+# =============================================================================
+# Document Parser
+# =============================================================================
+
+def _parse_file_sync(path: Path, parser: str) -> str:
+ """Synchronous file parsing - runs in thread pool."""
+ if parser == 'pypdf':
+ from pypdf import PdfReader
+ return "\n\n".join(p.extract_text() or '' for p in PdfReader(str(path)).pages)
+ elif parser == 'marker':
+ from marker.converters.pdf import PdfConverter
+ from marker.models import create_model_dict
+ converter = PdfConverter(artifact_dict=create_model_dict())
+ result = converter(str(path))
+ return result.markdown if hasattr(result, 'markdown') else str(result)
+ elif parser == 'unstructured':
+ from unstructured.partition.auto import partition
+ return "\n\n".join(str(el) for el in partition(str(path)))
+ elif parser == 'beautifulsoup':
+ from bs4 import BeautifulSoup
+ soup = BeautifulSoup(path.read_text(errors='ignore'), 'html.parser')
+ for s in soup(["script", "style"]):
+ s.decompose()
+ return soup.get_text(separator='\n')
+ raise ValueError(f"Unknown parser: {parser}")
+
+
+async def handle_document_parser(
+ node_id: str,
+ node_type: str,
+ parameters: Dict[str, Any],
+ context: Dict[str, Any]
+) -> Dict[str, Any]:
+ """Parse documents to text using configurable parsers."""
+ start_time = time.time()
+
+ try:
+ files = parameters.get('files', [])
+ input_dir = parameters.get('inputDir', '')
+ parser = parameters.get('parser', 'pypdf')
+ file_pattern = parameters.get('filePattern', '*.pdf')
+
+ paths = []
+ for f in files:
+ p = f.get('path', '') if isinstance(f, dict) else str(f)
+ if p:
+ paths.append(Path(p))
+ if input_dir and Path(input_dir).exists():
+ paths.extend(Path(input_dir).glob(file_pattern))
+
+ if not paths:
+ return {
+ "success": True, "node_id": node_id, "node_type": node_type,
+ "result": {"documents": [], "parsed_count": 0, "failed": []},
+ "execution_time": time.time() - start_time,
+ "timestamp": datetime.now().isoformat()
+ }
+
+ logger.info("[documentParser] Starting", node_id=node_id, files=len(paths), parser=parser)
+ documents, failed = [], []
+
+ for path in paths:
+ try:
+ content = await asyncio.to_thread(_parse_file_sync, path, parser)
+ documents.append({'source': str(path), 'filename': path.name,
+ 'content': content, 'length': len(content), 'parser': parser})
+ except Exception as e:
+ failed.append({'file': str(path), 'error': str(e)})
+
+ return {
+ "success": True, "node_id": node_id, "node_type": node_type,
+ "result": {"documents": documents, "parsed_count": len(documents), "failed": failed},
+ "execution_time": time.time() - start_time,
+ "timestamp": datetime.now().isoformat()
+ }
+ except Exception as e:
+ logger.error("[documentParser] Failed", node_id=node_id, error=str(e))
+ return {
+ "success": False, "node_id": node_id, "node_type": node_type,
+ "error": str(e), "execution_time": time.time() - start_time,
+ "timestamp": datetime.now().isoformat()
+ }
+
+
+# =============================================================================
+# Text Chunker
+# =============================================================================
+
+async def handle_text_chunker(
+ node_id: str,
+ node_type: str,
+ parameters: Dict[str, Any],
+ context: Dict[str, Any]
+) -> Dict[str, Any]:
+ """Split text into overlapping chunks using LangChain splitters."""
+ start_time = time.time()
+
+ try:
+ documents = parameters.get('documents', [])
+ chunk_size = int(parameters.get('chunkSize', 1024))
+ chunk_overlap = int(parameters.get('chunkOverlap', 200))
+ strategy = parameters.get('strategy', 'recursive')
+
+ if not documents:
+ return {
+ "success": True, "node_id": node_id, "node_type": node_type,
+ "result": {"chunks": [], "chunk_count": 0},
+ "execution_time": time.time() - start_time,
+ "timestamp": datetime.now().isoformat()
+ }
+
+ from langchain_text_splitters import RecursiveCharacterTextSplitter, MarkdownTextSplitter
+
+ if strategy == 'markdown':
+ splitter = MarkdownTextSplitter(chunk_size=chunk_size, chunk_overlap=chunk_overlap)
+ else:
+ splitter = RecursiveCharacterTextSplitter(chunk_size=chunk_size, chunk_overlap=chunk_overlap)
+
+ logger.info("[textChunker] Starting", node_id=node_id, docs=len(documents))
+ chunks = []
+
+ for doc in documents:
+ content = doc.get('content', '') if isinstance(doc, dict) else str(doc)
+ source = doc.get('source', 'input') if isinstance(doc, dict) else 'input'
+ if not content:
+ continue
+ for i, chunk_text in enumerate(splitter.split_text(content)):
+ chunks.append({'source': source, 'chunk_index': i,
+ 'content': chunk_text, 'length': len(chunk_text)})
+
+ return {
+ "success": True, "node_id": node_id, "node_type": node_type,
+ "result": {"chunks": chunks, "chunk_count": len(chunks)},
+ "execution_time": time.time() - start_time,
+ "timestamp": datetime.now().isoformat()
+ }
+ except Exception as e:
+ logger.error("[textChunker] Failed", node_id=node_id, error=str(e))
+ return {
+ "success": False, "node_id": node_id, "node_type": node_type,
+ "error": str(e), "execution_time": time.time() - start_time,
+ "timestamp": datetime.now().isoformat()
+ }
+
+
+# =============================================================================
+# Embedding Generator
+# =============================================================================
+
+async def handle_embedding_generator(
+ node_id: str,
+ node_type: str,
+ parameters: Dict[str, Any],
+ context: Dict[str, Any]
+) -> Dict[str, Any]:
+ """Generate embeddings using HuggingFace, OpenAI, or Ollama."""
+ start_time = time.time()
+
+ try:
+ chunks = parameters.get('chunks', [])
+ provider = parameters.get('provider', 'huggingface')
+ model = parameters.get('model', 'BAAI/bge-small-en-v1.5')
+ api_key = parameters.get('apiKey', '')
+
+ if not chunks:
+ return {
+ "success": True, "node_id": node_id, "node_type": node_type,
+ "result": {"embeddings": [], "embedding_count": 0, "dimensions": 0, "chunks": []},
+ "execution_time": time.time() - start_time,
+ "timestamp": datetime.now().isoformat()
+ }
+
+ texts = [c.get('content', '') if isinstance(c, dict) else str(c) for c in chunks]
+ logger.info("[embeddingGenerator] Starting", node_id=node_id, texts=len(texts), provider=provider)
+
+ if provider == 'huggingface':
+ from langchain_huggingface import HuggingFaceEmbeddings
+ embedder = HuggingFaceEmbeddings(model_name=model)
+ elif provider == 'openai':
+ from langchain_openai import OpenAIEmbeddings
+ embedder = OpenAIEmbeddings(model=model, api_key=api_key)
+ elif provider == 'ollama':
+ from langchain_ollama import OllamaEmbeddings
+ embedder = OllamaEmbeddings(model=model)
+ else:
+ raise ValueError(f"Unknown provider: {provider}")
+
+ embeddings = await asyncio.to_thread(embedder.embed_documents, texts)
+ dimensions = len(embeddings[0]) if embeddings else 0
+
+ return {
+ "success": True, "node_id": node_id, "node_type": node_type,
+ "result": {"embeddings": embeddings, "embedding_count": len(embeddings),
+ "dimensions": dimensions, "chunks": chunks, "provider": provider, "model": model},
+ "execution_time": time.time() - start_time,
+ "timestamp": datetime.now().isoformat()
+ }
+ except Exception as e:
+ logger.error("[embeddingGenerator] Failed", node_id=node_id, error=str(e))
+ return {
+ "success": False, "node_id": node_id, "node_type": node_type,
+ "error": str(e), "execution_time": time.time() - start_time,
+ "timestamp": datetime.now().isoformat()
+ }
+
+
+# =============================================================================
+# Vector Store
+# =============================================================================
+
+async def handle_vector_store(
+ node_id: str,
+ node_type: str,
+ parameters: Dict[str, Any],
+ context: Dict[str, Any]
+) -> Dict[str, Any]:
+ """Store or query vectors using ChromaDB, Qdrant, or Pinecone."""
+ start_time = time.time()
+
+ try:
+ operation = parameters.get('operation', 'store')
+ backend = parameters.get('backend', 'chroma')
+ collection_name = parameters.get('collectionName', 'documents')
+
+ logger.info("[vectorStore] Starting", node_id=node_id, op=operation, backend=backend)
+
+ if backend == 'chroma':
+ result = await _chroma_op(operation, parameters, collection_name)
+ elif backend == 'qdrant':
+ result = await _qdrant_op(operation, parameters, collection_name)
+ elif backend == 'pinecone':
+ result = await _pinecone_op(operation, parameters, collection_name)
+ else:
+ raise ValueError(f"Unknown backend: {backend}")
+
+ result['backend'] = backend
+ result['collection_name'] = collection_name
+
+ return {
+ "success": True, "node_id": node_id, "node_type": node_type,
+ "result": result, "execution_time": time.time() - start_time,
+ "timestamp": datetime.now().isoformat()
+ }
+ except Exception as e:
+ logger.error("[vectorStore] Failed", node_id=node_id, error=str(e))
+ return {
+ "success": False, "node_id": node_id, "node_type": node_type,
+ "error": str(e), "execution_time": time.time() - start_time,
+ "timestamp": datetime.now().isoformat()
+ }
+
+
+async def _chroma_op(operation: str, params: Dict, collection: str) -> Dict:
+ """ChromaDB operations."""
+ import chromadb
+ import uuid
+
+ persist_dir = params.get('persistDir', './data/vectors')
+ client = chromadb.PersistentClient(path=persist_dir)
+ coll = client.get_or_create_collection(name=collection)
+
+ if operation == 'store':
+ embeddings = params.get('embeddings', [])
+ chunks = params.get('chunks', [])
+ if not embeddings:
+ return {"stored_count": 0, "collection_count": coll.count()}
+ ids = [str(uuid.uuid4()) for _ in embeddings]
+ docs = [c.get('content', '') if isinstance(c, dict) else str(c) for c in chunks]
+ while len(docs) < len(embeddings):
+ docs.append('')
+ metas = [{'source': c.get('source', 'unknown'), 'chunk_index': c.get('chunk_index', i)}
+ if isinstance(c, dict) else {'source': 'input', 'chunk_index': i}
+ for i, c in enumerate(chunks)]
+ while len(metas) < len(embeddings):
+ metas.append({'source': 'unknown', 'chunk_index': len(metas)})
+ await asyncio.to_thread(coll.add, ids=ids, embeddings=embeddings, documents=docs, metadatas=metas)
+ return {"stored_count": len(embeddings), "collection_count": coll.count()}
+
+ elif operation == 'query':
+ query_emb = params.get('queryEmbedding', [])
+ top_k = int(params.get('topK', 5))
+ if not query_emb:
+ return {"matches": []}
+ results = coll.query(query_embeddings=[query_emb], n_results=top_k)
+ matches = []
+ if results['ids'] and results['ids'][0]:
+ for i in range(len(results['ids'][0])):
+ matches.append({
+ 'id': results['ids'][0][i],
+ 'document': results['documents'][0][i] if results['documents'] else '',
+ 'metadata': results['metadatas'][0][i] if results['metadatas'] else {},
+ 'distance': results['distances'][0][i] if results.get('distances') else None
+ })
+ return {"matches": matches}
+
+ elif operation == 'delete':
+ ids = params.get('ids', [])
+ if ids:
+ await asyncio.to_thread(coll.delete, ids=ids)
+ return {"deleted": True, "count": len(ids)}
+
+ return {}
+
+
+async def _qdrant_op(operation: str, params: Dict, collection: str) -> Dict:
+ """Qdrant operations."""
+ from qdrant_client import QdrantClient
+ from qdrant_client.models import VectorParams, Distance, PointStruct
+ import uuid
+
+ url = params.get('qdrantUrl', 'http://localhost:6333')
+ client = QdrantClient(url=url)
+
+ if operation == 'store':
+ embeddings = params.get('embeddings', [])
+ chunks = params.get('chunks', [])
+ if not embeddings:
+ return {"stored_count": 0}
+ vec_size = len(embeddings[0])
+ colls = client.get_collections().collections
+ if collection not in [c.name for c in colls]:
+ client.create_collection(collection, vectors_config=VectorParams(size=vec_size, distance=Distance.COSINE))
+ points = []
+ for i, emb in enumerate(embeddings):
+ payload = {}
+ if i < len(chunks):
+ c = chunks[i]
+ if isinstance(c, dict):
+ payload = {'content': c.get('content', ''), 'source': c.get('source', 'unknown'),
+ 'chunk_index': c.get('chunk_index', i)}
+ else:
+ payload = {'content': str(c), 'source': 'input', 'chunk_index': i}
+ points.append(PointStruct(id=str(uuid.uuid4()), vector=emb, payload=payload))
+ await asyncio.to_thread(client.upsert, collection_name=collection, points=points)
+ return {"stored_count": len(embeddings)}
+
+ elif operation == 'query':
+ query_emb = params.get('queryEmbedding', [])
+ top_k = int(params.get('topK', 5))
+ if not query_emb:
+ return {"matches": []}
+ results = await asyncio.to_thread(client.search, collection_name=collection,
+ query_vector=query_emb, limit=top_k)
+ return {"matches": [{'id': str(r.id), 'document': r.payload.get('content', ''),
+ 'metadata': r.payload, 'score': r.score} for r in results]}
+
+ elif operation == 'delete':
+ ids = params.get('ids', [])
+ if ids:
+ await asyncio.to_thread(client.delete, collection_name=collection, points_selector=ids)
+ return {"deleted": True, "count": len(ids)}
+
+ return {}
+
+
+async def _pinecone_op(operation: str, params: Dict, collection: str) -> Dict:
+ """Pinecone operations."""
+ from pinecone import Pinecone
+ import uuid
+
+ api_key = params.get('pineconeApiKey', '')
+ if not api_key:
+ raise ValueError("Pinecone API key required")
+
+ pc = Pinecone(api_key=api_key)
+ index = pc.Index(collection)
+
+ if operation == 'store':
+ embeddings = params.get('embeddings', [])
+ chunks = params.get('chunks', [])
+ if not embeddings:
+ return {"stored_count": 0}
+ vectors = []
+ for i, emb in enumerate(embeddings):
+ meta = {}
+ if i < len(chunks):
+ c = chunks[i]
+ if isinstance(c, dict):
+ meta = {'content': c.get('content', ''), 'source': c.get('source', 'unknown'),
+ 'chunk_index': c.get('chunk_index', i)}
+ else:
+ meta = {'content': str(c), 'source': 'input', 'chunk_index': i}
+ vectors.append({'id': str(uuid.uuid4()), 'values': emb, 'metadata': meta})
+ await asyncio.to_thread(index.upsert, vectors=vectors)
+ return {"stored_count": len(embeddings)}
+
+ elif operation == 'query':
+ query_emb = params.get('queryEmbedding', [])
+ top_k = int(params.get('topK', 5))
+ if not query_emb:
+ return {"matches": []}
+ results = await asyncio.to_thread(index.query, vector=query_emb, top_k=top_k, include_metadata=True)
+ return {"matches": [{'id': m.id, 'document': m.metadata.get('content', '') if m.metadata else '',
+ 'metadata': m.metadata or {}, 'score': m.score} for m in results.matches]}
+
+ elif operation == 'delete':
+ ids = params.get('ids', [])
+ if ids:
+ await asyncio.to_thread(index.delete, ids=ids)
+ return {"deleted": True, "count": len(ids)}
+
+ return {}
diff --git a/server/services/handlers/polyglot.py b/server/services/handlers/polyglot.py
new file mode 100644
index 00000000..5a216da3
--- /dev/null
+++ b/server/services/handlers/polyglot.py
@@ -0,0 +1,105 @@
+"""Polyglot node handlers - execute nodes via polyglot-server plugin registry.
+
+This module provides handlers for routing node execution to polyglot-server.
+It is designed to be optionally integrated without modifying the existing
+workflow execution flow.
+
+Usage:
+ # Optional integration - only if polyglot-server is running
+ from services.handlers.polyglot import handle_polyglot_node, POLYGLOT_NODE_TYPES
+"""
+
+import time
+from datetime import datetime
+from typing import Dict, Any
+
+from core.logging import get_logger
+
+logger = get_logger(__name__)
+
+
+async def handle_polyglot_node(
+ node_id: str,
+ node_type: str,
+ parameters: Dict[str, Any],
+ context: Dict[str, Any],
+ polyglot_client, # Injected via functools.partial
+) -> Dict[str, Any]:
+ """Execute a workflow node via polyglot-server plugin registry.
+
+ Args:
+ node_id: The workflow node ID
+ node_type: The node type (e.g., 'discordNode', 'telegramNode')
+ parameters: Resolved node parameters
+ context: Execution context
+ polyglot_client: PolyglotClient instance
+
+ Returns:
+ Execution result dict
+ """
+ start_time = time.time()
+
+ # Extract plugin name from node_type
+ plugin_name = node_type.replace("Node", "").lower()
+ action = parameters.get("action", "default")
+ params = {k: v for k, v in parameters.items() if k != "action"}
+
+ logger.info(
+ "[Polyglot] Executing plugin",
+ node_id=node_id,
+ plugin=plugin_name,
+ action=action,
+ )
+
+ try:
+ result = await polyglot_client.execute(plugin_name, action, params)
+ execution_time = time.time() - start_time
+
+ if result.get("success", False):
+ return {
+ "success": True,
+ "node_id": node_id,
+ "node_type": node_type,
+ "result": result.get("result", {}),
+ "timestamp": datetime.now().isoformat(),
+ "execution_time": execution_time,
+ }
+ else:
+ return {
+ "success": False,
+ "node_id": node_id,
+ "node_type": node_type,
+ "error": result.get("error", "Unknown error"),
+ "timestamp": datetime.now().isoformat(),
+ "execution_time": execution_time,
+ }
+
+ except Exception as e:
+ return {
+ "success": False,
+ "node_id": node_id,
+ "node_type": node_type,
+ "error": str(e),
+ "timestamp": datetime.now().isoformat(),
+ "execution_time": time.time() - start_time,
+ }
+
+
+# Node types that can be routed to polyglot-server (for future use)
+POLYGLOT_NODE_TYPES = frozenset([
+ "discordNode",
+ "telegramNode",
+ "slackNode",
+ "signalNode",
+ "notionNode",
+ "todoistNode",
+ "gmailNode",
+ "outlookNode",
+ "twitterNode",
+ "instagramNode",
+ "linkedinNode",
+ "dalleNode",
+ "stableDiffusionNode",
+ "githubNode",
+ "gitlabNode",
+])
diff --git a/server/services/handlers/tools.py b/server/services/handlers/tools.py
index a6216243..ef356a07 100644
--- a/server/services/handlers/tools.py
+++ b/server/services/handlers/tools.py
@@ -56,6 +56,10 @@ async def execute_tool(tool_name: str, tool_args: Dict[str, Any],
if node_type == 'whatsappSend':
return await _execute_whatsapp_send(tool_args, config.get('parameters', {}))
+ # WhatsApp chat history (existing node used as tool)
+ if node_type == 'whatsappChatHistory':
+ return await _execute_whatsapp_chat_history(tool_args, config.get('parameters', {}))
+
# Android toolkit - routes to connected service nodes
if node_type == 'androidTool':
return await _execute_android_toolkit(tool_args, config)
@@ -409,52 +413,157 @@ async def _execute_web_search(args: Dict[str, Any],
async def _execute_whatsapp_send(args: Dict[str, Any],
node_params: Dict[str, Any]) -> Dict[str, Any]:
- """Send WhatsApp message.
+ """Send WhatsApp message with full message type support.
+
+ Supports all message types: text, image, video, audio, document, sticker, location, contact
+ Recipients: phone number or group_id
+ Media sources: URL
Args:
- args: Dict with 'phone_number' and 'message'
- node_params: Node parameters containing defaultPhone, etc.
+ args: LLM-provided arguments matching WhatsAppSendSchema
+ node_params: Node parameters (used as fallback)
Returns:
- Dict with success status, phone, message_sent
+ Dict with success status and message details
"""
- import httpx
+ from services.handlers.whatsapp import handle_whatsapp_send
+
+ # Map LLM args to node parameter format (camelCase for handler)
+ parameters = {
+ 'recipientType': args.get('recipient_type', 'phone'),
+ 'phone': args.get('phone', ''),
+ 'group_id': args.get('group_id', ''),
+ 'messageType': args.get('message_type', 'text'),
+ 'message': args.get('message', ''),
+ 'mediaSource': 'url' if args.get('media_url') else 'none',
+ 'mediaUrl': args.get('media_url', ''),
+ 'caption': args.get('caption', ''),
+ 'latitude': args.get('latitude'),
+ 'longitude': args.get('longitude'),
+ 'locationName': args.get('location_name', ''),
+ 'address': args.get('address', ''),
+ 'contactName': args.get('contact_name', ''),
+ 'vcard': args.get('vcard', ''),
+ }
+
+ # Validate required fields based on message type
+ recipient_type = parameters['recipientType']
+ message_type = parameters['messageType']
+
+ if recipient_type == 'phone' and not parameters['phone']:
+ return {"error": "Phone number is required for recipient_type='phone'"}
+ if recipient_type == 'group' and not parameters['group_id']:
+ return {"error": "Group ID is required for recipient_type='group'"}
+ if message_type == 'text' and not parameters['message']:
+ return {"error": "Message content is required for message_type='text'"}
+ if message_type in ('image', 'video', 'audio', 'document', 'sticker') and not parameters['mediaUrl']:
+ return {"error": f"media_url is required for message_type='{message_type}'"}
+ if message_type == 'location' and (parameters['latitude'] is None or parameters['longitude'] is None):
+ return {"error": "latitude and longitude are required for message_type='location'"}
+ if message_type == 'contact' and not parameters['vcard']:
+ return {"error": "vcard is required for message_type='contact'"}
+
+ recipient = parameters['phone'] if recipient_type == 'phone' else parameters['group_id']
+ logger.info(f"[WhatsApp Tool] Sending {message_type} to {recipient[:15]}...")
+
+ try:
+ result = await handle_whatsapp_send(
+ node_id="tool_whatsapp_send",
+ node_type="whatsappSend",
+ parameters=parameters,
+ context={}
+ )
+
+ if result.get('success'):
+ return {
+ "success": True,
+ "recipient": recipient,
+ "recipient_type": recipient_type,
+ "message_type": message_type,
+ "details": result.get('result', {})
+ }
+ else:
+ return {"error": result.get('error', 'Unknown error')}
- phone = args.get('phone_number') or node_params.get('phoneNumber', '') or node_params.get('to', '')
- message = args.get('message') or node_params.get('message', '')
+ except Exception as e:
+ logger.error(f"[WhatsApp Tool] Error: {e}")
+ return {"error": f"WhatsApp send failed: {str(e)}"}
- if not phone:
- return {"error": "No phone number provided"}
- if not message:
- return {"error": "No message provided"}
- # Clean phone number
- phone = phone.replace('+', '').replace(' ', '').replace('-', '')
- if not phone.endswith('@s.whatsapp.net'):
- phone = f"{phone}@s.whatsapp.net"
+async def _execute_whatsapp_chat_history(args: Dict[str, Any],
+ node_params: Dict[str, Any]) -> Dict[str, Any]:
+ """Retrieve WhatsApp chat history.
- logger.info(f"[WhatsApp] Sending message to {phone[:10]}...")
+ Args:
+ args: LLM-provided arguments matching WhatsAppChatHistorySchema
+ node_params: Node parameters (used as fallback)
+
+ Returns:
+ Dict with messages array and metadata
+ """
+ from services.handlers.whatsapp import handle_whatsapp_chat_history
+
+ # Map LLM args to node parameter format (camelCase for handler)
+ parameters = {
+ 'chatType': args.get('chat_type', 'individual'),
+ 'phone': args.get('phone', ''),
+ 'group_id': args.get('group_id', ''),
+ 'messageFilter': args.get('message_filter', 'all'),
+ 'limit': args.get('limit', 50),
+ 'offset': args.get('offset', 0),
+ 'resultMode': 'multiple', # Always return multiple messages for tool use
+ }
+
+ # Validate required fields based on chat type
+ chat_type = parameters['chatType']
+
+ if chat_type == 'individual' and not parameters['phone']:
+ return {"error": "Phone number is required for chat_type='individual'"}
+ if chat_type == 'group' and not parameters['group_id']:
+ return {"error": "Group ID is required for chat_type='group'"}
+
+ identifier = parameters['phone'] if chat_type == 'individual' else parameters['group_id']
+ logger.info(f"[WhatsApp Tool] Getting chat history for {identifier[:15]}...")
try:
- async with httpx.AsyncClient(timeout=30.0) as client:
- response = await client.post(
- "http://localhost:5000/send",
- json={"to": phone, "message": message}
- )
+ result = await handle_whatsapp_chat_history(
+ node_id="tool_whatsapp_history",
+ node_type="whatsappChatHistory",
+ parameters=parameters,
+ context={}
+ )
- if response.status_code == 200:
- logger.info(f"[WhatsApp] Message sent successfully")
- return {
- "success": True,
- "phone": phone,
- "message_sent": message[:100] + "..." if len(message) > 100 else message
- }
- else:
- return {"error": f"Failed to send: {response.text}"}
+ if result.get('success'):
+ messages = result.get('result', {}).get('messages', [])
+ total = result.get('result', {}).get('total', 0)
+ has_more = result.get('result', {}).get('has_more', False)
+
+ # Format messages for LLM consumption
+ formatted_messages = []
+ for msg in messages:
+ formatted_messages.append({
+ "sender": msg.get('sender', ''),
+ "text": msg.get('text', ''),
+ "timestamp": msg.get('timestamp', ''),
+ "type": msg.get('type', 'text'),
+ "is_from_me": msg.get('is_from_me', False),
+ })
+
+ return {
+ "success": True,
+ "chat_type": chat_type,
+ "identifier": identifier,
+ "messages": formatted_messages,
+ "total": total,
+ "has_more": has_more,
+ "count": len(formatted_messages)
+ }
+ else:
+ return {"error": result.get('error', 'Unknown error')}
except Exception as e:
- logger.error(f"[WhatsApp] Error: {e}")
- return {"error": f"WhatsApp send failed: {str(e)}"}
+ logger.error(f"[WhatsApp Tool] Error: {e}")
+ return {"error": f"WhatsApp chat history failed: {str(e)}"}
async def _execute_android_toolkit(args: Dict[str, Any],
diff --git a/server/services/node_executor.py b/server/services/node_executor.py
index 06d93ec1..6e39c856 100644
--- a/server/services/node_executor.py
+++ b/server/services/node_executor.py
@@ -32,6 +32,8 @@ from services.handlers import (
handle_chat_send, handle_chat_history,
handle_start, handle_cron_scheduler, handle_timer, handle_console,
handle_whatsapp_send, handle_whatsapp_connect, handle_whatsapp_chat_history,
+ handle_http_scraper, handle_file_downloader, handle_document_parser,
+ handle_text_chunker, handle_embedding_generator, handle_vector_store,
)
if TYPE_CHECKING:
@@ -124,6 +126,13 @@ class NodeExecutor:
'httpRequest': handle_http_request,
# Android setup
'androidDeviceSetup': partial(handle_android_device_setup, settings=self.settings),
+ # Document processing
+ 'httpScraper': handle_http_scraper,
+ 'fileDownloader': handle_file_downloader,
+ 'documentParser': handle_document_parser,
+ 'textChunker': handle_text_chunker,
+ 'embeddingGenerator': handle_embedding_generator,
+ 'vectorStore': handle_vector_store,
# Note: 'console' handled in _dispatch with connected_outputs
}
diff --git a/server/services/polyglot_client.py b/server/services/polyglot_client.py
new file mode 100644
index 00000000..225deb79
--- /dev/null
+++ b/server/services/polyglot_client.py
@@ -0,0 +1,169 @@
+"""Polyglot Server Client - HTTP client for polyglot-server plugin registry."""
+
+import aiohttp
+from typing import Dict, Any, List, Optional
+
+from core.logging import get_logger
+
+logger = get_logger(__name__)
+
+
+class PolyglotClient:
+ """Client for polyglot-server plugin registry.
+
+ Provides async HTTP methods to interact with the polyglot-server
+ for plugin discovery, schema retrieval, and execution.
+ """
+
+ def __init__(self, base_url: str = "http://localhost:8080"):
+ self.base_url = base_url.rstrip("/")
+ self._session: Optional[aiohttp.ClientSession] = None
+
+ async def initialize(self) -> None:
+ """Initialize the HTTP session."""
+ if self._session is None or self._session.closed:
+ timeout = aiohttp.ClientTimeout(total=30)
+ self._session = aiohttp.ClientSession(timeout=timeout)
+ logger.info("PolyglotClient initialized", base_url=self.base_url)
+
+ async def close(self) -> None:
+ """Close the HTTP session."""
+ if self._session and not self._session.closed:
+ await self._session.close()
+ self._session = None
+ logger.info("PolyglotClient closed")
+
+ async def _ensure_session(self) -> aiohttp.ClientSession:
+ """Ensure session is initialized and return it."""
+ if self._session is None or self._session.closed:
+ await self.initialize()
+ return self._session
+
+ async def health_check(self) -> Dict[str, Any]:
+ """Check polyglot-server health status."""
+ session = await self._ensure_session()
+ try:
+ async with session.get(f"{self.base_url}/api/health") as resp:
+ if resp.status == 200:
+ return await resp.json()
+ return {"status": "error", "code": resp.status}
+ except aiohttp.ClientError as e:
+ logger.warning("Polyglot health check failed", error=str(e))
+ return {"status": "unreachable", "error": str(e)}
+
+ async def list_plugins(self) -> List[Dict[str, Any]]:
+ """List all available plugins from polyglot-server."""
+ session = await self._ensure_session()
+ try:
+ async with session.get(f"{self.base_url}/api/plugins") as resp:
+ if resp.status == 200:
+ data = await resp.json()
+ return data.get("plugins", [])
+ logger.warning("Failed to list plugins", status=resp.status)
+ return []
+ except aiohttp.ClientError as e:
+ logger.error("Failed to list plugins", error=str(e))
+ return []
+
+ async def get_plugin(self, name: str) -> Optional[Dict[str, Any]]:
+ """Get details for a specific plugin."""
+ session = await self._ensure_session()
+ try:
+ async with session.get(f"{self.base_url}/api/plugins/{name}") as resp:
+ if resp.status == 200:
+ return await resp.json()
+ return None
+ except aiohttp.ClientError as e:
+ logger.error("Failed to get plugin", plugin=name, error=str(e))
+ return None
+
+ async def get_schema(self, plugin_name: str) -> Optional[Dict[str, Any]]:
+ """Get plugin input/output schema for workflow node integration."""
+ session = await self._ensure_session()
+ try:
+ async with session.get(
+ f"{self.base_url}/api/plugins/{plugin_name}/schema"
+ ) as resp:
+ if resp.status == 200:
+ return await resp.json()
+ return None
+ except aiohttp.ClientError as e:
+ logger.error("Failed to get schema", plugin=plugin_name, error=str(e))
+ return None
+
+ async def execute(
+ self,
+ plugin_name: str,
+ action: str = "default",
+ params: Optional[Dict[str, Any]] = None,
+ ) -> Dict[str, Any]:
+ """Execute a plugin action.
+
+ Args:
+ plugin_name: Name of the plugin to execute
+ action: Action to perform (default: "default")
+ params: Optional parameters for the action
+
+ Returns:
+ Execution result with success status and result/error
+ """
+ session = await self._ensure_session()
+ payload = {
+ "action": action,
+ "params": params or {},
+ }
+
+ try:
+ async with session.post(
+ f"{self.base_url}/api/plugins/{plugin_name}/execute",
+ json=payload,
+ ) as resp:
+ result = await resp.json()
+ if resp.status == 200:
+ return result
+ return {
+ "success": False,
+ "error": result.get("error", f"HTTP {resp.status}"),
+ }
+ except aiohttp.ClientError as e:
+ logger.error(
+ "Plugin execution failed",
+ plugin=plugin_name,
+ action=action,
+ error=str(e),
+ )
+ return {"success": False, "error": str(e)}
+
+ async def list_categories(self) -> List[str]:
+ """List available plugin categories."""
+ session = await self._ensure_session()
+ try:
+ async with session.get(f"{self.base_url}/api/categories") as resp:
+ if resp.status == 200:
+ data = await resp.json()
+ return data.get("categories", [])
+ return []
+ except aiohttp.ClientError as e:
+ logger.error("Failed to list categories", error=str(e))
+ return []
+
+
+# Global client instance for simple usage
+_client: Optional[PolyglotClient] = None
+
+
+async def get_polyglot_client(base_url: str = "http://localhost:8080") -> PolyglotClient:
+ """Get or create the global polyglot client instance."""
+ global _client
+ if _client is None:
+ _client = PolyglotClient(base_url)
+ await _client.initialize()
+ return _client
+
+
+async def close_polyglot_client() -> None:
+ """Close the global polyglot client instance."""
+ global _client
+ if _client is not None:
+ await _client.close()
+ _client = None
diff --git a/server/services/skill_executor.py b/server/services/skill_executor.py
index dbd6a696..322281ae 100644
--- a/server/services/skill_executor.py
+++ b/server/services/skill_executor.py
@@ -4,6 +4,7 @@ Maps skill tool names to existing node handlers, enabling Chat Agent
to use skills that leverage the existing workflow node infrastructure.
"""
+import json
from typing import Dict, Any, List, Optional, Callable, Type, TYPE_CHECKING
from dataclasses import dataclass
from pydantic import BaseModel, Field
@@ -411,14 +412,16 @@ class SkillExecutor:
'message': args.get('message')
}
- # HTTP request
+ # HTTP request - serialize headers and body to JSON strings (handler expects JSON strings)
if tool_name == 'http-request':
+ headers = args.get('headers')
+ body = args.get('body')
return {
'url': args.get('url'),
'method': args.get('method', 'GET'),
- 'body': args.get('body'),
- 'headers': args.get('headers'),
- 'timeout': 30000
+ 'body': json.dumps(body) if isinstance(body, dict) else (body or ''),
+ 'headers': json.dumps(headers) if isinstance(headers, dict) else (headers or '{}'),
+ 'timeout': 30
}
# Maps geocode
diff --git a/server/services/temporal/workflow.py b/server/services/temporal/workflow.py
index 1f0009fc..5dc1cef8 100644
--- a/server/services/temporal/workflow.py
+++ b/server/services/temporal/workflow.py
@@ -18,7 +18,9 @@ from temporalio import workflow
from temporalio.common import RetryPolicy
# Config handles - nodes connecting via these are config nodes (not executed)
-CONFIG_HANDLES = {"input-tools", "input-memory", "input-model"}
+# AI Agent handles: input-memory, input-tools, input-model
+# Chat Agent handles: input-skill, input-tools
+CONFIG_HANDLES = {"input-tools", "input-memory", "input-model", "input-skill"}
# Android service types (connect to androidTool, not executed directly)
ANDROID_SERVICE_TYPES = {
@@ -26,6 +28,12 @@ ANDROID_SERVICE_TYPES = {
"systemInfo", "appList", "appLauncher",
}
+# Skill node types (connect to Chat Agent's input-skill, not executed directly)
+SKILL_NODE_TYPES = {
+ "assistantPersonality", "whatsappSkill", "memorySkill", "mapsSkill",
+ "httpSkill", "schedulerSkill", "androidSkill", "codeSkill", "customSkill",
+}
+
@workflow.defn(sandboxed=False)
class MachinaWorkflow:
"""Distributed workflow orchestrator.
@@ -285,6 +293,10 @@ class MachinaWorkflow:
if source_node.get("type") in ANDROID_SERVICE_TYPES:
config_ids.add(source_id)
+ # Skill nodes (always config, connect to Chat Agent)
+ if source_node.get("type") in SKILL_NODE_TYPES:
+ config_ids.add(source_id)
+
# Filter nodes and edges
exec_nodes = [n for n in nodes if n["id"] not in config_ids]
exec_edges = [
diff --git a/server/skills/claude-assistant/SKILL.md b/server/skills/assistant-personality/SKILL.md
similarity index 96%
rename from server/skills/claude-assistant/SKILL.md
rename to server/skills/assistant-personality/SKILL.md
index 2705f211..221f317e 100644
--- a/server/skills/claude-assistant/SKILL.md
+++ b/server/skills/assistant-personality/SKILL.md
@@ -1,5 +1,5 @@
---
-name: claude-assistant
+name: assistant-personality
description: General AI assistant with helpful, harmless, and honest responses. Use as the default personality for conversations.
metadata:
author: machina
@@ -7,7 +7,7 @@ metadata:
category: assistant
---
-# Claude Assistant
+# Assistant Personality
You are a helpful, harmless, and honest AI assistant. Your goal is to assist users with their requests while being truthful and avoiding harmful content.
diff --git a/server/skills/http-skill/SKILL.md b/server/skills/http-skill/SKILL.md
index 44a78c1b..e3f0b67e 100644
--- a/server/skills/http-skill/SKILL.md
+++ b/server/skills/http-skill/SKILL.md
@@ -4,7 +4,7 @@ description: Make HTTP requests to external APIs and web services. Use when user
allowed-tools: http-request
metadata:
author: machina
- version: "1.0"
+ version: "2.0"
category: integration
---
@@ -15,79 +15,147 @@ This skill enables you to make HTTP requests to external APIs and web services.
## Capabilities
- Make GET, POST, PUT, DELETE, PATCH requests
-- Send JSON payloads
-- Set custom headers
-- Handle API responses
+- Send JSON payloads in request body
+- Set custom headers (authentication, content-type, etc.)
+- Handle API responses (JSON and text)
## Tool Reference
### http-request
-Make an HTTP request to a URL.
-Parameters:
-- `url` (required): Full URL to request
-- `method` (optional): HTTP method (GET, POST, PUT, DELETE, PATCH). Default: GET
-- `body` (optional): Request body as JSON object
-- `headers` (optional): Custom headers as key-value pairs
-- `timeout` (optional): Timeout in milliseconds (default: 30000)
+Make an HTTP request to a URL.
-Returns:
-- status: HTTP status code
-- body: Response body
-- headers: Response headers
+**Parameters:**
+| Parameter | Type | Required | Default | Description |
+|-----------|------|----------|---------|-------------|
+| `url` | string | Yes | - | Full URL to request (e.g., `https://api.example.com/data`) |
+| `method` | string | No | `GET` | HTTP method: `GET`, `POST`, `PUT`, `DELETE`, `PATCH` |
+| `body` | object | No | null | Request body as JSON object (for POST/PUT/PATCH) |
+| `headers` | object | No | null | Custom headers as key-value pairs |
+
+**Returns:**
+| Field | Type | Description |
+|-------|------|-------------|
+| `status` | number | HTTP status code (200, 404, 500, etc.) |
+| `data` | any | Response body (parsed JSON or text) |
+| `headers` | object | Response headers |
+| `url` | string | Final URL (may differ if redirected) |
+| `method` | string | HTTP method used |
## Common Use Cases
-### Fetching Data
-```
-GET https://api.example.com/data
+### Fetching Data (GET)
+```json
+{
+ "url": "https://api.example.com/users/123",
+ "method": "GET"
+}
```
-### Creating Resources
+### Creating Resources (POST)
+```json
+{
+ "url": "https://api.example.com/users",
+ "method": "POST",
+ "body": {"name": "John", "email": "[email protected]"},
+ "headers": {"Content-Type": "application/json"}
+}
```
-POST https://api.example.com/items
-Body: {"name": "New Item", "value": 100}
+
+### Updating Resources (PUT/PATCH)
+```json
+{
+ "url": "https://api.example.com/users/123",
+ "method": "PUT",
+ "body": {"name": "John Updated"}
+}
```
-### Updating Resources
+### Deleting Resources (DELETE)
+```json
+{
+ "url": "https://api.example.com/users/123",
+ "method": "DELETE"
+}
```
-PUT https://api.example.com/items/123
-Body: {"name": "Updated Item"}
+
+### With Authentication
+```json
+{
+ "url": "https://api.example.com/protected",
+ "method": "GET",
+ "headers": {
+ "Authorization": "Bearer your-api-token",
+ "X-API-Key": "your-api-key"
+ }
+}
```
## Examples
**User**: "Get the current Bitcoin price"
**Action**: Use http-request with:
-- url: "https://api.coindesk.com/v1/bpi/currentprice.json"
-- method: "GET"
+```json
+{
+ "url": "https://api.coindesk.com/v1/bpi/currentprice.json",
+ "method": "GET"
+}
+```
**User**: "Post this data to my webhook"
**Action**: Use http-request with:
-- url: "[user's webhook URL]"
-- method: "POST"
-- body: {"data": "..."}
+```json
+{
+ "url": "https://webhook.example.com/endpoint",
+ "method": "POST",
+ "body": {"event": "user_action", "data": "..."},
+ "headers": {"Content-Type": "application/json"}
+}
+```
**User**: "Check if example.com is up"
**Action**: Use http-request with:
-- url: "https://example.com"
-- method: "GET"
+```json
+{
+ "url": "https://example.com",
+ "method": "GET"
+}
+```
+Then check if status is 200.
+
+**User**: "Get weather for New York"
+**Action**: Use http-request with:
+```json
+{
+ "url": "https://api.openweathermap.org/data/2.5/weather?q=New York&appid=YOUR_KEY",
+ "method": "GET"
+}
+```
## Security Guidelines
-1. **Never expose API keys** in responses
-2. **Validate URLs** before making requests
-3. **Don't make requests** to internal/private networks
+1. **Never expose API keys** in responses to the user
+2. **Validate URLs** - only request from trusted domains
+3. **Don't make requests** to internal/private networks (localhost, 192.168.x.x, 10.x.x.x)
4. **Respect rate limits** of external services
-5. **Handle errors gracefully** and inform the user
+5. **Handle errors gracefully** and inform the user clearly
+6. **Don't store sensitive data** from API responses
## Error Handling
-Common HTTP status codes:
-- 200: Success
-- 400: Bad request (check parameters)
-- 401: Unauthorized (check API key)
-- 403: Forbidden (access denied)
-- 404: Not found
-- 429: Too many requests (rate limited)
-- 500: Server error (try again later)
+Common HTTP status codes and what they mean:
+
+| Status | Meaning | Action |
+|--------|---------|--------|
+| 200-299 | Success | Process the response data |
+| 400 | Bad Request | Check request parameters |
+| 401 | Unauthorized | Check API key/authentication |
+| 403 | Forbidden | Access denied, may need different permissions |
+| 404 | Not Found | Check URL path |
+| 429 | Too Many Requests | Rate limited, wait before retrying |
+| 500-599 | Server Error | External service issue, try again later |
+
+When an error occurs, inform the user about:
+- What was attempted
+- What went wrong (status code and message)
+- Suggested next steps
diff --git a/server/skills/whatsapp-skill/SKILL.md b/server/skills/whatsapp-skill/SKILL.md
index b7df713d..3d8a9bce 100644
--- a/server/skills/whatsapp-skill/SKILL.md
+++ b/server/skills/whatsapp-skill/SKILL.md
@@ -1,68 +1,187 @@
---
name: whatsapp-skill
-description: Send and receive WhatsApp messages. Use when user mentions WhatsApp, messaging, texting someone, or wants to send a message to a phone number.
-allowed-tools: whatsapp-send whatsapp-status
+description: Send and receive WhatsApp messages, retrieve chat history. Supports text, images, videos, audio, documents, stickers, location, and contact cards.
+allowed-tools: whatsapp_send whatsapp_chat_history
metadata:
author: machina
- version: "1.0"
- category: communication
+ version: "2.0"
+ category: messaging
---
-# WhatsApp Messaging
+# WhatsApp Messaging Skill
-This skill enables you to send WhatsApp messages to contacts and groups.
+Send and receive WhatsApp messages using connected WhatsApp nodes.
## Capabilities
-- Send text messages to phone numbers
-- Send messages to groups
-- Check WhatsApp connection status
-
-## Usage
-
-### Sending Messages
-
-When the user wants to send a message:
-
-1. **Extract the recipient**: Phone number (with country code) or contact name
-2. **Extract the message**: The content to send
-3. **Use the whatsapp-send tool** with the extracted information
-
-### Phone Number Format
-
-- Always use international format with country code
-- Example: +1234567890 (US), +447123456789 (UK)
-- Remove spaces and dashes from numbers
-
-## Tool Reference
-
-### whatsapp-send
-Send a message via WhatsApp.
-
-Parameters:
-- `phone_number` (required): Recipient phone number with country code
-- `message` (required): Message text to send
-
-### whatsapp-status
-Check WhatsApp connection status.
-
-Parameters: None
-
-## Examples
-
-**User**: "Send a WhatsApp to +1234567890 saying I'll be late"
-**Action**: Use whatsapp-send with:
-- phone_number: "+1234567890"
-- message: "I'll be late"
-
-**User**: "Text John that the meeting is at 3pm"
-**Response**: I need John's phone number to send the message. Could you provide his number with the country code?
-
-**User**: "Is WhatsApp connected?"
-**Action**: Use whatsapp-status to check connection
+- Send text messages to phone numbers or groups
+- Send media messages (images, videos, audio, documents, stickers)
+- Send location information
+- Send contact cards (vCard)
+- Retrieve chat history from individual chats or groups
+- Filter messages by type (all or text only)
+- Paginate through message history
+
+## whatsapp_send
+
+Send messages to contacts or groups.
+
+### Parameters
+
+| Parameter | Type | Required | Description |
+|-----------|------|----------|-------------|
+| recipient_type | string | Yes | "phone" for individual or "group" for group chat |
+| phone | string | If phone | Phone number without + prefix (e.g., 1234567890) |
+| group_id | string | If group | Group JID (e.g., [email protected]) |
+| message_type | string | Yes | "text", "image", "video", "audio", "document", "sticker", "location", "contact" |
+| message | string | If text | Text message content |
+| media_url | string | If media | URL for image/video/audio/document/sticker |
+| caption | string | No | Caption for media messages (image, video, document) |
+| latitude | float | If location | Latitude coordinate |
+| longitude | float | If location | Longitude coordinate |
+| location_name | string | No | Display name for location |
+| address | string | No | Address text for location |
+| contact_name | string | If contact | Contact display name |
+| vcard | string | If contact | vCard 3.0 format string |
+
+### Examples
+
+**Send text message:**
+```json
+{
+ "recipient_type": "phone",
+ "phone": "1234567890",
+ "message_type": "text",
+ "message": "Hello! How are you?"
+}
+```
+
+**Send image with caption:**
+```json
+{
+ "recipient_type": "phone",
+ "phone": "1234567890",
+ "message_type": "image",
+ "media_url": "https://example.com/photo.jpg",
+ "caption": "Check out this photo!"
+}
+```
+
+**Send to group:**
+```json
+{
+ "recipient_type": "group",
+ "group_id": "[email protected]",
+ "message_type": "text",
+ "message": "Hello everyone!"
+}
+```
+
+**Send location:**
+```json
+{
+ "recipient_type": "phone",
+ "phone": "1234567890",
+ "message_type": "location",
+ "latitude": 37.7749,
+ "longitude": -122.4194,
+ "location_name": "San Francisco",
+ "address": "San Francisco, CA, USA"
+}
+```
+
+**Send contact card:**
+```json
+{
+ "recipient_type": "phone",
+ "phone": "1234567890",
+ "message_type": "contact",
+ "contact_name": "John Doe",
+ "vcard": "BEGIN:VCARD\nVERSION:3.0\nFN:John Doe\nTEL:+1234567890\nEND:VCARD"
+}
+```
+
+## whatsapp_chat_history
+
+Retrieve message history from chats.
+
+### Parameters
+
+| Parameter | Type | Required | Description |
+|-----------|------|----------|-------------|
+| chat_type | string | Yes | "individual" for 1:1 chat or "group" for group chat |
+| phone | string | If individual | Phone number without + prefix |
+| group_id | string | If group | Group JID (e.g., [email protected]) |
+| message_filter | string | No | "all" (default) or "text_only" |
+| limit | int | No | Max messages to retrieve (1-500, default 50) |
+| offset | int | No | Messages to skip for pagination (default 0) |
+
+### Examples
+
+**Get recent messages from contact:**
+```json
+{
+ "chat_type": "individual",
+ "phone": "1234567890",
+ "limit": 20
+}
+```
+
+**Get text-only messages from group:**
+```json
+{
+ "chat_type": "group",
+ "group_id": "[email protected]",
+ "message_filter": "text_only",
+ "limit": 50
+}
+```
+
+**Paginate through history:**
+```json
+{
+ "chat_type": "individual",
+ "phone": "1234567890",
+ "limit": 50,
+ "offset": 50
+}
+```
+
+### Response Format
+
+```json
+{
+ "success": true,
+ "chat_type": "individual",
+ "identifier": "1234567890",
+ "messages": [
+ {
+ "sender": "1234567890",
+ "text": "Hello!",
+ "timestamp": "2025-01-27T10:30:00Z",
+ "type": "text",
+ "is_from_me": false
+ }
+ ],
+ "total": 150,
+ "has_more": true,
+ "count": 50
+}
+```
+
+## Guidelines
+
+1. **Phone numbers**: Always use without + prefix, just digits (e.g., 1234567890)
+2. **Groups**: Use JID format ending in @g.us
+3. **Media URLs**: Must be publicly accessible URLs
+4. **Location**: Both latitude and longitude are required
+5. **Contact cards**: Use vCard 3.0 format
+6. **Pagination**: Use offset with limit to page through results
+7. **Message filter**: Use "text_only" to exclude media messages
## Error Handling
-- If WhatsApp is not connected, inform the user and suggest checking the connection
-- If phone number is invalid, ask for the correct format
-- If message fails to send, provide the error and suggest retrying
+- If recipient info is missing, ask for the phone number or group ID
+- If message type requires media URL but none provided, request the URL
+- If location is requested but coordinates missing, ask for latitude and longitude
+- If WhatsApp is not connected, inform the user to check connection status