Library
N8N Foundation · Chapter 6 of 10
Chapter 06

AI Agents Inside
n8n

Turn a workflow into a thinking, tool-using agent using the LangChain nodes shipped with n8n.

AI AgentsLangChainRAG
A Handbook For Builders
AI Agents Inside
n8n
Chapter 06
The Claude Code Handbook

An agent is a loop: observe, think, pick a tool, act, repeat. n8n ships this loop as a node.

Section 1

1. What is an AI Agent

An LLM given a goal, a set of tools, and permission to call them repeatedly until the goal is met.

Section 2

2. The Agent Loop

diagramclaude-code
user → LLM → (pick tool) → tool → observation → LLM → ... → answer
Section 3

3. Tools

  • HTTP Request — call any API.
  • Code — run JS on demand.
  • Custom sub-workflow — expose your workflow as a tool.
Section 4

4. Memory

Buffer memory (last N turns), window memory (rolling), and vector memory (semantic recall via pgvector).

Section 5

5. AI Agent Node in n8n

  1. Add AI Agent node.
  2. Attach a Chat Model (OpenAI, Anthropic).
  3. Attach Memory + Tools.
  4. Wire a Chat Trigger for testing.
Section 6

6. RAG Basics

Load docs → chunk → embed → store in pgvector → retrieve top-k on question → stuff into prompt.

Section 7

7. Evaluations

Keep a 20-question dataset. Run nightly. Track pass-rate. Alert on regression.

Section 8

8. Cost Control