How to Build an Agentic Workflow with n8n and an LLM (2026 Tutorial)

Satish Prasad
26 Min Read

TL;DR n8n’s AI Agent node (introduced in n8n 1.19.0) lets you build autonomous, tool-using AI agents inside a visual, no-code workflow editor.

An agent workflow has four core building blocks: a trigger, the AI Agent node (orchestration), a chat model (the LLM β€œbrain”), and tools + memory the agent can use.

This guide walks through the architecture, then builds one complete example end to end β€” an agent that researches a topic, writes a full blog post, generates a featured image, and publishes it to WordPress automatically.


1. What Is an Agentic Workflow in n8n?

Most n8n workflows are deterministic β€” trigger fires, data flows from node A to node B to node C, in a fixed sequence you defined. An agentic workflow is different: somewhere in that sequence sits an AI Agent node that doesn’t follow a fixed path. Instead, it reasons about the input it receives, decides which of its available tools to use (if any), executes those tools, evaluates the results, and loops until it has a final answer.

As n8n’s own documentation puts it: an AI agent builds on Large Language Models. LLMs generate text based on input by predicting the next word, and can select the best tool to achieve a task or simulate complex decision-making, but they can’t act on decisions or use tools themselves β€” AI agents add that goal-oriented functionality, allowing them to use tools, act on outputs, complete tasks, and solve problems.

In other words: the LLM is the brain, but the AI Agent node is the body β€” it gives the brain hands (tools), a memory, and a loop that keeps running until the job is done.

This is what makes n8n agentic workflows powerful for content automation, customer support, research tasks, and data processing pipelines where the exact sequence of steps can’t be hard-coded in advance.


2. The Four Core Components of Every n8n AI Agent

Every production AI agent in n8n is built from four components working together:

1. Trigger node β€” starts the workflow. This could be a Chat Trigger (for conversational agents), a Webhook (for API-triggered agents), a Schedule Trigger (for recurring automation like our blog post example), or any other n8n trigger.

2. AI Agent node β€” the orchestration layer. The AI Agent node serves as the orchestration layer, using LangChain-powered reasoning to make decisions and determine which tools to use based on user input and available capabilities.

3. Chat Model sub-node β€” the LLM connection. This is where you plug in OpenAI, Anthropic Claude, Google Gemini, Groq, Azure OpenAI, or self-hosted models via Ollama.

4. Memory and Tool sub-nodes β€” memory nodes maintain context across interactions, and tool nodes provide external APIs and functions the agent can invoke.

The key architectural insight from n8n’s documentation: data flows as JSON objects from node outputs to node inputs, and this modular architecture mirrors how you might structure a modern web application β€” with separated concerns between routing, business logic, and data access layers.


3. How the AI Agent Node Actually Works (Under the Hood)

Understanding the execution loop is the single most important thing for building reliable agents. Here’s what happens, step by step, every time the AI Agent node runs:

The node receives your input and any previous conversation context from memory. It constructs a prompt that includes the system instructions, conversation history, and available tools. It sends this to your chosen LLM. The LLM decides whether to respond directly or use a tool. If it chooses a tool, the node executes that tool and sends the result back to the LLM. This loop continues until the LLM provides a final response. The response is stored in memory and returned to you.

This is the ReAct loop (Reason β†’ Act β†’ Observe) that underlies almost all agentic AI systems β€” n8n just wraps it in a visual node so you don’t have to write the loop yourself.

The node handles token counting, context window management, error recovery, and the complex formatting required for different LLM providers β€” all of which you’d otherwise have to build yourself in code.

The agent’s β€œbrain” β€” choosing your LLM

In n8n, you can connect to OpenAI’s GPT models, Anthropic’s Claude, Google’s Gemini, or even self-hosted models via Ollama. Each has different strengths β€” GPT models are great for complex reasoning, Claude excels at following instructions precisely, and Gemini offers excellent value for simpler tasks.

For our blog automation example later in this guide, we’ll use GPT-4o for the writing and research steps (strong reasoning + writing quality) β€” but the workflow structure works identically if you swap in Claude or Gemini.

Memory β€” why agents need it

Without memory, your agent forgets everything between conversations. Memory in n8n stores the conversation history so your agent can maintain context. You can use simple Window Buffer Memory, which keeps the last N messages, or connect to external stores like Redis for persistence across restarts.

For single-run automation tasks (like generating one blog post), memory is less critical. For conversational agents (like a customer support bot), it’s essential.

Tools β€” how the agent takes action

The AI Agent node gives the LLM a set of tools β€” web search, API calls, calculators, and more β€” along with a task. The model then decides which tools to call, in what order, and loops until the task is complete.

Crucially: the AI Agent node, memory nodes, and all built-in tools configure through n8n’s visual interface without writing code. The only exception is the optional β€œCode” tool, which lets the agent run JavaScript β€” but this is not needed for most agent workflows. This means everything in this tutorial can be built by dragging and connecting nodes β€” no programming required.


4. Setting Up n8n: Cloud vs Self-Hosted

You have two options to get started:

n8n Cloud β€” the fastest way to start. Sign up at n8n.io, get a free trial, and you’re building workflows in your browser within minutes. Best for beginners and for testing this tutorial.

Self-hosted (Docker) β€” for production deployments where you want full control over data and costs. A quick start with Docker looks like: docker run -it --rm --name n8n -p 5678:5678 -v n8n_data:/home/node/.n8n n8nio/n8n

# Quick start with Docker
docker run -it --rm \
  --name n8n \
  -p 5678:5678 \
  -v n8n_data:/home/node/.n8n \
  n8nio/n8n

For production agent workflows that need to scale, deploy production-ready workflows using Docker Compose with PostgreSQL and Redis queue mode for horizontal scaling. We’ll cover this in Section 9.

For this tutorial, either option works β€” the workflow design is identical.


5. Step-by-Step: Your First AI Agent Workflow

Let’s build a minimal β€œhello world” agent before adding tools and memory. This establishes the pattern you’ll reuse for everything else.

Step 1 β€” Add a Chat Trigger

In a new workflow, add a Chat Trigger node. This gives you a simple chat interface to test your agent directly inside n8n.

Step 2 β€” Add the AI Agent node

Connect an AI Agent node to the Chat Trigger. When you add this node, n8n will show you slots for required sub-nodes β€” at minimum, a Chat Model.

Step 3 β€” Connect a Chat Model

For credentials, this tutorial uses OpenAI, but you can easily use DeepSeek, Google Gemini, Groq, Azure, and others. Add the OpenAI Chat Model sub-node, paste in your OpenAI API key as a credential, and select a model (e.g., gpt-4o).

Step 4 β€” Test it

You can test the basic structure before adding language model integration by creating a simple response workflow β€” the Chat Trigger passes user input to the AI Agent, which requires an LLM sub-node to generate actual responses.

Click β€œOpen Chat” in n8n, type a message like β€œWhat’s the capital of France?”, and you should get a response. At this point, your agent is just a chatbot β€” no tools, no memory. Let’s fix that.


6. Adding Memory for Multi-Turn Context

To make your agent remember previous messages in a conversation:

  1. On the AI Agent node, find the Memory connector slot
  2. Add a Window Buffer Memory sub-node β€” this is the simplest option and keeps the last N messages
  3. Configure the context window length (e.g., last 10 messages)

For production agents that need to persist memory across server restarts or scale horizontally, connect to external stores like Redis for persistence.

For our blog automation example, memory isn’t critical since each run is a single, self-contained task β€” but it becomes essential the moment you build a conversational agent (like a customer support bot that needs to remember earlier parts of the conversation).


7. Adding Tools: How the Agent Takes Action

This is where agentic workflows become genuinely powerful. Tools are what separate an β€œagent” from a β€œchatbot.”

On the AI Agent node, find the Tool connector slot (it accepts multiple connections β€” an agent can have many tools). Common tool types include:

  • HTTP Request tool β€” call any external API (the most flexible option)
  • Workflow tool β€” call another n8n workflow as a sub-task (great for breaking complex agents into manageable pieces)
  • Vector Store tool β€” for RAG-style knowledge retrieval
  • Built-in app tools β€” n8n provides native tool wrappers for many integrations (Google Sheets, Slack, Gmail, etc.)
  • Code tool (optional) β€” lets the agent run JavaScript, but this tool is optional and not needed for most agent workflows.

The most important best practice: give every tool a clear, descriptive name and description. The LLM selects tools based on these descriptions β€” vague names like β€œTool1” will cause the agent to misuse or ignore tools entirely. Write descriptions as if you’re briefing a new employee: β€œUse this tool to search the web for current information on a topic. Input: a search query string. Output: a list of search results with titles, URLs, and snippets.”


8. Full Tutorial: Automate Blog Post Creation & Publishing End-to-End

Now let’s put everything together into one real, complete example: an agentic workflow that takes a topic, researches it, writes a full blog post, generates a featured image, and publishes it directly to WordPress as a draft.

This mirrors exactly the kind of workflow RPABOTS.WORLD itself could use to scale content production.

Architecture overview

[Schedule Trigger / Manual Trigger]
        ↓
[Set Node: Define Topic]
        ↓
[AI Agent: Research & Outline]
   β”œβ”€β”€ Tool: HTTP Request (Web Search API)
   └── Chat Model: GPT-4o
        ↓
[AI Agent: Write Full Article]
   └── Chat Model: GPT-4o
        ↓
[AI Agent: Generate Featured Image Prompt]
   └── Chat Model: GPT-4o
        ↓
[HTTP Request: Generate Image (DALL-E API)]
        ↓
[HTTP Request: Upload Image to WordPress Media]
        ↓
[HTTP Request: Create WordPress Draft Post]
        ↓
[Slack/Email Node: Notify "Draft Ready for Review"]

Step 1 β€” Trigger and topic input

Add a Schedule Trigger (e.g., runs every Monday at 9 AM) or a Manual Trigger for testing. Follow it with a Set node where you define your input fields:

FieldExample value
topicβ€œUiPath vs Automation Anywhere 2026”
target_categoryβ€œRPA & Bot Automation”
target_word_count2000

Step 2 β€” AI Agent: Research & Outline

Add your first AI Agent node. Connect:

  • Chat Model: OpenAI GPT-4o
  • Tool: HTTP Request tool configured to call a web search API (e.g., Serper, Tavily, or Brave Search API)

System prompt for this agent:

You are a research assistant for a technical blog about RPA and 
agentic AI automation. Given a topic, your job is to:

1. Use the web search tool to find 3-5 current, relevant sources 
   on this topic (prioritize sources from the last 6 months)
2. Extract the key facts, statistics, and points of comparison
3. Produce a structured outline for a {{ $json.target_word_count }}-word 
   article with section headings

Topic: {{ $json.topic }}

Output your response as a JSON object with this structure:
{
  "outline": ["Section 1 title", "Section 2 title", ...],
  "key_facts": ["fact 1 with source", "fact 2 with source", ...],
  "sources": ["url1", "url2", ...]
}

The agent will: receive the topic, call the web search tool (possibly multiple times for different angles), reason about what it found, and return a structured outline β€” all autonomously, in one node.

Step 3 β€” AI Agent: Write the Full Article

Add a second AI Agent node, connected to the output of Step 2. This agent doesn’t need tools β€” it’s a pure writing task.

System prompt:

You are a senior technical writer for RPABOTS.WORLD, a publication 
for automation professionals. Write a complete, publish-ready blog 
post based on the outline and research provided.

Requirements:
- Target length: {{ $json.target_word_count }} words
- Tone: practitioner-focused, technically accurate, no marketing fluff
- Include a TL;DR summary at the top
- Use the key facts and sources provided β€” cite them naturally in the text
- Format the output as clean HTML suitable for WordPress 
  (use <h2>, <h3>, <p>, <ul>, <table> tags as appropriate)
- End with a "Key Takeaways" bulleted section

Outline: {{ $json.outline }}
Key facts: {{ $json.key_facts }}
Sources: {{ $json.sources }}

Output ONLY the HTML content of the article body β€” no preamble, 
no markdown code fences.

This single AI Agent call produces your full article body as ready-to-publish HTML.

Add a third AI Agent node (or a simple LLM call β€” no tools needed) to turn the article into an image generation prompt:

System prompt:

Based on this blog post title and summary, write a single, 
detailed image generation prompt for a professional blog 
featured image. Style: modern, tech-forward, dark background 
with blue/purple accent colors, no text in the image, 16:9 
aspect ratio.

Title: {{ $json.title }}
Summary: {{ $json.tldr }}

Output ONLY the image prompt as plain text.

Step 5 β€” Generate the image (HTTP Request)

Add an HTTP Request node to call an image generation API (OpenAI’s image generation endpoint, or any provider you prefer):

POST https://api.openai.com/v1/images/generations
Headers: 
  Authorization: Bearer {{your_api_key}}
  Content-Type: application/json
Body:
{
  "model": "dall-e-3",
  "prompt": "{{ $json.image_prompt }}",
  "size": "1792x1024",
  "n": 1
}

The response returns an image URL.

Step 6 β€” Upload the image to WordPress

Add another HTTP Request node to download the image and upload it to your WordPress media library via the WordPress REST API:

POST https://rpabotsworld.com/wp-json/wp/v2/media
Headers:
  Authorization: Basic {{base64_encoded_credentials}}
  Content-Disposition: attachment; filename="featured-image.png"
  Content-Type: image/png
Body: (binary image data from Step 5)

This returns a media_id you’ll use in the next step.

Step 7 β€” Create the WordPress draft post

The final automation step β€” an HTTP Request node that creates the post as a draft (never auto-publish without human review):

POST https://rpabotsworld.com/wp-json/wp/v2/posts
Headers:
  Authorization: Basic {{base64_encoded_credentials}}
  Content-Type: application/json
Body:
{
  "title": "{{ $json.title }}",
  "content": "{{ $json.article_html }}",
  "status": "draft",
  "featured_media": {{ $json.media_id }},
  "categories": [{{ $json.category_id }}]
}

Step 8 β€” Notify your team

Add a Slack or Email node as the final step:

πŸ€– New draft ready for review: "{{ $json.title }}"
View in WordPress: {{ $json.post_edit_link }}

What this workflow demonstrates

This is a genuinely agentic workflow β€” not just a chain of API calls β€” because:

  1. Step 2’s agent decides for itself how many searches to run and what to search for, based on the topic
  2. Step 3’s agent reasons about how to structure 2,000 words from raw research notes β€” a task with no fixed β€œcorrect” sequence of operations
  3. The overall pipeline adapts its output based on what the research agent actually finds β€” two different topics will produce structurally different outlines and articles

Compare this to a traditional n8n workflow (no AI Agent nodes) β€” you’d need to hard-code the exact research queries and article structure for every topic, which simply doesn’t scale.

Safety note: human-in-the-loop is essential

Notice that Step 7 creates a draft, not a published post, and Step 8 notifies a human reviewer. This is a critical design decision for any content-generation agent β€” LLMs can hallucinate facts, and automated publishing without review risks publishing inaccurate content under your byline. Always keep a human approval step for anything customer-facing or public.


9. Production Considerations: Cost, Errors, and Scaling

Cost

Cost depends on the LLM backend and your usage volume. With OpenAI GPT-4o, pricing is approximately $0.005 per 1,000 input tokens and $0.015 per 1,000 output tokens. A research agent that runs 5 tool calls and produces a 500-word summary costs roughly $0.05-0.10 per run.

For our blog automation workflow (research agent + writing agent + image prompt agent + DALL-E image), expect a cost in the range of $0.30–$0.60 per article β€” extremely cheap relative to the time saved, but worth monitoring at scale (e.g., if running this for 50 articles).

Error handling

n8n provides built-in error handling via its Error Workflow feature β€” configure a separate workflow that triggers when any node in your main workflow fails, so you get notified (e.g., via Slack) rather than silently losing a run.

For agent-specific failures (e.g., the LLM returns malformed JSON that breaks downstream nodes), add a Code node after each AI Agent node to validate and parse the output, with a fallback path if parsing fails.

Scaling

For production deployments, run n8n using Docker Compose with PostgreSQL and Redis queue mode for horizontal scaling. This allows multiple workflow executions (e.g., generating articles for many topics in parallel) to run across multiple worker processes rather than one at a time.

Parallel agents

For more advanced pipelines, you can run agents in parallel using n8n’s β€œParallel Branches” feature β€” split the input, run two agents simultaneously, then merge their outputs. For example: run the research agent and the image-prompt agent in parallel since they don’t depend on each other, then merge before the writing step.


10. n8n vs Other Agent Platforms β€” When to Use What

PlatformBest forCode required?
n8nVisual, self-hostable workflows combining AI agents with traditional automation (APIs, databases, CMSs)No (Code node optional)
CrewAIMulti-agent systems with defined roles, built in PythonYes (Python)
LangGraphComplex, stateful agent graphs requiring fine control over flowYes (Python)
UiPath Agent BuilderEnterprise agents that need to call existing RPA automations and enterprise systemsNo (low-code)

n8n’s sweet spot is exactly the scenario in this tutorial: you need an agent that reasons and writes, but the overall pipeline also needs to talk to WordPress, Slack, image generation APIs, and other everyday business tools β€” without writing a custom Python application to glue it all together.

For a deeper comparison, see our guide: n8n vs Zapier vs Make for AI Automation β†’


11. Key Takeaways

  • n8n’s AI Agent node (since v1.19.0, August 2024) brings ReAct-style agentic reasoning into a visual, mostly no-code workflow builder.
  • Every agent needs four components: a trigger, the AI Agent node, a Chat Model (LLM), and optionally memory + tools.
  • The agent’s execution loop β€” receive input, reason, call tools, observe results, repeat until done β€” is handled automatically by the AI Agent node.
  • Tools can be HTTP requests, sub-workflows, vector stores, or built-in app integrations. Tool descriptions matter enormously for correct tool selection.
  • Our end-to-end example shows a real agentic content pipeline: research agent β†’ writing agent β†’ image generation β†’ WordPress publishing β†’ human review notification.
  • Always keep a human-in-the-loop step (draft, not auto-publish) for any agent that produces public-facing content.
  • For production, run n8n with Docker Compose + PostgreSQL + Redis for scalability, and build dedicated error-handling workflows.
  • Typical cost for a multi-agent content pipeline: $0.30–$0.60 per article with GPT-4o β€” cheap, but worth monitoring at scale.


Written by Satish Prasad β€” RPABOTS.WORLD | June 2026 Sources: n8n official documentation (docs.n8n.io/advanced-ai), n8n AI Agent node release notes (v1.19.0, August 2024), and independent 2026 n8n agent-building guides cross-referenced for accuracy.

Share This Article
Follow:
Satish Prasad An NIT Kurukshetra alumnus and Intelligent Automation Architect, Satish brings 15+ years of battle-tested experience deploying over 100 production bots across Investment Banking and Logistics. Today, he bridges the gap between Data Analytics and the frontier of Agentic AI, building autonomous agents that transform complex business logic into intelligent automation. Catch his latest insights on the evolution of tech vibes and digital autonomy.
Leave a Comment