n8n × AI Agent Integration— Building Local Workflow Automation with Claude and Gemini
A comprehensive guide to integrating n8n with AI agents to build secure, locally-hosted business automation pipelines. Covers self-hosted setup, Claude/Gemini/OpenAI node integration, and three real-world workflow patterns: email classification, weekly reports, and SNS scheduling.
When I first tried to automate workflows across multiple services in my indie dev projects, the cost was the first wall I hit. Zapier's paid plans start at $29/month, Make at $16/month — hard to justify for small projects.
That's when I discovered n8n (pronounced "en-eight-en"). It's open source, and when self-hosted, your only cost is the server. With its recently expanded AI agent integration features, it's now the backbone of my development automation stack. Here's how to build it.
What n8n Is — And Where It Beats Zapier and Make
n8n is a "fair-code" licensed workflow automation tool with a visual GUI for building flows and integrations with 400+ services. The biggest difference from Zapier and Make is data flexibility. n8n lets you run arbitrary JavaScript or Python inside workflows, with no constraints on data transformation. And since self-hosted means your data stays on your server, it's a solid choice for workflows handling sensitive information.
To be honest about the downsides: the UI is more complex than Zapier, and there's a learning curve. For a simple 2-step automation, Zapier might get you there faster. n8n shines when complex branching, data transformation, and AI integration come together.
✦
Thank you for reading this far.
Continue Reading
What follows includes implementation code, benchmarks, and practical content we hope you'll find useful. This site runs without ads — server and development costs are supported entirely by members like you. If it's been helpful, we'd be truly grateful for your support.
WHAT YOU'LL LEARN
✦Step-by-step instructions for self-hosting n8n locally or on a VPS with Docker Compose, including production Nginx setup
✦Integrating Claude, Gemini, and OpenAI as n8n nodes to trigger natural language AI processing in your workflows
✦Three real-world automation patterns: email classification, weekly report generation, and SNS post scheduling
Secure payment via Stripe · Cancel anytime
✦
Unlock This Article
Get full access to the rest of this article. Buy once, read anytime. This site is ad-free — your support goes directly toward keeping it running.
That's it — n8n is available at http://localhost:5678. For production, add Nginx as a reverse proxy and enable HTTPS with Let's Encrypt.
Production Deployment on a $6/Month VPS
My current setup: DigitalOcean $6/month Droplet (1vCPU / 1GB RAM) + Nginx + Let's Encrypt. n8n itself can run on 512MB RAM, but if you're processing large datasets through AI nodes, 1GB or more is recommended.
n8n's AI nodes expanded significantly in late 2024. You can now integrate Claude, Gemini, and OpenAI as workflow nodes, with full AI agent orchestration built into n8n itself.
Claude Integration Setup
Register your Anthropic API key in n8n Credentials, then add an "Anthropic Chat Model" node to your workflow. Here's an example of generating dynamic prompts with n8n's Code node:
// Generate dynamic prompt in n8n Code nodeconst emailBody = $json.email_body;const sender = $json.sender_name;return { prompt: `Classify the following email.Sender: ${sender}Body: ${emailBody}Return category (support/sales/other) and priority (high/medium/low) as JSON.Format: {"category": "...", "priority": "...", "summary": "..."}`};
Real Workflow 1: Automated Email Classification
This is a workflow I actually run in production:
Gmail Trigger (new email)
│
├─ Filter: Remove spam and promotions
│
├─ Claude Node: Analyze and classify email content
│ Prompt: Return category, priority, summary as JSON
│
├─ Switch Node: Branch by category
│ ├─ Support → Create ticket in Notion database
│ ├─ Sales → Post to Slack #sales channel
│ └─ Other → Apply Gmail label only
│
└─ Completion notification
The key implementation detail: specify the return format as strict JSON. Vague format instructions will cause parsing failures in downstream nodes.
Real Workflow 2: Weekly Report Auto-Generation
Scheduler (every Monday at 9:00)
│
├─ Google Analytics Node: Fetch last week's traffic data
├─ Google Search Console: Fetch search performance data
├─ Notion Node: Fetch completed task count for last week
│
├─ Code Node: Format data and compose prompt
│
├─ Gemini Node: Generate report body
│ (Gemini 2.5 Pro handles long-form generation well)
│
└─ Gmail Node: Send report to self
Real Workflow 3: SNS Post Scheduling
Notion Trigger (new content item added)
│
├─ Claude Node: Optimize copy for each platform
│ ├─ X (Twitter): Under 280 characters
│ ├─ LinkedIn: Professional tone
│ └─ Instagram: Hashtag optimization
│
├─ Approval step (Review in Slack → Button approval)
│
└─ Buffer / Hootsuite Node: Schedule posts to each platform
Using n8n's AI Agent Mode
Recent versions of n8n include an "AI Agent" node that goes beyond simple LLM calls to enable autonomous agents within your workflows:
AI Agent Node
├─ System Prompt: "You are a data analysis agent. Use tools to..."
├─ Tools: Calculator, HTTP Request, Code Executor
└─ Model: Claude 3.5 Sonnet
The agent decides on its own: "I need to calculate this, so I'll use the Calculator" or "I need more data, so I'll fetch via HTTP." I use this for content research collection workflows.
3 Security Lessons I Learned the Hard Way
1. Randomize your webhook URL paths
Leaving the default /webhook/ path exposed will get it hammered by scanners. Use random strings like /webhook/a7f3k9m2b6/.
2. Manage API keys through Credentials or environment variables
Never hardcode API keys directly inside workflow nodes. Use n8n's Credentials feature or .env files.
3. Set up regular backups
The n8n_data volume contains all your workflows and credentials. Run a separate n8n workflow to back it up to S3 or Backblaze B2 every day.
A Note from an Indie Developer
Where to Go Next
Once your n8n foundation is solid, try building custom nodes. Any service not covered by existing integrations can be wrapped as an n8n node in Node.js. Also worth evaluating: n8n Cloud (paid, but zero maintenance) vs. self-hosted — weigh the cost against the ops burden based on your situation.
Automation isn't "set it and forget it" — it's something you grow over time. Start small, verify behavior, and gradually add complexity. That's the approach that actually sticks.
Workflow examples in this guide were tested on n8n v1.x. UI and node names may differ across versions.
Share
Thank You for Reading
Antigravity Lab is ad-free, supported entirely by members like you. We publish practical guides daily with implementation code, benchmarks, and production-ready patterns. If you've found it useful, we'd love to have you on board.