Package Information
Downloads: 7 weeklyĀ /Ā 54 monthly
Latest Version: 0.1.0
Author: go9tech
Documentation
n8n Tool Workflow with Transformer
A custom n8n node that executes workflows as AI agent tools with JavaScript output transformation capabilities.
šÆ Overview
The Tool Workflow with Transformer node is based on the official n8n ToolWorkflow node, but adds a powerful feature: the ability to transform the workflow output using custom JavaScript code before returning it to the AI agent.
This is particularly useful when you need to:
- Format workflow output for specific AI agent requirements
- Extract only relevant data from complex workflow results
- Convert data structures to match expected formats
- Summarize or aggregate workflow outputs
⨠Features
- š¤ AI Tool Integration: Designed to work as a tool for AI agents
- š Workflow Execution: Execute any n8n workflow from database or JSON
- š§ Output Transformation: Transform workflow output with custom JavaScript
- š¦ Flexible Input/Output: Handle various data formats
- ā” Error Handling: Robust error handling and reporting
š¦ Installation
Using npm
npm install n8n-nodes-tool-workflow-transformer
Local Development
- Clone the repository:
git clone https://github.com/your-org/n8n-nodes-tool-workflow-transformer.git
cd n8n-nodes-tool-workflow-transformer
- Install dependencies:
npm install
- Build the project:
npm run build
- Link to n8n:
npm link
cd /path/to/n8n
npm link n8n-nodes-tool-workflow-transformer
š§ Node Configuration
Parameters
Tool Configuration
- Name: The name of the tool function (alphanumeric with underscores)
- Description: Description of what the tool does for the AI agent
Workflow Source
- Source: Choose between:
- Database: Load workflow by ID from n8n database
- Define Below: Provide workflow JSON directly
Transformation
- Transform Output: Toggle to enable/disable output transformation
- Transformation Code: JavaScript code to transform the workflow output
Transformation Variables
The transformation code has access to:
$output: The output from the executed workflow (object or array)$input: The input that was sent to the workflow
š Usage Examples
Example 1: Extract Specific Fields
// Extract only names from an array of objects
if (Array.isArray($output)) {
return $output.map(item => item.name).join(', ');
}
return $output.name || 'Unknown';
Example 2: Format for AI Response
// Format workflow output as a structured message
const count = Array.isArray($output) ? $output.length : 1;
return `Found ${count} results. Details: ${JSON.stringify($output, null, 2)}`;
Example 3: Aggregate Data
// Sum values from workflow output
if (Array.isArray($output)) {
const total = $output.reduce((sum, item) => sum + (item.value || 0), 0);
return { total, itemCount: $output.length, average: total / $output.length };
}
return $output;
Example 4: Error Handling
// Safely handle different output types
try {
if (!$output) return 'No data received';
if (Array.isArray($output)) {
return $output.filter(item => item.status === 'active');
}
return $output.status === 'active' ? $output : null;
} catch (error) {
return `Error processing data: ${error.message}`;
}
šļø Architecture
The node extends the standard n8n workflow execution with:
- Workflow Execution: Executes the specified workflow with provided inputs
- Output Capture: Captures the workflow output data
- Transformation: Applies JavaScript transformation if enabled
- Result Return: Returns the (transformed) result to the AI agent
š ļø Development
Project Structure
n8n-nodes-tool-workflow-transformer/
āāā nodes/
ā āāā ToolWorkflowWithTransformer.node.ts
ā āāā toolWorkflowWithTransformer.svg
āāā dist/ # Compiled files
āāā package.json
āāā tsconfig.json
Available Scripts
npm run build- Build the TypeScript codenpm run dev- Build in watch modenpm run lint- Run ESLintnpm run lintfix- Fix linting issues
š¤ Contributing
Contributions are welcome! Please feel free to submit a Pull Request.
š License
MIT
š Support
For issues or questions, please open an issue on GitHub.
š Links
Made with ā¤ļø for the n8n community