Use this advanced n8n workflow to deploy a dynamic AI assistant powered by Anthropic's Claude Sonnet 4 and Opus 4. It includes intelligent routing, web search, memory, and tool integration, leveraging multiple n8n node types for optimal performance.
Download this n8n workflow template and start using it instantly.
This automation solves the challenge of optimizing resource usage and latency when interacting with expensive, powerful large language models like Anthropic Opus 4. Instead of sending every query to the highest-tier model, this intelligent n8n workflow uses a dedicated routing agent to analyze the user's prompt.
If the request is complex, critical, or requires deep reasoning (as defined in the system prompt), it is routed to Opus 4. For standard, routine tasks, it uses Sonnet 4. This robust decision-making is implemented entirely using n8n node architecture and LangChain concepts, providing an efficient and flexible AI solution. This powerful n8n template showcases complex conditional logic and tool integration, making it an essential resource for advanced automation.
This high-level n8n workflow operates in a multi-stage process:
When chat message received n8n trigger, which captures the user's input and session ID.Anthropic Routing Agent. This specialized n8n agent uses a Sonnet 3.7 model and highly specific system instructions to determine whether the user query requires the complexity of Opus 4 or the efficiency of Sonnet 4.Structured Output Parser n8n node validates and extracts the routing agent's decision, ensuring the output contains a clean prompt and the selected model name in JSON format.AI Agent n8n node. This agent is configured to dynamically load the selected model (Sonnet 4 or Opus 4) and utilizes multiple tools, including websearch, Think, and Calculator.Simple Memory1 (Buffer Window) to maintain conversation context across multiple turns. If the query is factual or requires current information, the agent's system prompt directs it to utilize the websearch tool.To deploy this comprehensive n8n template, follow these steps:
NNTZAD0Gmf7lcniq in the provided JSON. Replace this with your valid API key credentials across all nodes that require it (Sonnet 4 or Opus 4, Sonnet 3.7, and web_search).When chat message received n8n trigger is correctly linked to your chat application endpoint (e.g., Slack, custom chat interface).This advanced n8n workflow utilizes several key nodes:
When chat message received (n8n trigger):
Function: Serves as the starting point, listening for incoming messages from a user interface (e.g., Slack or custom endpoint).
Key Configuration: A webhook ID is configured to receive incoming chat messages.
Anthropic Routing Agent (n8n node):
Function: A crucial LangChain agent responsible for analyzing the user query and selecting the optimal Anthropic model (Opus 4 or Sonnet 4) to handle the request.
Key Configuration: System message explicitly defines model strengths and strictly mandates a JSON output format.
Structured Output Parser (n8n node):
Function: Guarantees that the output from the Routing Agent conforms to a strict JSON schema (containing prompt and model fields), ensuring reliability for the subsequent n8n node.
AI Agent (n8n node):
Function: The primary execution agent. It dynamically receives the selected Anthropic model name and the user prompt, then orchestrates the use of connected tools and memory.
Key Configuration: The model parameter is set dynamically using an expression: ={{ $json.output.model }}.
Sonnet 4 or Opus 4 (n8n node):
Function: The dynamic Anthropic language model node. It executes the final generation using the model selected by the routing agent.
Key Configuration: Model selection is driven by the dynamic expression: ={{ $json.output.model }}.
web_search (n8n node):
Function: An HTTP Request Tool configured to perform web searches, vital for providing up-to-date information within the primary AI Agent's thought process.
* Key Configuration: Configured to interact with the Anthropic API, passing the search query and the dynamically selected model.
Build a powerful RAG (Retrieval-Augmented Generation) chatbot using n8n that processes PDFs from Google Drive, indexes them in Pinecone, and answers WhatsApp queries automatically. Use this n8n workflow template.

Automate real estate inquiries using a powerful n8n workflow. Scrape PropertyFinder links, use SerpAPI for public data, and power your context-aware AI agent with OpenRouter. Get this n8n template today.

Deploy a powerful n8n workflow to create a Telegram chatbot that performs factual web searches using Tavily and summarizes reliable answers using the GPT-5 model for fast, grounded replies.

Use this complex n8n workflow to intelligently query AppSheet data using conversational AI, dynamic schema analysis, and Cohere reranking for precise results. Discover advanced n8n templates.

Full-stack Web Developer based in Italy specialising in Marketing & AI-powered automations. For business enquiries, send me an email at [email protected] or add me on Linkedin.com/in/davideboizza







































