Skip to main content

Anthropic AI agent: Claude Sonnet 4 and Opus 4 with Think and Web Search tool

Workflow preview

Workflow preview
100%
Anthropic AI agent: Claude Sonnet 4 and Opus 4 with Think and Web Search tool preview
Open on n8n.io

Important notice

This workflow is provided as-is. Please review and test before using in production.

1. Workflow Overview

This workflow dynamically chooses between two new powerful Anthropic models — Claude Opus 4 and Claude Sonnet 4 — to handle user queries, based on their complexity and nature, maintaining scalabili...

Best for

  • Engineering automation workflows
  • AI Chatbot automation workflows
  • intermediate n8n builders looking for reusable templates

Tools used

@n8n/n8n-nodes-langchain.chattrigger, @n8n/n8n-nodes-langchain.outputparserstructured, n8n-nodes-base.stickynote, @n8n/n8n-nodes-langchain.agent, @n8n/n8n-nodes-langchain.toolthink, @n8n/n8n-nodes-langchain.toolcalculator, @n8n/n8n-nodes-langchain.lmchatanthropic, @n8n/n8n-nodes-langchain.memorybufferwindow

Source and attribution

This workflow is cataloged by N8N Workflows and links back to its original n8n.io source page by Davide.

Original n8n.io source

1.1 Workflow description

Title
Anthropic AI agent: Claude Sonnet 4 and Opus 4 with Think and Web Search tool
Workflow name
Anthropic AI agent: Claude Sonnet 4 and Opus 4 with Think and Web Search tool

This workflow dynamically chooses between two new powerful Anthropic models — Claude Opus 4 and Claude Sonnet 4 — to handle user queries, based on their complexity and nature, maintaining scalability and context awareness with Anthropic web search function and Think tool.


Key Advantages

  1. 🔁 Dynamic Model Selection

    • Automatically routes each user query to either Claude Sonnet 4 (for routine tasks) or Claude Opus 4 (for complex reasoning), ensuring optimal performance and cost-efficiency.
  2. 🧠 AI Agent with Tool Use

    • The AI agent can utilize a web search tool to retrieve up-to-date information and a Think tool for complex reasoning processes — improving response quality.
  3. 📎 Memory Integration

    • Uses session-based memory to maintain conversational context, making interactions more coherent and human-like.
  4. 🧮 Built-in Calculation Tool

    • Handles numeric queries using an integrated calculator tool, reducing the need for external processing.
  5. 📤 Structured Output Parser

    • Ensures outputs are always well-structured and formatted in JSON, which improves consistency and downstream integrations.
  6. 🌐 Web Search Capability

    • Supports real-time information retrieval for current events, statistics, or details not available in the AI’s base knowledge.

Components Overview

  • Trigger: Listens for new chat messages.

  • Routing Agent: Analyzes the message and returns the best model to use.

  • AI Agent: Handles the conversation, decides when to use tools.

  • Tools:

    • web_search for internet queries
    • Think for reasoning
    • Calculator for math tasks
  • Models Used:

    • claude-sonnet-4-20250514: Optimized for general and business logic tasks.
    • claude-opus-4-20250514: Best for deep, strategic, and analytical queries.

How It Works

  1. Dynamic Model Selection

    • The workflow begins when a chat message is received. The Anthropic Routing Agent analyzes the user's query to determine the most suitable model (either Claude Sonnet 4 or Claude Opus 4) based on the query's complexity and requirements.
    • The routing agent uses predefined criteria to decide:
      • Claude Sonnet 4: Best for standard tasks like real-time workflow routing, data validation, and routine business logic.
      • Claude Opus 4: Reserved for complex scenarios requiring deep reasoning, advanced analysis, or high-impact decisions.
  2. Query Processing and Response Generation

    • The selected model processes the query, leveraging tools like web_search for real-time information retrieval, Think for internal reasoning, and Calculator for numerical tasks.
    • The AI Agent coordinates these tools, ensuring the response is accurate and context-aware. A Simple Memory node retains session context for coherent multi-turn conversations.
    • The final response is formatted and returned to the user without intermediate steps or metadata.

Set Up Steps

  1. Node Configuration

    • Trigger: Configure the "When chat message received" node to handle incoming user queries.
    • Routing Agent: Set up the "Anthropic Routing Agent" with the system message defining model selection logic. Ensure it outputs a JSON object with prompt and model fields.
    • AI Model Nodes: Link the "Sonnet 4 or Opus 4" node to dynamically use the selected model. The "Sonnet 3.7" node powers the routing agent itself.
  2. Tool Integration

    • Attach the "web_search" HTTP tool to enable internet searches, ensuring the API endpoint and headers (e.g., anthropic-version) are correctly configured.
    • Connect auxiliary tools (Think, Calculator) to the "AI Agent" for extended functionality.
    • Add the "Simple Memory" node to maintain conversation history.
  3. Credentials

    • Provide an Anthropic API key to all nodes requiring authentication (e.g., model nodes, web search).
  4. Testing

    • Activate the workflow and test with sample queries to verify:
      • Correct model selection (e.g., Sonnet for simple queries, Opus for complex ones).
      • Proper tool usage (e.g., web searches trigger when needed).
      • Memory retention across chat turns.
  5. Deployment

    • Once validated, set the workflow to active for live interactions.

Need help customizing?

Contact me for consulting and support or add me on Linkedin.

1.2 Logical Blocks

This catalog entry is organized from the workflow JSON. The node-level section below shows the executable blocks available for review before importing the template.

2. Block-by-Block Analysis

Block 1 - When chat message received

Type / Role
@n8n/n8n-nodes-langchain.chatTrigger - chatTrigger
Config choices
Version 1.1

Block 2 - Structured Output Parser

Type / Role
@n8n/n8n-nodes-langchain.outputParserStructured - outputParserStructured
Config choices
Version 1.2

Block 3 - Sticky Note

Type / Role
n8n-nodes-base.stickyNote - stickyNote
Config choices
Version 1

Block 4 - AI Agent

Type / Role
@n8n/n8n-nodes-langchain.agent - agent
Config choices
Version 1.9

Block 5 - Think

Type / Role
@n8n/n8n-nodes-langchain.toolThink - toolThink
Config choices
Version 1

Block 6 - Calculator

Type / Role
@n8n/n8n-nodes-langchain.toolCalculator - toolCalculator
Config choices
Version 1

Block 7 - Anthropic Routing Agent

Type / Role
@n8n/n8n-nodes-langchain.agent - agent
Config choices
Version 1.9

Block 8 - Sonnet 4 or Opus 4

Type / Role
@n8n/n8n-nodes-langchain.lmChatAnthropic - lmChatAnthropic
Config choices
Version 1.3

Block 9 - Sonnet 3.7

Type / Role
@n8n/n8n-nodes-langchain.lmChatAnthropic - lmChatAnthropic
Config choices
Version 1.3

Block 10 - Simple Memory1

Type / Role
@n8n/n8n-nodes-langchain.memoryBufferWindow - memoryBufferWindow
Config choices
Version 1.3

Block 11 - web_search

Type / Role
n8n-nodes-base.httpRequestTool - httpRequestTool
Config choices
Version 4.2

3. Summary Table

Workflow Anthropic AI agent: Claude Sonnet 4 and Opus 4 with Think and Web Search tool
Complexity intermediate
Nodes 11
Categories Engineering, AI Chatbot
Author Davide
Published 26 May 2025

4. Reproducing the Workflow from Scratch

  1. 1. Download the workflow JSON

    Use the JSON export at /data/workflows/4399/4399.json as the source template for this automation.

  2. 2. Import the template into n8n

    Open n8n, import the downloaded JSON, and review each node before activating the workflow.

  3. 3. Configure credentials and variables

    Replace placeholder credentials, API keys, webhook URLs, account IDs, and environment-specific values with your own settings.

  4. 4. Test with sample data

    Run the workflow manually or in a staging workspace, inspect node output, and confirm downstream systems receive the expected data.

  5. 5. Activate and monitor

    Enable the workflow only after testing, then monitor executions, errors, and rate limits during the first production runs.

5. General Notes & Resources

Review imported nodes carefully before activation. This catalog entry is intended to help you inspect the workflow structure, understand required services, and find related templates faster.

Node names, credentials, schedules, webhook paths, and external service limits may need adjustment for your workspace.

Frequently asked questions

What does Anthropic AI agent: Claude Sonnet 4 and Opus 4 with Think and Web Search tool do?

This workflow dynamically chooses between two new powerful Anthropic models — Claude Opus 4 and Claude Sonnet 4 — to handle user queries, based on their complexity and nature, maintaining scalabili...

What do I need before importing this workflow?

Review the workflow JSON, configure any required credentials in n8n, and test the automation in a safe workspace before using it in production.

Can I customize this workflow?

Yes. Use the block-by-block analysis and the downloadable JSON to inspect each node, then adjust credentials, prompts, schedules, filters, or destinations for your Engineering, AI Chatbot use case.