Back to N8n

AI Workflow Builder Prompts

packages/@n8n/ai-workflow-builder.ee/src/prompts/README.md

1.37.25.6 KB
Original Source

AI Workflow Builder Prompts

Centralized prompts for the n8n AI Workflow Builder. This directory contains all prompts used by agents and chains.

Directory Structure

src/prompts/
├── index.ts                      # Central exports
├── README.md                     # This file
│
├── builder/                      # PromptBuilder utility
│   ├── prompt-builder.ts         # Fluent builder class
│   └── types.ts                  # Type definitions
│
├── agents/                       # Multi-agent system prompts
│   ├── supervisor.prompt.ts      # Routes requests to specialists
│   ├── discovery.prompt.ts       # Finds nodes & categorizes techniques
│   ├── builder.prompt.ts         # Creates workflow structure and configures parameters
│   └── responder.prompt.ts       # Generates user responses
│
└── chains/                       # Chain-level prompts
    ├── categorization.prompt.ts  # Workflow technique classification
    ├── compact.prompt.ts         # Conversation summarization
    ├── workflow-name.prompt.ts   # Workflow name generation
    │
    └── parameter-updater/        # Dynamic prompt system for node updates
        ├── registry.ts           # Pattern-matching registry
        ├── types.ts              # Type definitions
        ├── parameter-updater.prompt.ts  # Base prompts
        ├── guides/               # Node & parameter guides
        └── examples/             # Few-shot examples

PromptBuilder Utility

A type-safe, fluent builder for composing LLM prompts with conditional sections.

Basic Usage

typescript
const systemPrompt = prompt()
  .section('role', 'You are an assistant')
  .sectionIf(hasContext, 'context', () => buildContext())
  .examples('examples', data, (ex) => `${ex.input}${ex.output}`)
  .build();

Key Features

  • Fluent API: Chain methods for readable prompt composition
  • Conditional sections: sectionIf() and examplesIf() for dynamic content
  • Lazy evaluation: Factory functions evaluated only at build time
  • Output formats: XML tags (default) or Markdown headers
  • LangChain integration: buildAsMessageBlocks() with cache_control support

Multi-Agent Prompts

The agents/ directory contains prompts for the multi-agent workflow builder system. Each agent has a specialized role:

AgentPurpose
SupervisorRoutes user requests to the appropriate specialist
DiscoveryIdentifies relevant n8n nodes and categorizes techniques
BuilderCreates workflow structure and configures node parameters
ResponderGenerates user-facing responses

All agent prompts use PromptBuilder for consistent composition.

Chain Prompts

The chains/ directory contains prompts for specific LLM chain operations:

ChainPurpose
CategorizationAnalyzes user prompts to identify workflow techniques
CompactSummarizes conversations for context management
Workflow NameGenerates descriptive workflow names
Parameter UpdaterBuilds context-aware prompts for node parameter updates

Parameter Updater System

A registry-based system that automatically selects relevant guides and examples based on node type patterns.

How It Works

  1. Pattern Matching: Guides and examples declare patterns they match against
  2. Context-Based Selection: Registry filters content based on node type and conditions
  3. Dynamic Assembly: PromptBuilder combines base prompts with matched content

Pattern Types

PatternExampleMatches
Exact matchn8n-nodes-base.setOnly that specific node
Suffix wildcard*ToolgmailTool, slackTool, etc.
Prefix wildcardn8n-nodes-base.*Any n8n-nodes-base node
Substring.setAny node containing .set

Adding a New Guide

  1. Create a file in guides/ with the guide content and patterns
  2. Export from guides/index.ts
  3. Add to the registry array in registry.ts

Example guide structure:

typescript
export const MY_NODE_GUIDE: NodeTypeGuide = {
  patterns: ['n8n-nodes-base.myNode'],  // Which nodes to match
  condition: (ctx) => true,              // Optional: extra conditions
  content: `Your guide content here...`,
};

Conditional Guides

Some guides only apply in certain contexts. Use the condition property:

typescript
export const RESOURCE_LOCATOR_GUIDE: NodeTypeGuide = {
  patterns: ['*'],  // Matches all nodes
  condition: (ctx) => ctx.hasResourceLocatorParams === true,
  content: `...`,
};

Current Guides

GuidePatternPurpose
Set Noden8n-nodes-base.setAssignment structure & types
IF Noden8n-nodes-base.ifFilter conditions & operators
Switch Noden8n-nodes-base.switchRules and routing
HTTP Requestn8n-nodes-base.httpRequestURL, headers, body, auth
Tool Nodes*Tool$fromAI expressions
Resource Locator* (conditional)__rl structure & modes
System Message* (conditional)AI node message separation
Text Fields* (conditional)Expression embedding

Current Examples

ExamplesPatternPurpose
Set Noden8n-nodes-base.setSet node examples
IF Noden8n-nodes-base.ifIF node examples
Switch Noden8n-nodes-base.switchSwitch node examples
Tool Nodes*ToolTool node examples
Resource Locator* (conditional)ResourceLocator examples
Simple Updates*Generic fallback examples