Route AI tasks between Anthropic Claude models with Postgres policies and SLA
Ready for 3.0What this workflow does
This AI workflow has 20 nodes and runs when an HTTP POST request hits its webhook URL (plus 1 other trigger). Along the way it connects Postgres and Anthropic Chat Model.
How it runs
Trigger: When an HTTP POST request hits its webhook URL (plus 1 other trigger).
- Workflow Configuration (Edit Fields (Set)): sets 5 fields: maxLatencyMs, costCeiling, timeoutMs…
- Fetch Historical Data (Postgres): run a query
- Task Classifier Agent (AI Agent): runs an AI agent, with model: Anthropic Chat Model; output parser: Classification Output Parser
- Aggregate: combines items into one
- Load Policy Rules (Postgres): run a query
- Calculate Routing Adjustments (Code): runs custom JavaScript code
- Policy Engine Decision (Code): runs custom JavaScript code
- Update Policy Rules (Postgres): run a query
- Route by Model Selection (Switch): routes items into 2 branches
- Small Model Execution (AI Agent): runs an AI agent, with model: Anthropic Chat Model
…plus 4 more steps. See the full node list below.
Services it uses
Before you upgrade to n8n 3.0
Nothing in this workflow is removed in n8n 3.0, so it should import and run after the upgrade.
Nodes used (11)
- Webhook
n8n-nodes-base.webhook - Edit Fields (Set)
n8n-nodes-base.set - AI Agent
@n8n/n8n-nodes-langchain.agent - Postgres
n8n-nodes-base.postgres - Code
n8n-nodes-base.code - Switch
n8n-nodes-base.switch - Respond to Webhook
n8n-nodes-base.respondToWebhook - Schedule Trigger
n8n-nodes-base.scheduleTrigger - Aggregate
n8n-nodes-base.aggregate - Anthropic Chat Model
@n8n/n8n-nodes-langchain.lmChatAnthropic - Structured Output Parser
@n8n/n8n-nodes-langchain.outputParserStructured
From the author
Overview This workflow implements a policy-driven LLM orchestration system that dynamically routes AI tasks to different language models based on task complexity, policies, and performance constraints. Instead of sending every request to a single model, the…