An AI agent in n8n is a workflow that does not just execute a fixed sequence of steps. It receives an input, decides which tools to use based on that input, uses them, and returns a response. The difference from a standard n8n workflow: the agent reasons about what to do rather than following a predetermined path.

This tutorial builds the most practical version for operations teams: an agent that receives a question or request, looks up relevant information from a Google Sheet, and sends a structured response via email or Slack.

Common use case: someone submits a question about a product, order, or supplier through a form or chat. The agent pulls the relevant data from your sheet and replies with a formatted answer, without any manual lookup.

No coding required beyond small text inputs. No ERP API. The agent reads from a spreadsheet you already maintain.

What You Are Building

An n8n AI Agent workflow that:

  1. Receives a question via webhook (a form submission, a Slack message, or a direct API call)
  2. Uses the AI Agent node to process the question with a defined system prompt
  3. Calls a Google Sheets tool to look up relevant data based on the question
  4. Returns a formatted response sent to Gmail or Slack

By the end of this tutorial, you will have a working agent that can answer operations questions from a spreadsheet on demand, with no human lookup required.

How the n8n AI Agent Node Works

The AI Agent node in n8n has three parts:

The model. The large language model the agent uses to reason. n8n connects to OpenAI (GPT-4o, GPT-4), Anthropic (Claude), and others via credentials. For this tutorial, GPT-4o or Claude Sonnet are both suitable; either gives you accurate, structured responses.

The system prompt. Instructions that define the agent's role, what it knows about your context, and how it should format its responses. The system prompt is plain text you write once when configuring the node.

The tools. Actions the agent can call when it needs information or needs to take an action. In n8n, tools include: HTTP Request (call any API), Code (run JavaScript), Google Sheets (read or write), and any other n8n node you configure as a tool.

The agent receives a user message, decides whether it needs to call a tool to answer it, calls the tool, incorporates the result, and generates a final response. This decision loop is handled automatically by the model. You define the tools and the system prompt; the model decides when and how to use them.

Prerequisites

A Google Sheet with structured data. For this tutorial: a product information sheet with columns for Product Name, SKU, Stock Level, Lead Time, and Supplier. Or adapt to whatever data your team actually queries. The sheet should be organized as a simple table with clear column headers.

An n8n instance. n8n Cloud or self-hosted, version 1.40 or later (the AI Agent node is available from version 1.25+, but 1.40+ is recommended for stability).

Google Sheets credentials in n8n. Go to Credentials, add Google Sheets OAuth2, authorize against the account that owns your sheet.

An AI model credential. In n8n Credentials, add either an OpenAI API credential (paste your OpenAI API key) or an Anthropic API credential (paste your Anthropic API key). If you do not already have one, both providers offer a free tier that is sufficient for this tutorial.

A notification destination. Gmail (add Gmail OAuth2 credentials) or Slack (incoming webhook URL from your Slack workspace settings).

Workflow Overview

Webhook Trigger (receives the question)
    → AI Agent node
          ├─ Model: GPT-4o or Claude Sonnet
          ├─ System Prompt: your context and instructions
          └─ Tool: Google Sheets (read rows)
    → Gmail or Slack (send the agent's response)

Three nodes. The AI Agent node handles all the reasoning and tool calls internally; from the outside, it receives a question and returns an answer.

Step-by-Step Build

Step 1: Use n8n AI to Scaffold the Workflow

Before adding any nodes manually, use n8n's built-in AI to generate the starting structure. Open a new workflow, click the AI button in the editor, and describe what you want to build:

"Create a workflow with a webhook trigger that receives a question, passes it to an AI Agent node connected to a Google Sheets tool, and sends the agent's response via Gmail."

n8n AI will generate the webhook, AI Agent node, and response node and connect them. It will not know your specific credentials or sheet details yet, but it gives you the correct structure to configure. You will wire in your credentials, system prompt, and tool settings in the steps below.

Once the AI has laid out the workflow, locate the Webhook node it created and configure it:

  • HTTP Method: POST
  • Path: Set a custom path, e.g., ops-agent
  • Response Mode: Respond to Webhook (so the caller gets a confirmation)

Copy the Test Webhook URL. You will use this to send test questions to the agent.

The webhook accepts a JSON body. For this tutorial, the expected format is:

{
  "question": "What is the lead time for SKU-4421?"
}

The question field is what the agent will receive as its user message.

Step 2: Add the AI Agent Node

Add an AI Agent node after the Webhook.

Configure the model:

  • Click Add Model inside the AI Agent node
  • Select OpenAI Chat Model (or Anthropic Chat Model)
  • Choose your credential
  • Select the model: gpt-4o or claude-sonnet-4-5 (or the latest available)

Write the system prompt:

The system prompt tells the agent what it is, what data it has access to, and how to respond. Keep it specific and practical:

You are an operations assistant for a manufacturing company. You have access to a Google Sheet containing product information including SKUs, stock levels, lead times, and supplier names.

When asked about a product, use the Google Sheets tool to look up the relevant row and return a clear, structured answer. Always include the SKU, the specific information requested, and the data's source (the sheet name and column). If the product is not found, say so clearly.

Format responses as plain text. No markdown. Keep answers under 100 words unless the question requires more detail.

Adjust the system prompt to match your actual sheet and use case. The more specific you are about what the agent should and should not do, the more consistent the responses will be.

Add the Google Sheets tool:

Inside the AI Agent node, click Add Tool, then select Google Sheets.

Configure it:

  • Operation: Get Many Rows
  • Credential: Your Google Sheets credential
  • Spreadsheet: Your product information sheet
  • Sheet: The relevant tab
  • Return All Rows: Enable
  • Tool Name: lookup_product_data (the agent uses this name when deciding whether to call the tool)
  • Tool Description: Use this to look up product information including stock levels, lead times, and supplier names. Returns all rows from the product information sheet.

The tool description is what the model reads to decide when to use this tool. Write it as a clear, literal description of what the tool returns.

Step 3: Connect the User Input

The AI Agent node needs to receive the question from the webhook. Click on the User Message field in the AI Agent node and set it to:

{{ $json.body.question }}

This pulls the question field from the webhook's POST body and passes it to the agent as the user's input.

Step 4: Add the Response Node

Add a Gmail or Slack node after the AI Agent node. The agent's response is available as {{ $json.output }}.

For Gmail:

  • To: A fixed address or a field from the webhook body (add "email" to the webhook input format)
  • Subject: Response to your operations question
  • Message: {{ $json.output }}

For Slack:

  • Channel: Your ops channel
  • Message: Question: {{ $('Webhook').item.json.body.question }}\n\nResponse: {{ $json.output }}

Step 5: Test the Workflow

Click Listen for Test Event on the Webhook node to put it in test mode.

Open a terminal or use a tool like Postman to POST a test question:

curl -X POST https://your-n8n-instance/webhook-test/ops-agent \
  -H "Content-Type: application/json" \
  -d '{"question": "What is the lead time for SKU-4421?"}'

Watch the execution in n8n. You should see:

  1. The Webhook node receives the request
  2. The AI Agent node processes the question, calls the Google Sheets tool, reads the data, and generates a response
  3. The Gmail or Slack node sends the response

Open the AI Agent node output to see the full execution trace, including which tool calls the agent made and what data it retrieved. This trace is how you debug unexpected responses: if the agent returned wrong information, the trace shows exactly what row it read.

Step 6: Activate the Workflow

Switch from the test webhook URL to the production webhook URL (toggle the workflow to Active and use the production URL path). Test with a real question from the team. Confirm the response is accurate and formatted correctly.

What to Watch Out For

Hallucinated responses. If the agent cannot find a matching row in the sheet, it may guess rather than saying "not found." The system prompt instruction "If the product is not found, say so clearly" reduces this, but test with questions about SKUs that do not exist in the sheet to confirm the agent handles the negative case correctly.

Tool description quality. The tool description is what the model uses to decide when to call the tool. If the description is vague ("provides data"), the agent may skip the lookup for questions where it would have been useful. If you add more tools later, make each description specific about what it returns so the agent can distinguish between them.

Model response consistency. Different AI models format responses differently. GPT-4o and Claude Sonnet are both reliable for this use case, but test several questions and compare the outputs before choosing one for production. Claude tends to follow formatting instructions in the system prompt more precisely; GPT-4o tends to be slightly faster.

API cost. Each agent run makes at least one API call to the model and at least one Google Sheets read. For a team sending 20–50 questions per day, cost is negligible (typically under $1/day). For higher volumes, consider caching sheet data in a Code node and passing it to the agent directly, reducing the number of Sheets API calls.

How to Extend This Workflow

Add a second tool for writing back. Add a second Google Sheets tool configured for Update Row. Update the system prompt to tell the agent it can also update a row when asked to record a change. The agent will call the write tool when the user's question implies an update rather than a lookup.

Add memory between turns. The n8n AI Agent node supports a Memory subnode. Add a Simple Memory or Postgres Memory node to give the agent context from previous questions in the same session. Useful if you want the agent to handle multi-turn conversations.

Connect to Slack as the input. Replace the Webhook trigger with a Slack Trigger node. The agent then listens for direct messages or @mentions in a Slack channel and responds in the same thread. This gives your team a conversational interface into your spreadsheet data without changing how the data is maintained.

Expand the knowledge base. Add more Google Sheets tools pointing to different sheets: supplier information, open orders, pricing data. Update the system prompt to describe each tool. The agent will route questions to the right sheet based on the tool descriptions.

Why AI Agents Are the Next Step After Standard Automation

Standard n8n workflows are deterministic: trigger fires, steps run in order, output goes to a destination. That model works well when you know exactly what condition to check and what action to take.

AI agents handle the cases where the request varies. A team member might ask about lead time, or stock level, or supplier contact, or all three in the same question. A standard workflow requires a separate branch for each case. An agent handles all of them from the same entry point: it reads the question, decides what to look up, and returns what was asked.

For operations teams already running standard n8n workflows, an AI agent adds a layer that handles unstructured or variable requests without requiring a new workflow for each one. The Google Sheets knowledge base pattern in this tutorial is the lightest version of that capability: no vector database, no embeddings, just a sheet and a model.

The Flow Kaizen guide covers how to sequence your first five automation builds, including when to use standard workflows and when an AI agent is the right tool.