workflows.fit
Back to n8n workflows
n8n templateFreeBy Davide Boizza

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 se...

AILangchainCore NodesChat TriggerAgentModel SelectorOutput Parser Structured
Loading interactive preview...

Template notes

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.