Use this sophisticated n8n workflow to automatically route user chat prompts to the most appropriate local Ollama LLM (coding, vision, or reasoning) for maximum performance and privacy.
Download this n8n workflow template and start using it instantly.
When operating a self-hosted environment with multiple large language models (LLMs) via Ollama, selecting the most effective model for a given query is crucial for performance and resource utilization. This specialized n8n workflow solves the 'model selection' problem automatically. It acts as an expert LLM router, analyzing the user's intent—be it complex reasoning, coding assistance, or visual data extraction—and automatically selecting the correct local Ollama model. This complex n8n workflow ensures maximum efficiency by routing the task to a specialized model, all while maintaining complete privacy because the entire process runs locally. This sophisticated use of an n8n node structure provides enterprise-level AI orchestration capabilities in a private, self-hosted environment.
This automation begins with the 'When chat message received' n8n trigger, which initiates the flow whenever a new chat input is detected, passing the user’s prompt to the LLM Router. The core of this n8n workflow is the 'LLM Router' node, which functions as a decision-making AI agent. This agent utilizes the 'Ollama phi4' model and the 'Router Chat Memory' to analyze the input against a detailed decision tree (which classifies inputs into complex reasoning, coding, vision, or general chat tasks). The router’s output is a JSON object containing the name of the optimal LLM model (e.g., 'granite3.2-vision' for chart analysis).
This crucial decision is then passed to the final execution step. The 'AI Agent with Dynamic LLM' node is responsible for generating the final response. Its connected language model, 'Ollama Dynamic LLM', uses a dynamic n8n expression to read the chosen model name from the router's JSON output: ={{ $('LLM Router').item.json.output.parseJson().llm }}. This dynamically configured n8n node ensures that the correct, specialized local Ollama LLM is called to answer the user's request, maintaining conversation context via the 'Agent Chat Memory' node and completing the private, intelligent n8n workflow.
To deploy this powerful n8n workflow template, follow these steps:
http://127.0.0.1:11434).ollama pull qwq, ollama pull qwen2.5-coder:14b, etc.).This advanced n8n workflow uses several specialized nodes to achieve dynamic routing:
When chat message received (n8n Trigger):
Function: Serves as the starting point, initiating the n8n workflow upon receiving a user chat message (input).
Key Configuration: A LangChain Chat Trigger webhook setup to receive chatInput and sessionId data.
LLM Router (n8n Node):
Function: The central decision-maker. It analyzes the user prompt and selects the optimal specialized Ollama model.
Key Configuration: Uses a highly detailed System Message defining classification rules, decision trees, and required JSON output format (llm and reason). It uses 'Ollama phi4' as its computational engine.
Ollama phi4 (n8n Node):
Function: Acts as the primary LLM for the Router Agent, performing the prompt classification and model selection task.
Key Configuration: Uses the phi4:latest model via the Ollama API connection.
Router Chat Memory & Agent Chat Memory (n8n Node):
Function: Stores the history for the conversation to maintain context, ensuring the LLM Router and the final AI Agent provide coherent responses across multiple turns.
Ollama Dynamic LLM (n8n Node):
Function: The model used by the final execution agent. Its model choice is dynamically determined by the preceding routing step.
Key Configuration: The model name is set dynamically using an expression: ={{ $('LLM Router').item.json.output.parseJson().llm }}. This powerful feature is core to this n8n workflow's flexibility.
AI Agent with Dynamic LLM (n8n Node):
Function: The final agent that executes the user's request using the dynamically selected local Ollama LLM and generates the response.
* Key Configuration: Uses the user's original input as the main text and relies on the dynamically connected 'Ollama Dynamic LLM' for processing.
Automate Brazilian PIX QR code generation using this powerful n8n workflow. Integrate payments instantly with custom data processing and external API calls.

Implement robust double opt-in using a core n8n workflow. Verify user emails, store data in Google Sheets, and ensure clean subscriber lists using this reliable n8n template.

An advanced n8n workflow leveraging Perplexity research and OpenAI to automatically generate SEO-optimized HTML blog posts and publish them as drafts to WordPress, dramatically accelerating content production.

Learn how to deploy a self-hosted AI assistant using this n8n workflow, leveraging the Ollama n8n node and LangChain integration to ensure structured JSON output from Llama 3.2.

Automated system to monitor Meta (Facebook) Ad Account balances using an n8n workflow. Receive real-time low balance alerts via WhatsApp or Gmail to prevent campaign downtime. This n8n template ensures continuous operation.

Analyze n8n community contributor statistics using an advanced n8n workflow and an AI agent. This powerful n8n template fetches leaderboard data from GitHub, filters it by username, and generates a comprehensive Markdown report detailing popular n8n templates and creator impact.


As an AI Automation consultant based in Canada, I partner with forward-thinking organizations to implement AI solutions that streamline operations and drive growth.







































