No history yet

Configuring the AI Agent

The Heart of the Agent

The AI Agent node is where you move beyond simple question-and-answer bots. Instead of a linear chain, think of this node as a loop. It takes an input, thinks about it, decides if it needs to use a tool, uses it, observes the result, and repeats this cycle until it has a final answer. This is the core difference between a chatbot and a true agent: the ability to plan and execute a series of steps on its own.

We'll focus on the 'Tools Agent', which is built on the ReAct (Reasoning and Acting) framework. This model allows the AI to reason about a task, select an appropriate tool, act, and then reassess based on the outcome.

Create AI Agent Node. The core of your AI Agent.

Crafting the System Message

The System Message is the agent's constitution. It's not just a polite greeting; it's a set of binding rules, constraints, and the persona the agent must adopt. A well-crafted system message is the single most important factor in getting reliable, predictable behavior.

Here, you define the agent's objective, what it should and should not do, and the format for its final output. Be explicit. For example, instead of saying "Be helpful," say "You are an order-lookup assistant. Your only function is to use the provided tools to find order status. Never answer questions unrelated to orders."

You are a helpful e-commerce assistant. 
Your goal is to answer customer questions about their orders. 

RULES:
1.  You must use the `getOrderDetails` tool to find information.
2.  If the order ID is invalid or not found, you must state that you cannot find the order. Do not invent information.
3.  Never answer questions that are not about a specific order.
4.  Your final answer must only contain the order status and tracking number, formatted as:
    - Status: [Order Status]
    - Tracking: [Tracking Number]

This level of detail constrains the agent, preventing it from going off-task and ensuring its output is structured and predictable.

Dynamic Inputs and Execution

An agent isn't very useful if it can't react to changing information. The 'User Message' field is where you feed the agent its specific task for a given workflow run. This is almost always done using expressions to pull data from previous nodes.

For example, if a Webhook node receives a customer query, you might use an expression like {{ $json.body.question }} to pass that query directly to the agent. This allows the agent to work on new, incoming data every time the workflow runs.

This internal loop of thought, action, and observation is powerful, but it can also run away from you. The 'Max Iterations' parameter is a crucial safeguard. It sets a hard limit on how many times the agent can loop before it's forced to stop. This prevents infinite loops that can consume a lot of resources and drive up API costs. Similarly, setting a 'Timeout' ensures that a single step doesn't hang indefinitely while waiting for a slow tool or API.

Tuning for Your Model

Not all models are created equal. You'll find that different LLMs have distinct personalities and respond differently to the same system prompt. For instance, within the n8n environment, GPT-4o tends to follow structured output formats in system messages very strictly. In contrast, Claude 3.5 Sonnet might be more conversational in its thought process and may require more explicit instructions to adhere to a specific format.

Experimentation is key. You may need to tweak your system message and parameters to get the best performance from your chosen model. Two of the most common parameters you'll adjust are Temperature and Top P.

ParameterWhat It DoesWhen to Adjust
TemperatureControls randomness. Higher values (e.g., 0.8) make output more creative. Lower values (e.g., 0.2) make it more deterministic.For agentic tasks requiring factual tool use, keep this low. For creative or brainstorming agents, you can increase it.
Top PAn alternative to Temperature. It considers only the most probable set of next words.Generally, you should only modify one or the other. For most agentic workflows, leaving Top P at its default (usually 1) and controlling creativity with Temperature is sufficient.

Ready to test your knowledge on configuring an AI agent?

Quiz Questions 1/6

What is the fundamental difference between a simple Q&A chatbot and an AI agent, as described in the 'AI Agent' node?

Quiz Questions 2/6

What is the primary role of the 'System Message' in configuring an AI agent?

By mastering these configurations, you can build robust agents that reliably execute complex tasks, moving far beyond the capabilities of a simple chatbot.