Anthropic AI agent Claude Sonnet 4 and Opus 4 with Think and We
This workflow dynamically chooses between two new powerful Anthropic models — Claude Opus 4 and Claude Sonnet 4 — to handle user queries, based on their comp...
🔌 Nodes & Integrations Used (8)
📖 Implementation & Setup Guide
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**
- **🔁 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](mailto:info@n3w.it) for consulting and support or add me on [Linkedin](https://www.linkedin.com/in/davideboizza/).
⚡ How to import this workflow into n8n:
- Click the Direct Download JSON button above to save
Anthropic_AI_agent_Claude_Sonnet_4_and_Opus_4_with_Think_and_We.json. - Log in to your n8n Cloud or self-hosted n8n instance.
- In your workflow canvas, click the menu in top-right and select Import from File (or paste the JSON directly).
- Configure your credentials (e.g. API keys, database URLs) in the corresponding node settings.
- Click Execute Workflow to test and switch to Active!
Related AI Agents Workflows
View All in AI Agents →5 ways to process images PDFs with Gemini AI in n8n
How it works Many users have asked in the support forum about different methods to analyze images and PDF documents with Google Gemini AI in n8n. This workfl...
7 AI Sales Assistant
Production-ready n8n automation template for 7 AI Sales Assistant built by AhiXLight. Seamlessly connects Airtop Tool, Slack, Airtop with 24 configured nodes.
AAVE portfolio professional AI agent Telegram Email GPT 4o
A next-generation AI-powered DeFi health monitor that tracks wallet positions across Aave V3 using GPT-4o and LangChain. It delivers human-readable reports v...
Access control for AI agents RBAC using Airtable and Telegram
Purpose This workflow allows granular control over the access to tools connected to AI Agents (including Multi-Agent setups) using Role Based Access Control....