Route chat requests through tiered AI agents using OpenRouter and LangChain
Quick Overview This workflow provides a tiered chat assistant that validates each request, scores it for domain, complexity, and risk, then routes it to a fast OpenRouter model, a domain-specialist OpenRouter model, or a multi-agent OpenRouter orchestrator with critic and scenario simulation tools.
How it works Receives a chat request via an n8n Chat Trigger webhook. Normalizes the incoming payload, extracting the user request text and session ID and adding a timestamp. Scores the request for domain hints, complexity, and guardrail risks (empty, oversized, or prompt-injection markers) and assigns a routing tier. If the request is blocked, returns a guardrail message without calling any language model. If the request is simple, uses OpenRouter with shared session memory to generate a concise response. If the request matches a domain (code, legal, finance, bio, or science), uses an OpenRouter domain-specialist agent with shared session memory to produce a structured answer. If the request is complex, uses an OpenRouter orchestrator that plans the work and can consult a specialist sub-agent, a critic, a scenario simulator, Wikipedia, and a calculator before returning the final response. Returns the final reply along with telemetry fields (route, domain, complexity score, risk level, and timestamps) as the chat response.
Setup Add an OpenRouter API credential and select it for all OpenRouter Chat Model nodes used by the fast, specialist, orchestrator, and tool agents. Confirm the configured OpenRouter models (including openai/gpt-4.1 for the orchestrator tier) are available to your OpenRouter account. Enable the workflow and use the Chat Trigger test/production URL to send messages into the workflow from your chat client or integration.
Related Templates
Get Airtable data via AI and Obsidian Notes
I am submitting this workflow for the Obsidian community to showcase the potential of integrating Obsidian with n8n. Whi...
Text automations using Apple Shortcuts
Overview This workflow answers user requests sent via Mac Shortcuts Several Shortcuts call the same webhook, with a quer...
AI SEO Readability Audit: Check Website Friendliness for LLMs
Who is this for? This workflow is designed for SEO specialists, content creators, marketers, and website developers who ...
🔒 Please log in to import templates to n8n and favorite templates
Workflow Visualization
Loading...
Preparing workflow renderer
Comments (0)
Login to post comments