Beginner N8n Tutorial 6 min read

Building AI Workflows with n8n: No-Code Agent Automation

#n8n #workflow-automation #no-code #ai-agent #openai #webhook

What Is n8n?

n8n (pronounced “n-eight-n”) is an open-source workflow automation platform that lets you connect apps, APIs, and AI models through a visual drag-and-drop interface — no coding required. Think of it as Zapier or Make, but self-hostable, open-source, and with built-in AI agent capabilities.

For AI developers, n8n is powerful because it bridges the gap between LLMs and the rest of your tech stack. You can build an AI Agent workflow in minutes: the agent receives a trigger (a webhook, email, or schedule), reasons using an LLM, calls tools (search, database, API), and takes action — all without writing a Python script.

n8n is used by over 100,000 teams worldwide for workflows ranging from simple Slack notifications to complex multi-step AI pipelines.

n8n vs Python Frameworks

n8nPython (LangChain/CrewAI)
SetupVisual UI, minutesCode + dependencies
FlexibilityHigh (400+ integrations)Maximum (code anything)
AI integrationBuilt-in AI Agent nodeFull LLM control
Best forOps teams, rapid prototypesDev teams, custom logic
Self-hostedYesYes

Use n8n when you need to integrate AI with existing apps fast. Use Python frameworks when you need fine-grained control over model behavior.

Installing n8n

Option 1: npx (fastest, no install)

npx n8n

Open your browser at http://localhost:5678. This runs n8n with an SQLite database in your home directory.

Option 2: npm global install

npm install -g n8n
n8n start
docker run -it --rm \
  -p 5678:5678 \
  -v ~/.n8n:/home/node/.n8n \
  n8nio/n8n

Option 4: n8n Cloud

Sign up at n8n.io for a managed cloud instance — no infrastructure needed. A free tier is available.

Core Concepts

Workflow — A visual diagram of connected nodes. Runs automatically when triggered.

Node — A single step: a trigger, a transformation, or an action. n8n has 400+ built-in nodes (Slack, Gmail, PostgreSQL, HTTP, etc.).

Trigger Node — The start of every workflow. Can be a webhook, schedule, email, or manual click.

AI Agent Node — The AI brain of the workflow. Connects to an LLM (OpenAI, Anthropic, etc.) and can use tools defined in the workflow.

Your First AI Workflow: Chat Summarizer

This workflow takes an HTTP POST request with a body of text and returns a summary generated by GPT-4o-mini.

Step 1: Add a Webhook Trigger

  1. Open n8n at http://localhost:5678
  2. Create a new workflow
  3. Add a Webhook node
  4. Set Method: POST, Path: summarize
  5. Copy the webhook URL (e.g., http://localhost:5678/webhook/summarize)

Step 2: Add the OpenAI Node

  1. Add an OpenAI node after the Webhook
  2. Connect your OpenAI credential (API key)
  3. Resource: Text
  4. Operation: Complete
  5. Model: gpt-4o-mini
  6. Prompt: Summarize the following text in 3 bullet points: {{ $json.body.text }}

Step 3: Add a Respond to Webhook Node

  1. Add a Respond to Webhook node
  2. Response Body: {{ $json.message.content }}

Step 4: Test It

curl -X POST http://localhost:5678/webhook/summarize \
  -H "Content-Type: application/json" \
  -d '{"text": "LangChain is a framework for building LLM applications. It provides tools for chaining prompts, managing memory, and integrating with external data sources. It supports Python and JavaScript."}'

You should receive a 3-bullet summary back.

Building an AI Agent Workflow

The AI Agent node is n8n’s most powerful feature — it gives an LLM access to tools defined in your workflow. Here’s how to build an agent that can search the web and answer questions:

Node Setup

  1. Manual Trigger — Start workflow manually for testing
  2. AI Agent node:
    • Chat Model: OpenAI Chat Model (GPT-4o-mini)
    • System Prompt: “You are a helpful research assistant. Use the provided tools to answer questions accurately.”
  3. SerpAPI Tool (sub-node inside AI Agent) — enables web search
  4. Set node — format the final output

Connecting Tools

Inside the AI Agent node, click Add Tool and select:

  • HTTP Request Tool — lets the agent call any API
  • Code Tool — lets the agent run JavaScript
  • Wikipedia Tool — lets the agent look up Wikipedia articles

The agent decides which tool to call based on the question, calls it, observes the result, and continues until it has a complete answer.

Practical Example: Email-to-Action Agent

This workflow monitors a Gmail inbox, reads new emails, and automatically:

  1. Classifies the email (support / sales / spam)
  2. Creates a Notion task for support and sales emails
  3. Sends an auto-reply with a relevant response

Workflow Nodes

Gmail Trigger

AI Agent (GPT-4o-mini)
  System: "You are an email classifier and responder.
           Classify each email and draft an appropriate reply."

Switch (based on classification)
    ├── Support → Create Notion task + Send reply
    ├── Sales   → Create Notion task + Notify Slack
    └── Spam    → Move to trash

Key Expressions

n8n uses {{ }} expressions to reference data from previous nodes:

Email subject: {{ $('Gmail Trigger').item.json.subject }}
Email body:    {{ $('Gmail Trigger').item.json.snippet }}
AI reply:      {{ $('AI Agent').item.json.output }}

Environment Variables for Production

Store API keys as n8n credentials, not hardcoded in workflows. In the n8n settings:

  1. Go to Settings → Credentials
  2. Create a new credential for each service (OpenAI, Gmail, Notion)
  3. Reference credentials in nodes instead of pasting keys directly

For self-hosted n8n, you can also use environment variables:

export N8N_ENCRYPTION_KEY="your-random-32-char-key"
export EXECUTIONS_DATA_PRUNE=true
export EXECUTIONS_DATA_MAX_AGE=168  # hours to keep execution data

Frequently Asked Questions

Is n8n free?

The core n8n platform is open-source and free to self-host under the Sustainable Use License. The n8n Cloud service has a free tier (limited executions per month) and paid plans. For commercial use with on-premise deployment, check the licensing terms on the n8n website.

How is n8n different from Zapier or Make?

n8n is self-hostable — your data never leaves your servers, which matters for GDPR compliance and sensitive data. n8n also has more developer-friendly features: code nodes (JavaScript/Python), complex branching logic, and built-in AI agent capabilities. Zapier and Make are SaaS-only. n8n is more flexible but requires more setup.

Can I use n8n with Claude (Anthropic)?

Yes. n8n has an Anthropic node. In the AI Agent node, select Anthropic Chat Model and configure your API key. You can use Claude Sonnet or Haiku as the agent’s reasoning model.

What happens when a workflow fails?

n8n records every execution with full input/output data for each node. You can view the error, identify which node failed, and re-run from that point. Set up error workflows (a special trigger type) to send Slack alerts when a workflow fails.

How many workflows can I run concurrently?

On self-hosted n8n, this depends on your server resources. By default, workflows run sequentially. You can enable Queue Mode with a Redis backend for parallel, distributed execution — useful for high-volume webhook-triggered workflows.

Next Steps

Related Articles