AI Integration Overview
Relevant source files
The following files were used as context for generating this wiki page:
- packages/frontend/editor-ui/src/constants.ts
- packages/nodes-base/nodes/HumanticAI/HumanticAi.node.json
- packages/nodes-base/nodes/Google/CloudNaturalLanguage/GoogleCloudNaturalLanguage.node.json
- packages/frontend/editor-ui/src/components/WhatsNewModal.test.ts
- packages/nodes-base/nodes/HttpRequest/HttpRequest.node.json
- packages/nodes-base/nodes/If/If.node.json
- packages/nodes-base/nodes/Function/Function.node.json
n8n integrates Artificial Intelligence capabilities directly into its workflow automation platform through a dedicated set of nodes, primarily located in the @n8n/n8n-nodes-langchain package. This integration allows users to build sophisticated workflows that leverage large language models (LLMs), agents, and various AI-powered tools for tasks ranging from data transformation and analysis to complex, multi-step reasoning and interaction with external systems.
The AI features are designed to be modular, with distinct nodes for different functionalities like agents, chains, tools, and language models. This approach allows for flexible and powerful combinations, enabling the creation of AI-driven applications and assistants within the n8n canvas. The system also includes UI elements like the "Ask AI" feature and specific modals to enhance the user experience when building with AI.
Sources: packages/frontend/editor-ui/src/constants.ts:1040
AI Node Architecture
The AI capabilities in n8n are structured into a clear hierarchy of categories, which helps organize the various nodes available for building AI-powered workflows. This structure is defined within the frontend constants and is reflected in the node creator panel in the UI.
Sources: packages/frontend/editor-ui/src/constants.ts:350-374
AI Node Categories
The following diagram and table illustrate the main categories for AI nodes, providing a structured approach to building complex AI agents and chains.
This diagram shows the high-level categorization of AI nodes within n8n.
| Category | Description |
|---|---|
Agents | Nodes that use language models to choose a sequence of actions to take, often using Tools. |
Chains | Nodes for creating sequences of calls to LLMs or other utilities. |
Language Models | Nodes for interacting directly with LLMs like OpenAI. |
Tools | Nodes that provide agents with capabilities, such as performing web searches or making API calls. |
Vector Stores | Nodes for storing and searching over unstructured data using vector embeddings. |
Retrievers | Nodes responsible for fetching documents to pass to a chain. |
Embeddings | Nodes that create vector representations of text. |
Document Loaders | Nodes for loading data from a source as documents. |
Text Splitters | Nodes for splitting large pieces of text into smaller chunks. |
Memory | Nodes that allow chains and agents to remember previous interactions. |
Output Parsers | Nodes that structure the output from language models. |
Root Nodes | Core nodes for initiating AI-specific workflows, like chat triggers. |
Model Context Protocol | Nodes related to the Model Context Protocol (MCP). |
Evaluation | Nodes for evaluating the performance of AI models and prompts. |
Miscellaneous | Other uncategorized AI-related nodes. |
Sources: packages/frontend/editor-ui/src/constants.ts:361-374
Key AI Node Types
n8n provides a wide array of specific nodes for AI integration. The following table lists some of the key node types available.
| Node Type Constant | Node Name / Purpose |
|---|---|
AGENT_NODE_TYPE | @n8n/n8n-nodes-langchain.agent (Core Agent node) |
OPEN_AI_NODE_TYPE | @n8n/n8n-nodes-langchain.openAi (OpenAI integration) |
BASIC_CHAIN_NODE_TYPE | @n8n/n8n-nodes-langchain.chainLlm (Basic LLM Chain) |
QA_CHAIN_NODE_TYPE | @n8n/n8n-nodes-langchain.chainRetrievalQa (Retrieval QA Chain) |
AI_TRANSFORM_NODE_TYPE | n8n-nodes-base.aiTransform (Transform data using AI) |
AI_CODE_NODE_TYPE | @n8n/n8n-nodes-langchain.code (Execute code generated by AI) |
HTTP_REQUEST_TOOL_NODE_TYPE | n8n-nodes-base.httpRequestTool (HTTP Request as an AI tool) |
AI_WORKFLOW_TOOL_LANGCHAIN_NODE_TYPE | @n8n/n8n-nodes-langchain.toolWorkflow (Use another workflow as a tool) |
HUMANTIC_AI_NODE_TYPE | n8n-nodes-base.humanticAi (HumanticAI for personality insights) |
GOOGLE_CLOUD_NATURAL_LANGUAGE_NODE_TYPE | n8n-nodes-base.googleCloudNaturalLanguage (Google's NLP services) |
Sources: packages/frontend/editor-ui/src/constants.ts:170-280, packages/nodes-base/nodes/HumanticAI/HumanticAi.node.json, packages/nodes-base/nodes/Google/CloudNaturalLanguage/GoogleCloudNaturalLanguage.node.json
AI in Workflows
AI nodes are designed to work seamlessly with standard n8n nodes. An AI agent can use tools, which can be other n8n nodes, to interact with the outside world. For example, an agent can be given an HttpRequest node as a tool to fetch information from an API.
The following diagram shows a conceptual flow where a chat trigger initiates a workflow, an AI Agent processes the input, and uses an HTTP Request tool to get external data before making a decision with an IF node.
Modular Workflows with Sub-Workflows
For complex AI-driven processes, workflows can become large and difficult to manage. The "Convert to sub-workflow" feature allows developers to encapsulate a series of connected nodes into a reusable sub-workflow. This is particularly useful for modularizing AI logic, such as creating a dedicated sub-workflow for a specific agent and its tools, which can then be called from a main workflow. This improves maintainability, scalability, and debugging.
Sources: packages/frontend/editor-ui/src/components/WhatsNewModal.test.ts:84-105
UI and Developer Experience
The n8n frontend includes several features specifically for working with AI.
Ask AI
The "Ask AI" feature provides an interactive way to get help or generate content within the application. It has defined constraints on prompt length to ensure efficient interaction.
| Constant | Value | Description |
|---|---|---|
ASK_AI_MAX_PROMPT_LENGTH | 600 | The maximum character length for a prompt. |
ASK_AI_MIN_PROMPT_LENGTH | 15 | The minimum character length for a prompt. |
ASK_AI_LOADING_DURATION_MS | 12000 | The loading indicator timeout in milliseconds. |
Sources: packages/frontend/editor-ui/src/constants.ts:1016-1019
AI-Related Modals and Experiments
The UI defines modals for AI-specific interactions, such as FROM_AI_PARAMETERS_MODAL_KEY, which is likely used to configure node parameters from an AI-generated output. Furthermore, n8n uses an experimentation framework to test new AI-related features, such as the WORKFLOW_BUILDER_EXPERIMENT (for an AI-powered workflow builder agent) and PRE_BUILT_AGENTS_EXPERIMENT.
Sources: packages/frontend/editor-ui/src/constants.ts:93, 900-905, 923-927
Conclusion
n8n's AI integration is a comprehensive ecosystem of nodes and features built upon the n8n-nodes-langchain package. It provides a structured, modular, and powerful way to embed artificial intelligence into automation workflows. By categorizing AI functionalities and enabling seamless interaction between AI and standard nodes, n8n empowers developers to build complex, intelligent systems for a wide variety of use cases, from simple data analysis to autonomous agents that can interact with external APIs and make decisions. Features like sub-workflows and a dedicated UI further enhance the development and maintenance of these sophisticated automations.