Dynamic AI model router for query optimization with OpenRouter
The Agent Decisioner is a dynamic, AI-powered routing system that automatically selects the most appropriate large language model (LLM) to respond to a user'...
🔌 Nodes & Integrations Used (6)
📖 Implementation & Setup Guide
The **Agent Decisioner** is a dynamic, AI-powered routing system that automatically selects the most appropriate large language model (LLM) to respond to a user's query based on the query’s content and purpose.
This workflow ensures **dynamic, optimized AI responses** by intelligently routing queries to the best-suited model.
---
**Advantages**
* **🔁 Automatic Model Routing:** Automatically selects the best model for the job, improving efficiency and relevance of responses.
* **🎯 Optimized Use of Resources:** Avoids overuse of expensive models like GPT-4 by routing simpler queries to lightweight models.
* **📚 Model-Aware Reasoning:** Uses detailed metadata about model capabilities (e.g., reasoning, coding, web search) for intelligent selection.
* **📥 Modular and Extendable:** Easy to integrate with other tools or expand by adding more models or custom decision logic.
* **👨💻 Ideal for RAG and Multi-Agent Systems:** Can serve as the brain behind more complex agent frameworks or Retrieval-Augmented Generation pipelines.
---
**How It Works**
- **Chat Trigger**: The workflow starts when a user sends a message, triggering the **Routing Agent**.
- **Model Selection**: The **AI Agent** analyzes the query and selects the best-suited model from the available options (e.g., Claude 3.7 Sonnet for coding, Perplexity/Sonar for web searches, GPT-4o Mini for reasoning).
- **Structured Output**: The agent returns a **JSON response** with the user’s prompt and the chosen model.
- **Execution**: The selected model processes the query and generates a response, ensuring optimal performance for the task.
**Set Up Steps**
- **Configure Nodes**:
- - **Chat Trigger**: Set up the webhook to receive user messages.
- - **Routing Agent (AI Agent)**: Define the system message with model strengths and JSON output rules.
- - **OpenRouter Chat Model**: Connect to OpenRouter for model access.
- - **Structured Output Parser**: Ensure it validates the JSON response format (`prompt` + `model`).
- - **Execution Agent (AI Agent1)**: Configure it to forward the prompt to the selected model.
2. **Connect Nodes**: - Link the **Chat Trigger** to the **Routing Agent**. - Connect the **OpenRouter Chat Model** and **Output Parser** to the **Routing Agent**. - Route the parsed JSON to the **Execution Agent**, which uses the chosen model via **OpenRouter Chat Model1**.
3. **Credentials**: - Ensure **OpenRouter API credentials** are correctly set for both chat model nodes.
4. **Test & Deploy**: - Activate the workflow and test with sample queries to verify model selection logic. - Adjust the routing rules if needed for better accuracy.
---
**Need help customizing?** [Contact me](mailto:info@n3w.it) for consulting and support or add me on [Linkedin](https://www.linkedin.com/in/davideboizza/).
⚡ How to import this workflow into n8n:
- Click the Direct Download JSON button above to save
Dynamic_AI_model_router_for_query_optimization_with_OpenRouter.json. - Log in to your n8n Cloud or self-hosted n8n instance.
- In your workflow canvas, click the menu in top-right and select Import from File (or paste the JSON directly).
- Configure your credentials (e.g. API keys, database URLs) in the corresponding node settings.
- Click Execute Workflow to test and switch to Active!
Related AI Agents Workflows
View All in AI Agents →5 ways to process images PDFs with Gemini AI in n8n
How it works Many users have asked in the support forum about different methods to analyze images and PDF documents with Google Gemini AI in n8n. This workfl...
7 AI Sales Assistant
Production-ready n8n automation template for 7 AI Sales Assistant built by AhiXLight. Seamlessly connects Airtop Tool, Slack, Airtop with 24 configured nodes.
AAVE portfolio professional AI agent Telegram Email GPT 4o
A next-generation AI-powered DeFi health monitor that tracks wallet positions across Aave V3 using GPT-4o and LangChain. It delivers human-readable reports v...
Access control for AI agents RBAC using Airtable and Telegram
Purpose This workflow allows granular control over the access to tools connected to AI Agents (including Multi-Agent setups) using Role Based Access Control....