AGENT INCOME .IO

AI agents, agentic coding, and passive income.

n8n Tutorial 2026: Build AI Agents That Actually Do Work


If you’ve been building AI agents with Python and wondering why gluing together API clients feels like plumbing — n8n is worth thirty minutes of your time.

n8n is a self-hostable workflow automation platform with native AI agent support. It has 400+ built-in integrations, a visual editor, and lets you drop into JavaScript or Python when you need actual logic. More importantly, it runs on your own hardware, your data stays yours, and the community tier is free.

This tutorial gets you from zero to a running AI agent workflow. No fluff.

What You’re Building

By the end of this, you’ll have:

  1. n8n running locally (or on a VPS)
  2. An AI Agent node connected to a real LLM
  3. Tools the agent can call (web search + HTTP requests)
  4. A trigger that fires the workflow on a schedule or webhook

This is the foundation. From here you can extend it into anything — email triage, customer support, content pipelines, data enrichment. The pattern is the same.

Install n8n

The fastest path is Docker. If you already have Docker installed:

docker run -it --rm \
  --name n8n \
  -p 5678:5678 \
  -v ~/.n8n:/home/node/.n8n \
  n8nio/n8n

Open http://localhost:5678 and create your account. That’s it — you’re in.

For a persistent self-hosted setup (recommended if you’re running this for anything real), use Docker Compose:

version: "3.8"
services:
  n8n:
    image: n8nio/n8n
    restart: always
    ports:
      - "5678:5678"
    environment:
      - N8N_BASIC_AUTH_ACTIVE=true
      - N8N_BASIC_AUTH_USER=admin
      - N8N_BASIC_AUTH_PASSWORD=changeme
      - WEBHOOK_URL=https://your-domain.com
    volumes:
      - n8n_data:/home/node/.n8n

volumes:
  n8n_data:

Run it with:

docker compose up -d

If you want this on a VPS, Railway and Render both support one-click Docker deploys. n8n’s official docs also have a self-hosting guide covering nginx, SSL, and production hardening.

Connect Your LLM

Once you’re inside n8n:

  1. Go to Settings → Credentials
  2. Click New credential
  3. Search for “OpenAI” or “Anthropic” — both are supported natively
  4. Paste your API key

For Anthropic (Claude), the credential type is Anthropic API. If you’re running local models, n8n also supports Ollama — point it at http://localhost:11434 and you’re off. See our self-hosted AI tools guide for the full local stack.

Build Your First AI Agent Workflow

In n8n, everything is a workflow. A workflow is a chain of nodes. Here’s the structure for a useful AI agent:

[Trigger] → [AI Agent] → [Output / Action]
         ↑         ↓
         └── [Tools] ──┘

Step 1: Add a Trigger

Click + to add a node. For testing, use Manual Trigger — you click “Execute” and it runs. For production, use:

  • Schedule Trigger — runs on a cron schedule
  • Webhook — fires when something POSTs to a URL
  • Email Trigger — fires on incoming email (IMAP)

Step 2: Add the AI Agent Node

Search for AI Agent in the node picker. This is n8n’s built-in LangChain-backed agent node. Configure it:

  • Model: select your Anthropic or OpenAI credential
  • System message: write your agent’s persona and instructions here
  • Memory: enable “Window Buffer Memory” to give the agent short-term context

A simple system prompt that works:

You are a research assistant. When given a topic, search for recent information,
summarize the key points, and return a structured report. Be concise and factual.

Step 3: Give the Agent Tools

This is where n8n gets powerful. Under the AI Agent node, click Add Tool and connect:

  • HTTP Request Tool — lets the agent make arbitrary API calls
  • Code Tool — lets the agent run JavaScript
  • n8n Workflow Tool — lets the agent trigger other workflows (composable agents)
  • SerpAPI / Brave Search — web search integration

For a research agent, connect a search tool. For a data processing agent, the HTTP Request tool + Code tool combination handles almost any API integration.

Step 4: Add an Output Node

Connect an output after the agent:

  • Send Email (Gmail/SMTP) — email the results
  • HTTP Request — POST the output to another service or webhook
  • Slack / Discord — send a message to a channel
  • Google Sheets — write structured data to a spreadsheet
  • Airtable / Notion — update a database

For a starter workflow: Schedule Trigger → AI Agent → Send Email gives you a daily automated report on any topic you care about.

A Real Example: Daily News Digest Agent

Here’s a workflow that runs every morning at 7am, searches for news on a topic, and emails you a summary:

Nodes:

  1. Schedule Trigger0 7 * * * (7am daily)
  2. HTTP Request — GET https://newsapi.org/v2/top-headlines?q=AI+agents&apiKey=YOUR_KEY
  3. AI Agent (Claude claude-sonnet-4-5) — system prompt: “Summarize these news articles into 5 bullet points. Be direct. Skip fluff.”
  4. Send Email — Gmail credential, to your address

Total setup time: under 20 minutes. This is the same pattern as an AI automation agency workflow — except here you own the infrastructure.

Memory and State

By default, n8n AI Agent nodes are stateless — each execution starts fresh. For agents that need to remember context across runs:

Window Buffer Memory (built-in): keeps the last N messages in context. Good for chat-style agents where runs happen in sequence.

Postgres / Redis Memory: n8n supports external memory stores for persistent context across separate workflow executions. Configure this under the Memory section of the AI Agent node.

For workflows that need to track state between runs (e.g., “only process new items since last run”), use a Set node to write a timestamp to a static data store:

// In a Code node, read/write workflow static data
const lastRun = $getWorkflowStaticData('global').lastRun || 0;
$getWorkflowStaticData('global').lastRun = Date.now();
return [{ json: { lastRun } }];

Self-Hosted vs n8n Cloud

If you’re just testing: use n8n Cloud (free tier, no setup). For production or anything processing sensitive data: self-host.

Self-hosting reasons:

  • No execution limits
  • Data never leaves your machine
  • You control upgrades and rollbacks
  • Monthly cost is just your VPS (~$5-20/mo vs n8n Cloud $20+/mo for paid plans)

The n8n self-hosted AI starter kit on GitHub is a Docker Compose setup that includes n8n + Ollama + Qdrant (vector store) pre-wired. Clone it and you have a local AI stack in one docker compose up.

Connecting to the Claude API Directly

For workflows where you want fine-grained control — specific models, exact prompt construction, caching — skip the AI Agent node and use an HTTP Request node to call the Claude API directly:

POST https://api.anthropic.com/v1/messages
Headers:
  x-api-key: {{ $credentials.anthropic.apiKey }}
  anthropic-version: 2023-06-01
Body:
{
  "model": "claude-sonnet-4-5",
  "max_tokens": 1024,
  "messages": [{ "role": "user", "content": "{{ $json.prompt }}" }]
}

Map the response with a Set node: {{ $json.content[0].text }} and you have direct LLM integration without any abstraction layer.

Where n8n Fits in Your Agent Stack

n8n is a workflow orchestrator, not a full agent framework. It’s excellent for:

  • Trigger-driven automations with LLM steps baked in
  • Connecting APIs without writing glue code
  • Agents that read/write to real apps (email, Sheets, Slack, Notion)
  • Prototyping agent pipelines quickly before productionizing

It’s not the right tool when you need:

  • Complex multi-agent coordination (look at LangGraph for that)
  • Custom Python logic throughout the pipeline
  • Agents that run for hours with deep state management

For most “build something that makes money” use cases — a client-facing automation, a content pipeline, a data enrichment service — n8n covers 80% of what you need without writing a line of Python. That’s the point.

Monetizing n8n Workflows

The AI automation agency model is the direct play here: build workflows for clients, charge monthly retainers. n8n makes this practical because:

  • You can export workflows as JSON and re-deploy for each client
  • White-labeling is possible with a custom domain
  • You can spin up a new instance per client (isolation, billing)

Standard pricing for n8n automation services: $500-2,000/month per client depending on complexity. A single well-built email triage + CRM-update workflow justifies $500/month to a busy professional. Five clients is $2,500-10,000/month recurring.

The path: build it once, deploy it many times. That’s what makes this model work — see passive income from AI agents for more on the infrastructure side of that equation.

Next Steps