Model Discovery & Preferences
Relevant source files
The following files were used as context for generating this wiki page:
- packages/@n8n/ai-utilities/src/model-discovery/index.ts
- packages/cli/src/modules/mcp/tools/workflow-builder/mcp-instructions.ts
- packages/@n8n/ai-workflow-builder.ee/src/prompts/agents/discovery.prompt.ts
- packages/@n8n/ai-workflow-builder.ee/src/code-builder/prompts/index.ts
- packages/cli/src/ai-preference.controller.ts
Model Discovery & Preferences refers to the system within n8n that identifies, suggests, and configures AI models and nodes for workflow automation. It enables the AI Workflow Builder to select appropriate Large Language Models (LLMs) and integration nodes based on user intent while respecting stored user preferences for specific AI providers or techniques.
Sources: packages/@n8n/ai-workflow-builder.ee/src/prompts/agents/discovery.prompt.ts:18-21, packages/cli/src/modules/mcp/tools/workflow-builder/mcp-instructions.ts:80-82
Discovery Agent Architecture
The Discovery Agent identifies relevant n8n nodes and connection-changing parameters based on a user's request. It assesses whether the request is underspecified and asks clarifying questions to ensure the generated workflow matches user intent.
Sources: packages/@n8n/ai-workflow-builder.ee/src/prompts/agents/discovery.prompt.ts:32-34
Node Selection Logic
The discovery process prioritizes native n8n nodes over custom Code nodes to ensure better user experience and visual debugging. It uses specific mappings for common tasks:
- Data Transformation: Uses "Edit Fields (Set)" for mapping or restructuring.
- Logic: Uses "Filter", "If", or "Switch" for conditional routing.
- AI Tasks: Uses "AI Agent" for reasoning and specialized LLM nodes (OpenAI, Anthropic, Google Gemini) for specific model capabilities.
Sources: packages/@n8n/ai-workflow-builder.ee/src/prompts/agents/discovery.prompt.ts:208-220, packages/@n8n/ai-workflow-builder.ee/src/prompts/agents/discovery.prompt.ts:225-231
Discovery Data Flow
The following diagram illustrates how the Discovery Agent processes a request to identify nodes and parameters.
The agent extract requirements, identifies external services, and searches for matching nodes before submitting final results.
Sources: packages/@n8n/ai-workflow-builder.ee/src/prompts/agents/discovery.prompt.ts:40-44, packages/@n8n/ai-workflow-builder.ee/src/code-builder/prompts/index.ts:391-410
AI Node & Model Discovery Patterns
The system employs specific patterns for connecting AI models to agents and tools. It distinguishes between regular nodes and tool nodes based on whether the AI model needs to control the execution at runtime.
AI Agent Configuration
- AI Agent Node: Used for text analysis, classification, and reasoning tasks.
- Chat Models: Connected via
ai_languageModelto power the agent. - Memory: "Window Buffer Memory" is included for chatbots to maintain context.
- Output Parsers: "Structured Output Parser" is preferred for data extraction that feeds into downstream nodes.
Sources: packages/@n8n/ai-workflow-builder.ee/src/prompts/agents/discovery.prompt.ts:46-56
Multi-Agent Systems
For requests involving "team of agents" or "supervisor agents", the system utilizes the AI Agent Tool (@n8n/n8n-nodes-langchain.agentTool). This allows a main agent to invoke sub-agents as tools.
Each Agent Tool requires its own Chat Model to function as a complete sub-unit.
Sources: packages/@n8n/ai-workflow-builder.ee/src/prompts/agents/discovery.prompt.ts:60-75
User Preferences and Gateway Credits
User preferences influence the discovery process by guiding the LLM toward specific services or styles. Additionally, n8n supports "Gateway credits" which allow users to use LLMs without configuring individual credentials.
Preference Handling
The system retrieves user preferences before starting the building process. This ensures the output aligns with the user's preferred house style or preferred AI providers.
Sources: packages/cli/src/modules/mcp/tools/workflow-builder/mcp-instructions.ts:77-82
Gateway Credits Discovery
Discovery tools return a gatewayCredits.nodes array when available. If a node is part of this array, it can attach a managed credential automatically, allowing the workflow to run without the user providing API keys.
Sources: packages/cli/src/modules/mcp/tools/workflow-builder/mcp-instructions.ts:90-97
Summary of Techniques and Mappings
The discovery process categorizes user prompts into specific techniques to retrieve relevant best practices and node recommendations.
| Technique | Purpose | Recommended Nodes |
|---|---|---|
| Chatbot | Receiving and replying to messages | Chat Trigger, Slack/Telegram nodes |
| Scraping | Collecting information from websites | HTTP Request, HTML Extract, SearchAPI |
| Data Analysis | Identifying patterns or insights | AI Agent, Aggregate, Code |
| Notification | Sending alerts or updates | Gmail, Slack, Twilio, Email Send |
| Knowledge Base | Retrieving from info collections | Vector Store (Pinecone, Qdrant), Supabase |
Sources: packages/@n8n/ai-workflow-builder.ee/src/prompts/agents/discovery.prompt.ts:133-155, packages/@n8n/ai-workflow-builder.ee/src/prompts/agents/discovery.prompt.ts:175-200
Conclusion
Model Discovery & Preferences provides the intelligence layer for n8n's AI Workflow Builder. By combining active discovery via specialized agents with a preference system that respects user configuration and Gateway credits, n8n automates the selection of models and nodes while maintaining workflow architectural integrity.
Sources: packages/@n8n/ai-workflow-builder.ee/src/prompts/agents/discovery.prompt.ts:20-25, packages/cli/src/modules/mcp/tools/workflow-builder/mcp-instructions.ts:108-115