Skip to content

AI Agent#

Use the Agent node to set which agent type you want to use.

On this page, you'll find the node parameters for the Agent node, and links to more resources.

Connect a tool

You must connect at least one tool sub-node.

n8n provides several agents. The tool agent is the default. n8n recommends using this for most use cases: it will handle most scenarios and provides the best experience when working with tools. If your preferred AI model doesn't support tools, the conversational agent is a good general option.

Conversational Agent#

This agent is optimised for conversation allowing it to chat with the user.

You can use this agent with the Chat Trigger node. Attach a memory sub-node so that users can have an ongoing conversation with multiple queries. Memory doesn't persist between sessions.

Parameters#

Text#

The input from the chat. This is the user's query, also known as the prompt.

Options#

Human Message#

Tell the agent about the tools it can use, and add context to the user's input.

You must include:

  • {tools}: a LangChain expression. Provides a string of the tools you've connected to the Agent.
  • {format_instructions}: a LangChain expression. Provides the schema or format from the output parser node you've connected.
  • {{input}}: a LangChain variable. The user's prompt. Populated with the value of the Text parameter.

Example:

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
TOOLS
------
Assistant can ask the user to use tools to look up information that may be helpful in answering the users original question. The tools the human can use are:

{tools}

{format_instructions}

USER'S INPUT
--------------------
Here is the user's input (remember to respond with a markdown code snippet of a json blob with a single action, and NOTHING else):

{{input}}

System Message#

Send a message to the agent before the conversation starts. Use this to guide the agent's decision-making.

Max Iterations#

How many times the model should run to try and generate a good answer for the user's prompt.

Return Intermediate Steps#

Set to true to include intermediate steps the agent took in the final output. This could be useful for further refining the agent's behavior based on the steps it took.

OpenAI Functions Agent#

Use the OpenAI Functions Agent node to use an OpenAI functions model. These are models that detect when a function should be called and respond with the inputs that should be passed to the function.

You can use this agent with the Chat Trigger node. Attach a memory sub-node so that users can have an ongoing conversation with multiple queries. Memory doesn't persist between sessions.

You must use the OpenAI Chat Model with this agent.

Parameters#

Text#

The input from the chat. This is the user's query, also known as the prompt.

ReAct Agent#

The ReAct Agent node implements ReAct logic. ReAct (reasoning and action) brings together the reasoning powers of chain-of-thought prompting and action plan generation.

No memory

The ReAct agent doesn't support memory sub-nodes. This means it can't recall previous prompts, or simulate an ongoing conversation.

Parameters#

Text#

The input from the chat. This is the user's query, also known as the prompt.

Options#

Use the options to create a message to send to the agent at the start of the conversation. The message type depends on the model you're using.

  • Chat models: these models have the concept of three components interacting (AI, system, and human). They can receive system messages and human messages (prompts).
  • Instruct models: these models don't have the concept of separate AI, system, and human components. They receive one body of text, the instruct message.

Human Message Template#

Use this to extend the user prompt. This is a way for the agent to pass information from one iteration to the next.

Available LangChain expressions:

  • {input}: contains the user prompt.
  • {agent_scratchpad}: information to remember for the next iteration.

Prefix Message#

Add text to prefix the tools list at the start of the conversation. You don't need to add the list of tools. LangChain automatically adds this.

Suffix Message for Chat Model#

The final part of the system message. Sent before the user prompt.

Suffix Message for Regular Model#

The final part of the message. Sent before the user prompt.

Return Intermediate Steps#

Set to true to include intermediate steps the agent took in the final output. This could be useful for further refining the agent's behavior based on the steps it took.

SQL Agent#

The SQL Agent uses a SQL database as a data source. The agent builds a SQL query based on the natural language query in the prompt.

Postgres and MySQL Agents

If you are using Postgres or MySQL this doesn't support the tunnel options you can set in the credential.

Data Source#

Options:

  • MySQL
  • SQLite
  • Postgres

SQLite

To use SQLite you will need to use a Read/Write File From Disk node before the Agent to read your SQLite file.

Prompt#

The query to run on the data.

Options#

Use the options to refine the agent's behavior.

  • Ignored Tables: comma-separated list of tables to ignore from the database. If empty, no tables are ignored.
  • Include Sample Rows: number of sample rows to include in the prompt to the agent. It helps the agent to understand the schema of the database but it also increases the amount of tokens used.
  • Included Tables: comma-separated list of tables to include in the database. If empty, all tables are included.
  • Prefix Prompt: set the initial message.
  • Suffix Prompt: set the final part of the message. Includes the user input and agent scratchpad.
  • Top K: number of database results the agent should keep in its context.

You can view prompt examples in the node.

Tools Agent#

This agent has an enhanced ability to work with tools, and can ensure a standard output format.

The Tools Agent implements Langchain's tool calling interface. This interface describes available tools and their schemas. The agent also has improved output parsing capabilities, as it passes the parser to the model as a formatting tool.

You can use this agent with the Chat Trigger node. Attach a memory sub-node so that users can have an ongoing conversation with multiple queries. Memory doesn't persist between sessions.

This agent supports the following chat models:

Parameters#

Text#

The input from the chat. This is the user's query, also known as the prompt.

Options#

System Message#

Send a message to the agent before the conversation starts. Use this to guide the agent's decision-making.

Max Iterations#

How many times the model should run to try and generate a good answer for the user's prompt.

Return Intermediate Steps#

Set to true to include intermediate steps the agent took in the final output. This could be useful for further refining the agent's behavior based on the steps it took.

Templates and examples#

AI agent chat

by n8n Team

View template details
AI agent that can scrape webpages

by Eduard

View template details
AI chatbot that can search the web

by n8n Team

View template details
Browse AI Agent integration templates, or search all templates

Refer to LangChain's documentation on agents for more information about the service.

View n8n's Advanced AI documentation.

  • completion: Completions are the responses generated by a model like GPT.
  • hallucinations: Hallucination in AI is when an LLM (large language model) mistakenly perceives patterns or objects that don't exist.
  • vector database: A vector database stores mathematical representations of information. Use with embeddings and retrievers to create a database that your AI can access when answering questions.
  • vector store: A vector store, or vector database, stores mathematical representations of information. Use with embeddings and retrievers to create a database that your AI can access when answering questions.