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 → ... → answerSection 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
- Add AI Agent node.
- Attach a Chat Model (OpenAI, Anthropic).
- Attach Memory + Tools.
- 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