# The AI Agent Node — AI Automation with n8n

Source: https://www.geekswithgeeks.com/en/n8n-ai-automation/ai-agent-node

> Assemble an agent from a chat model, memory and tools and limit how long it may run.

## A node with three plug-ins

The **AI Agent** node runs a tool-calling loop for you. Attach a **chat model** (required), optional **memory** so a chat keeps its history, and one or more **tools** it may call. Write a clear **system message** describing the role, the tools and the rules. Set a **maximum number of iterations** so a confused agent cannot loop forever.

## A system message for an agent

Say which tool to use when, what to refuse, and how to answer. Short and specific beats long and vague.

```text
You are a support assistant for Acme.
- To check an order, call get_order with the order number.
- To answer policy questions, call search_policy first and quote it.
- Never issue refunds yourself; create a refund request with request_refund.
- If you cannot find the answer, say so and offer to contact a human.
- Reply in the customer's language, in under 120 words.
```

## Cap the iterations

Keep the maximum iterations low (for example 5 to 10) for simple agents. Each iteration is another model call, so unbounded loops directly cost money and time.

**Quiz:** Which sub-node is required to run an AI Agent?

- [x] A chat model
- [ ] A vector store
- [ ] A Slack node
- [ ] A Wait node

*Answer:* A chat model. The model provides the reasoning; memory and tools are optional extras.
