See llms.txt for all machine-readable content.

Back to Templates

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

  1. Receives a chat request via an n8n Chat Trigger webhook.
  2. Normalizes the incoming payload, extracting the user request text and session ID and adding a timestamp.
  3. Scores the request for domain hints, complexity, and guardrail risks (empty, oversized, or prompt-injection markers) and assigns a routing tier.
  4. If the request is blocked, returns a guardrail message without calling any language model.
  5. If the request is simple, uses OpenRouter with shared session memory to generate a concise response.
  6. 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.
  7. 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.
  8. Returns the final reply along with telemetry fields (route, domain, complexity score, risk level, and timestamps) as the chat response.

Setup

  1. Add an OpenRouter API credential and select it for all OpenRouter Chat Model nodes used by the fast, specialist, orchestrator, and tool agents.
  2. Confirm the configured OpenRouter models (including openai/gpt-4.1 for the orchestrator tier) are available to your OpenRouter account.
  3. Enable the workflow and use the Chat Trigger test/production URL to send messages into the workflow from your chat client or integration.