Skip to main content

AI orchestrator: dynamically selects models based on input type

Workflow preview

Workflow preview
100%
AI orchestrator: dynamically selects models based on input type preview
Open on n8n.io

Important notice

This workflow is provided as-is. Please review and test before using in production.

1. Workflow Overview

This workflow is designed to intelligently route user queries to the most suitable large language model (LLM) based on the type of request received in a chat environment. It uses structured classif...

Best for

  • Engineering automation workflows
  • AI Chatbot automation workflows
  • intermediate n8n builders looking for reusable templates

Tools used

@n8n/n8n-nodes-langchain.chattrigger, @n8n/n8n-nodes-langchain.agent, @n8n/n8n-nodes-langchain.modelselector, @n8n/n8n-nodes-langchain.outputparserstructured, @n8n/n8n-nodes-langchain.memorybufferwindow, @n8n/n8n-nodes-langchain.chainllm, @n8n/n8n-nodes-langchain.lmchatanthropic, @n8n/n8n-nodes-langchain.lmchatgooglegemini

Source and attribution

This workflow is cataloged by N8N Workflows and links back to its original n8n.io source page by Davide.

Original n8n.io source

1.1 Workflow description

Title
AI orchestrator: dynamically selects models based on input type
Workflow name
AI orchestrator: dynamically selects models based on input type

This workflow is designed to intelligently route user queries to the most suitable large language model (LLM) based on the type of request received in a chat environment. It uses structured classification and model selection to optimize both performance and cost-efficiency in AI-driven conversations.

It dynamically routes requests to specialized AI models based on content type, optimizing response quality and efficiency.


Benefits

  • Smart Model Routing: Reduces costs by using lighter models for general tasks and reserving heavier models for complex needs.
  • Scalability: Easily expandable by adding more request types or LLMs.
  • Maintainability: Clear logic separation between classification, model routing, and execution.
  • Personalization: Can be integrated with session IDs for per-user memory, enabling personalized conversations.
  • Speed Optimization: Fast models like GPT-4.1 mini or Gemini Flash are chosen for tasks where speed is a priority.

How It Works

  1. Input Handling:

    • The workflow starts with the "When chat message received" node, which triggers the process when a chat message is received. The input includes the chat message (chatInput) and a session ID (sessionId).
  2. Request Classification:

    • The "Request Type" node uses an OpenAI model (gpt-4.1-mini) to classify the incoming request into one of four categories:
      • general: For general queries.
      • reasoning: For reasoning-based questions.
      • coding: For code-related requests.
      • search: For queries requiring search tools.
    • The classification is structured using the "Structured Output Parser" node, which enforces a consistent output format.
  3. Model Selection:

    • The "Model Selector" node routes the request to one of four AI models based on the classification:
      • Opus 4 (Claude 4 Sonnet): Used for coding requests.
      • Gemini Thinking Pro: Used for reasoning requests.
      • GPT 4.1 mini: Used for general requests.
      • Perplexity: Used for search (Google-related) requests.
  4. AI Processing:

    • The selected model processes the request via the "AI Agent" node, which includes intermediate steps for complex tasks.
    • The "Simple Memory" node retains session context using the provided sessionId, enabling multi-turn conversations.
  5. Output:

    • The final response is generated by the chosen model and returned to the user.

Set Up Steps

  1. Configure Trigger:

    • Ensure the "When chat message received" node is set up with the correct webhook ID to receive chat inputs.
  2. Define Classification Logic:

    • Adjust the prompt in the "Request Type" node to refine classification accuracy.
    • Verify the output schema in the "Structured Output Parser" node matches expected categories (general, reasoning, coding, search).
  3. Connect AI Models:

    • Link each model node (Opus 4, Gemini Thinking Pro, GPT 4.1 mini, Perplexity) to the "Model Selector" node.
    • Ensure credentials (API keys) for each model are correctly configured in their respective nodes.
  4. Set Up Memory:

    • Configure the "Simple Memory" node to use the sessionId from the input for context retention.
  5. Test Workflow:

    • Send test inputs to verify classification and model routing.
    • Check intermediate outputs (e.g., request_type) to ensure correct model selection.
  6. Activate Workflow:

    • Toggle the workflow to "Active" in n8n after testing.

Need help customizing?

Contact me for consulting and support or add me on Linkedin.

1.2 Logical Blocks

This catalog entry is organized from the workflow JSON. The node-level section below shows the executable blocks available for review before importing the template.

2. Block-by-Block Analysis

Block 1 - When chat message received

Type / Role
@n8n/n8n-nodes-langchain.chatTrigger - chatTrigger
Config choices
Version 1.1

Block 2 - AI Agent

Type / Role
@n8n/n8n-nodes-langchain.agent - agent
Config choices
Version 2.1

Block 3 - Model Selector

Type / Role
@n8n/n8n-nodes-langchain.modelSelector - modelSelector
Config choices
Version 1

Block 4 - Structured Output Parser

Type / Role
@n8n/n8n-nodes-langchain.outputParserStructured - outputParserStructured
Config choices
Version 1.3

Block 5 - Simple Memory

Type / Role
@n8n/n8n-nodes-langchain.memoryBufferWindow - memoryBufferWindow
Config choices
Version 1.3

Block 6 - Request Type

Type / Role
@n8n/n8n-nodes-langchain.chainLlm - chainLlm
Config choices
Version 1.7

Block 7 - Opus 4

Type / Role
@n8n/n8n-nodes-langchain.lmChatAnthropic - lmChatAnthropic
Config choices
Version 1.3

Block 8 - Gemini Thinking Pro

Type / Role
@n8n/n8n-nodes-langchain.lmChatGoogleGemini - lmChatGoogleGemini
Config choices
Version 1

Block 9 - GPT 4.1 mini

Type / Role
@n8n/n8n-nodes-langchain.lmChatOpenAi - lmChatOpenAi
Config choices
Version 1.2

Block 10 - Perplexity

Type / Role
@n8n/n8n-nodes-langchain.lmChatOpenRouter - lmChatOpenRouter
Config choices
Version 1

Block 11 - OpenAI Chat Model

Type / Role
@n8n/n8n-nodes-langchain.lmChatOpenAi - lmChatOpenAi
Config choices
Version 1.2

Block 12 - Sticky Note

Type / Role
n8n-nodes-base.stickyNote - stickyNote
Config choices
Version 1

3. Summary Table

Workflow AI orchestrator: dynamically selects models based on input type
Complexity intermediate
Nodes 12
Categories Engineering, AI Chatbot
Author Davide
Published 05 Aug 2025

4. Reproducing the Workflow from Scratch

  1. 1. Download the workflow JSON

    Use the JSON export at /data/workflows/7004/7004.json as the source template for this automation.

  2. 2. Import the template into n8n

    Open n8n, import the downloaded JSON, and review each node before activating the workflow.

  3. 3. Configure credentials and variables

    Replace placeholder credentials, API keys, webhook URLs, account IDs, and environment-specific values with your own settings.

  4. 4. Test with sample data

    Run the workflow manually or in a staging workspace, inspect node output, and confirm downstream systems receive the expected data.

  5. 5. Activate and monitor

    Enable the workflow only after testing, then monitor executions, errors, and rate limits during the first production runs.

5. General Notes & Resources

Review imported nodes carefully before activation. This catalog entry is intended to help you inspect the workflow structure, understand required services, and find related templates faster.

Node names, credentials, schedules, webhook paths, and external service limits may need adjustment for your workspace.

Frequently asked questions

What does AI orchestrator: dynamically selects models based on input type do?

This workflow is designed to intelligently route user queries to the most suitable large language model (LLM) based on the type of request received in a chat environment. It uses structured classif...

What do I need before importing this workflow?

Review the workflow JSON, configure any required credentials in n8n, and test the automation in a safe workspace before using it in production.

Can I customize this workflow?

Yes. Use the block-by-block analysis and the downloadable JSON to inspect each node, then adjust credentials, prompts, schedules, filters, or destinations for your Engineering, AI Chatbot use case.