Skip to main content

AI-powered Gmail assistant: send replies by analyzing thread ID with Sonnet 4.5

Workflow preview

Workflow preview
100%
AI-powered Gmail assistant: send replies by analyzing thread ID with Sonnet 4.5 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 automates analyzing Gmail threads and drafting AI powered replies with the new model Anthropic Sonnet 4.5 . This workflow automates the process of analyzing incoming emails and genera...

Best for

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

Tools used

n8n-nodes-base.gmailtrigger, n8n-nodes-base.gmail, n8n-nodes-base.merge, @n8n/n8n-nodes-langchain.lmchatopenai, @n8n/n8n-nodes-langchain.textclassifier, @n8n/n8n-nodes-langchain.agent, n8n-nodes-base.code, @n8n/n8n-nodes-langchain.lmchatanthropic

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
AI-powered Gmail assistant: send replies by analyzing thread ID with Sonnet 4.5
Workflow name
AI-powered Gmail assistant: send replies by analyzing thread ID with Sonnet 4.5

This workflow automates analyzing Gmail threads and drafting AI-powered replies with the new model Anthropic Sonnet 4.5.

This workflow automates the process of analyzing incoming emails and generating context-aware draft replies by examining the entire email thread.


Key Advantages

  • Time-Saving – Automates repetitive email replies, reducing manual workload.
  • Context-Aware Responses – Replies are generated using the entire email thread, not just the latest message.
  • Smart Filtering – The classifier prevents unnecessary drafts for spam or promotional emails.
  • Human-in-the-Loop – Drafts are created instead of being sent immediately, allowing manual review and corrections.
  • Scalable & Flexible – Can be adapted to different accounts, reply styles, or workflows.
  • Seamless Gmail Integration – Directly interacts with Gmail threads and drafts via OAuth.

How it Works

This workflow automates the process of analyzing incoming emails and generating context-aware draft replies by examining the entire email thread.

  1. Trigger & Initial Filtering: The workflow is automatically triggered every minute by the Gmail Trigger node, which detects new emails. For each new email, it immediately performs a crucial first step: it uses an AI Email Classifier to analyze the email snippet. The AI determines if the email is a legitimate message that warrants a reply (categorized as "ok") or if it's spam, a newsletter, or an advertisement. This prevents the system from generating replies for unwanted emails.

  2. Context Aggregation: If an email is classified as "ok," the workflow fetches the entire conversation thread from Gmail using the threadId. A Code Node then processes all the messages in the thread, structuring them into a consistent format that the AI can easily understand.

  3. AI-Powered Draft Generation: The structured conversation history is passed to the Replying email Agent with Sonnet 4.5. This agent, powered by a language model, analyzes the entire thread to understand the context and the latest inquiry. It then drafts a relevant and coherent HTML email reply. The system prompt instructs the AI not to invent information and to use placeholders for any missing details.

  4. Draft Creation: The final step takes the AI-generated reply and the original email's metadata (subject, recipient, threadId) and uses them to create a new draft email in Gmail. This draft is automatically placed in the correct email thread, ready for the user to review and send.


Set up Steps

To implement this automated email reply system, you need to configure the following:

  1. Configure Gmail & OpenAI Credentials: Ensure the following credentials are set up in your n8n instance:

    • Gmail OAuth2 Credentials: The workflow uses the same Gmail account for the trigger, fetching threads, and creating drafts. Configure this in the "Gmail Trigger," "Get a thread," and "Create a draft" nodes.

    • OpenAI API Credentials: Required for both the "Email Classifier". Provide your API key in the respective OpenAI Chat Model nodes.

    • Anthropic API Credentials: Required for the main "Replying email Agent." Provide your API key in the respective Antrhopic Chat Model nodes.

  2. Review AI Classification & Prompting:

    • Email Filtering: Check the categories in the Email Classifier node. The current setup marks only non-advertising, non-newsletter emails as "ok." You can modify these categories to fit your specific needs and reduce false positives.
    • Reply Agent Instructions: Review the system message in the Replying email Agent. You can customize the AI's persona, tone, and instructions (e.g., making it more formal, or instructing it to sign with a specific name) to better align with your communication style.

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 - Gmail Trigger

Type / Role
n8n-nodes-base.gmailTrigger - gmailTrigger
Config choices
Version 1.3

Block 2 - Get a thread

Type / Role
n8n-nodes-base.gmail - gmail
Config choices
Version 2.1

Block 3 - Create a draft

Type / Role
n8n-nodes-base.gmail - gmail
Config choices
Version 2.1

Block 4 - Merge

Type / Role
n8n-nodes-base.merge - merge
Config choices
Version 3.2

Block 5 - OpenAI Chat Model1

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

Block 6 - Email Classifier

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

Block 7 - Replying email Agent

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

Block 8 - Code

Type / Role
n8n-nodes-base.code - code
Config choices
Version 2

Block 9 - Anthropic Sonnet 4.5

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

Block 10 - Sticky Note

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

Block 11 - Sticky Note1

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

3. Summary Table

Workflow AI-powered Gmail assistant: send replies by analyzing thread ID with Sonnet 4.5
Complexity intermediate
Nodes 11
Categories AI Chatbot
Author Davide
Published 02 Oct 2025

4. Reproducing the Workflow from Scratch

  1. 1. Download the workflow JSON

    Use the JSON export at /data/workflows/9193/9193.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 AI-powered Gmail assistant: send replies by analyzing thread ID with Sonnet 4.5 do?

This workflow automates analyzing Gmail threads and drafting AI powered replies with the new model Anthropic Sonnet 4.5 . This workflow automates the process of analyzing incoming emails and genera...

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 AI Chatbot use case.