Skip to main content

Stack multiple subsidies: 70% SSG/IBF subsidies, SkillsFuture Credits, UTAP and SFEC credits.

Learn More
← Back to Blogs

Build Your First AI Agent in n8n: A Step-by-Step Tutorial

Posted on 20/11/2026 04:48 AM by Shaza Farid

Last updated: 20 November 2026

You don’t need to be a programmer to build an AI agent. With n8n, a visual automation tool, you connect building blocks on a screen instead of writing code. If you can follow a recipe, you can follow this guide.

By the end of this tutorial, you’ll have built a working AI agent that:

  1. Chats with you and remembers what you’ve said.
  2. Reads your Gmail inbox when you ask it to.
  3. Runs on its own every morning, summarises the emails you received in the last 24 hours and sends the summary to your inbox.

We’ll explain every term in plain language and go one click at a time. You’ll need roughly 45 to 60 minutes, and you can stop between parts and come back later.

Before you start: n8n updates its interface regularly, so some buttons or labels may look slightly different from this guide. The steps and ideas stay the same.

What Is n8n?

n8n (pronounced “n-eight-n”) is a workflow automation tool. It lets you connect apps and services, such as Gmail, Google Sheets, Slack and AI models, so that tasks happen automatically.

You build automations on a visual canvas, a bit like drawing a flowchart. Each box on the canvas does one job, and lines connect the boxes to show the order in which things happen.

n8n has a built-in AI Agent feature, which makes it a practical way for non-technical professionals to build their first AI agent.

Key Terms in Plain Language

Before we start building, here are the words you’ll see in n8n. You don’t need to memorise them. Come back to this list whenever you need it.

Term What it means Everyday comparison
Workflow A complete automation, made up of connected steps A recipe
Node One step or box in a workflow One instruction in the recipe
Trigger The node that starts a workflow The alarm that tells you to start cooking
AI Agent A node that uses AI to decide what to do and then does it A new assistant
Chat model The AI “brain” the agent uses to think and write, such as an OpenAI or Google Gemini model The assistant’s knowledge and judgement
Memory Lets the agent remember earlier messages in a conversation The assistant’s notebook
Tool An app the agent is allowed to use, such as Gmail An access card to a specific room
Credential Saved login details that let n8n connect to an app on your behalf A key you hand to your assistant
API key A long code that acts like a password, letting n8n use a service such as an AI model A key card for one specific service
Execution One run of a workflow One time you cooked the recipe

The most useful way to think about an AI agent: it’s like a new assistant on their first day. You give them a brain (the chat model), a notebook (memory), access cards (tools) and a set of instructions (the system message). The better your instructions and the clearer the access you give, the better they’ll do.

What You’ll Need

Get these ready before you start:

  1. An n8n account. We’ll use n8n Cloud, which runs in your web browser, so you don’t need to install anything. New users can sign up for a free trial.
  2. Access to an AI model. You’ll need an API key from an AI provider such as OpenAI or Google. We’ll walk you through getting one in Part 2.
  3. A Google account with Gmail. For Parts 3 and 4, use a personal Gmail account you’re comfortable testing with, not a work account, unless your company has approved it.

A note on cost: n8n Cloud offers a free trial, after which it’s a paid service. AI providers usually charge based on how much you use their models. Light personal use, like this tutorial, typically costs very little, but it’s good practice to set a monthly spending limit in your AI provider’s account. Always check each provider’s current pricing.

ChatGPT Plus is not the same as an OpenAI API key. A ChatGPT Plus subscription doesn’t include API access. The API is a separate, pay-as-you-go service from OpenAI.

Part 1: Set Up Your n8n Account

  1. Go to the n8n website and sign up for n8n Cloud.
  2. Follow the on-screen steps to create your account and workspace.
  3. Once you’re in, you’ll see your Overview or Workflows page. This is where all your automations will live.

Tip: if your company already uses n8n, ask your IT team whether you should use the company’s account instead.

Overview graphic showing three parts of an n8n tutorial: a chat agent that remembers, Gmail access, and an independent morning email digest.

Part 2: Build a Chat Agent That Remembers

In this part, you’ll build a simple AI agent you can chat with. It’s the foundation for everything that follows.

Heicoders Academy overview graphic headed ‘What you’ll build’. Three white cards on a red-to-pink gradient show the tutorial progression: ‘Chats and remembers’ for Part 2, ‘Reads your Gmail’ for Part 3, and ‘Works on its own’ for Part 4. The subtitle describes a 45–60 minute learning path. Use it to preview the chat agent, Gmail integration and morning digest project, while clarifying in surrounding HTML that Part 4 creates a separate scheduled workflow.

Step 1: Create a New Workflow

  1. Click Create workflow (or the + button).
  2. A blank canvas opens. Give your workflow a name by clicking the title at the top, for example “My First AI Agent”.

Step 2: Add a Chat Trigger

The trigger decides how your workflow starts. For a chat agent, it starts when you send it a message.

  1. Click Add first step (or the + in the middle of the canvas).
  2. In the search box, type Chat Trigger.
  3. Select Chat Trigger, which may appear as “When chat message received”.
  4. A settings panel opens. You don’t need to change anything. Close the panel to go back to the canvas.

You’ll now see one box on your canvas: the Chat Trigger.

Step 3: Add the AI Agent

  1. Click the small + on the right side of the Chat Trigger box.
  2. Type AI Agent in the search box and select it.
  3. The AI Agent settings panel opens. Leave the default settings for now and close the panel.

Your AI Agent box is now connected to the Chat Trigger. Underneath it, you’ll see three small connection points labelled Chat Model, Memory and Tool. These are where you plug in the agent’s brain, notebook and access cards.

Step 4: Connect the Agent’s Brain (the Chat Model)

  1. Click the + under Chat Model on the AI Agent box.
  2. Select OpenAI Chat Model. If you’re using Google instead, select the Google Gemini Chat Model.
  3. In the panel that opens, find the Credential field and choose Create new credential.

Now you need an API key. Here’s how to get one from OpenAI:

  1. In a new browser tab, sign in to the OpenAI Platform (platform.openai.com). This is separate from ChatGPT.
  2. Add a payment method and set a monthly usage limit in the billing settings.
  3. Go to the API keys section and click Create new secret key.
  4. Copy the key straight away. You usually can’t see it again after closing the window.

Back in n8n:

  1. Paste the key into the API Key field and click Save.
  2. If the connection works, you’ll see a green confirmation message.
  3. Under Model, choose a model from the list. A smaller, lower-cost model is fine for this tutorial.
  4. Close the panel.

Keep your API key private. Treat it like a password: don’t share it in emails, chats or screenshots. If you think someone else has seen it, delete it in your OpenAI account and create a new one.

Tip: some n8n Cloud accounts include a small number of free AI credits for new users. If you see that option when choosing a credential, you can use it to try the tutorial before setting up your own API key.

Step 5: Test Your Agent

  1. Click Save in the top-right corner of n8n. Save often as you work.
  2. Click the Open chat button, usually at the bottom of the canvas.
  3. Type “Hello! What can you help me with?” and press Enter.

After a moment, the agent replies. You’ll see the boxes on your canvas light up as the workflow runs. Congratulations: you’ve just run your first AI agent.

Step 6: Give Your Agent a Memory

Try this test first. Type “My name is Sarah”, and once it replies, ask “What’s my name?” The agent won’t know, because right now it forgets each message as soon as it has answered.

Here’s how to fix that:

  1. Click the + under Memory on the AI Agent box.
  2. Select Simple Memory.
  3. In the panel, look for a setting such as Context Window Length. This is how many recent messages the agent remembers. The default is fine for now.
  4. Close the panel, click Save, and start a new chat session.
  5. Repeat the test. This time, the agent remembers your name.

Step 7: Give Your Agent Instructions

Instructions, called the system message, tell the agent who it is and how to behave. They’re the single biggest factor in how useful your agent is.

  1. Double-click the AI Agent box to open it.
  2. Find Options (sometimes at the bottom of the panel) and click Add Option.
  3. Select System Message.
  4. Replace the default text with the instructions below, then edit the details to suit you.
You are a helpful work assistant for a busy professional in Singapore.

Your job is to help me stay on top of my work by answering questions clearly and concisely.

Follow these rules:
- Keep answers short and practical, using bullet points where helpful.
- Use British English spelling.
- If you are not sure about something, say so instead of guessing.
- Never share or repeat sensitive personal information.

Save and test the agent again. Ask it something like “Give me three tips to manage a busy inbox”, and notice how its style follows your instructions.

Part 3: Give Your Agent a Tool (Gmail)

So far, your agent can only talk. Now you’ll give it an access card so it can read your Gmail inbox.

Step 8: Add the Gmail Tool

  1. Click the + under Tool on the AI Agent box.
  2. Search for Gmail and select Gmail Tool.
  3. In the Credential field, choose Create new credential.
  4. Click Sign in with Google, choose your Gmail account and approve the permissions n8n asks for.
  5. Back in the Gmail Tool panel, set Operation to Get Many. In some versions it’s called “Get many messages”.

Step 9: Let the Agent Decide the Details

Your agent needs to decide, for example, which emails to look for. n8n lets you hand those decisions to the AI:

  1. Next to fields such as Limit or Search, look for a small button or option labelled “Let the model define this parameter” (sometimes shown as a sparkle icon).
  2. Turn it on for Search and Limit. The agent will now fill these in based on what you ask.
  3. In the Description field at the top of the tool, write a short explanation so the agent knows when to use it:
Use this tool to find and read emails in my Gmail inbox. You can search using Gmail search terms, for example "newer_than:1d" for emails from the last day.

Close the panel and click Save.

Step 10: Test Your Agent With Gmail

Open the chat and try these requests:

  • “How many emails did I receive today?”
  • “Summarise the three most recent emails in my inbox.”

The agent decides to use the Gmail tool, fetches the emails, and answers based on them. You can click on the Gmail Tool box after a run to see exactly what it fetched.

What’s happening behind the scenes: you didn’t tell the agent step by step what to do. It read your request, decided it needed the Gmail tool, chose what to search for and then wrote a reply. That ability to decide and act is what makes it an agent rather than a simple chatbot.

Part 4: Make Your Agent Work on Its Own Every Morning

Chatting is useful, but the real value of an agent is that it can work without you. In this part, you’ll build a separate workflow that runs every morning, summarises your inbox and emails you the summary.

Morning digest diagram: an 8am Singapore-time schedule starts an AI Agent that uses a chat model, Gmail Get Many and Gmail Send to summarise recent emails and deliver the digest.

Step 11: Create a New Workflow With a Schedule

  1. Go back to your Workflows page and click Create workflow. Name it “Morning Inbox Digest”.
  2. Click Add first step, search for Schedule Trigger and select it.
  3. Set it to run every day at a time that suits you, for example 8:00am.
  4. Check the time zone in your workflow settings is set to Singapore time, so the schedule runs when you expect.

Step 12: Add the AI Agent and Give It a Task

  1. Click the + on the right of the Schedule Trigger and add an AI Agent.
  2. Open the AI Agent. Because there’s no chat this time, you need to type the task directly. Find the field called Source for Prompt (or similar) and choose Define below.
  3. In the Prompt box, paste this task:
Check my Gmail inbox for emails received in the last 24 hours.

Write a short morning summary with these sections:
1. Emails that need a reply from me, with the sender and a one-line summary.
2. Important updates I should know about.
3. Everything else, grouped in one short line each.

Keep the whole summary under 300 words. Use British English.

Then send the summary to me by email with the subject line "Your Morning Inbox Digest".

Add the same chat model as before by clicking the + under Chat Model. You can reuse the credential you’ve already saved.

You don’t need to add memory for this workflow, because each morning’s summary is a fresh task.

Step 13: Add Two Gmail Tools

This agent needs two access cards: one to read emails and one to send the summary.

Tool 1: Read emails

  1. Click the + under Tool and add a Gmail Tool.
  2. Select your saved Gmail credential.
  3. Set Operation to Get Many, and let the model define Search and Limit, as in Step 9.
  4. Add the same description you used before.

Tool 2: Send the summary

  1. Click the + under Tool again and add another Gmail Tool.
  2. Select your Gmail credential and set Operation to Send.
  3. Important: in the To field, type your own email address directly. Don’t let the model define it. This makes sure the agent can only ever send emails to you.
  4. Let the model define the Subject and Message fields.
  5. In the Description, write:
Use this tool to send the finished morning summary to me. Only use it once, after the summary is complete.

Close the panel and click Save.

Step 14: Test the Workflow

  1. Click Execute workflow (or Test workflow) at the bottom of the canvas.
  2. Watch the boxes light up as the agent reads your emails and writes the summary.
  3. Check your inbox. You should receive an email titled “Your Morning Inbox Digest”.

If the summary isn’t quite right, adjust the prompt in Step 12. For example, ask for shorter summaries, or tell the agent to ignore newsletters.

Step 15: Switch It On

Until you switch it on, the schedule won’t run by itself.

  1. At the top of the workflow, find the toggle labelled Active (or the Publish button, depending on your n8n version).
  2. Turn it on.
  3. Your agent will now run every morning at the time you set.

You can see every past run in the Executions tab. That’s useful for checking that the agent ran and what it did.

Troubleshooting Common Problems

If something doesn’t work, check this table first.

Problem Likely cause What to try
The agent doesn’t reply in chat The chat model isn’t connected, or the credential failed Open the chat model box and check the credential shows as connected
An error mentions billing or quota Your AI provider account has no credit or has hit its limit Check billing and usage limits in your AI provider account
The agent forgets earlier messages No memory is connected, or you started a new session Add Simple Memory, save, and keep chatting in the same session
The agent doesn’t use the Gmail tool The tool description is unclear Make the tool description and your request more specific
Gmail sign-in fails Permissions weren’t fully approved Delete the Gmail credential and reconnect, approving all requested permissions
The morning workflow didn’t run The workflow isn’t switched on, or the time zone is wrong Check the Active toggle and the time zone in workflow settings
The summary is too long or misses things The prompt needs more detail Add clear rules to the prompt, such as a word limit or what to ignore

Safety Tips for Your First Agent

Agents can take actions, so it’s worth building good habits from the start:

  • Give the smallest access needed. Only connect the tools your agent needs for its task.
  • Lock down important fields. As with the “To” field in Step 13, fix any setting that could cause problems if the AI got it wrong.
  • Test with your own data first. Use a personal account while you learn, and don’t connect work systems without your company’s approval.
  • Check the Executions tab. Review what your agent did, especially in its first week.
  • Watch your usage. Set a spending limit with your AI provider and keep an eye on how much each run uses.
  • Keep credentials private. Never share API keys or screenshots that show them.

Six AI agent safety habits: limit access, lock important fields, test with your own data, review executions, watch usage and keep credentials private.

What to Build Next

Once your morning digest is working, try extending your agent with other tools:

  • Google Sheets: log each day’s summary in a spreadsheet so you can look back over the week.
  • Google Calendar: add today’s meetings to your morning summary.
  • Slack: post the summary in a Slack channel instead of sending an email.

Each new tool follows the same pattern you’ve just learned: add the tool, connect a credential, describe when to use it, and decide which details the AI can fill in.

For more on how agents differ from rule-based automation, read our guide to AI agents vs traditional automation. If you’d rather hand off whole tasks without building workflows yourself, our Manus AI guide for professionals covers a different approach.

Frequently Asked Questions About Building an AI Agent in n8n

Do I need coding skills to use n8n?

No. Everything in this tutorial is done by clicking, selecting options and typing plain-language instructions. n8n does support code for advanced users, but you don't need it to build useful agents.

Is n8n free?

n8n offers a free trial of its cloud service, after which it's a paid subscription. It's also available as a free, self-hosted Community Edition, but setting that up takes more technical knowledge. Check n8n's website for current plans.

What's the difference between an AI agent and a normal automation?

A normal automation follows fixed rules, such as “when an email arrives, save the attachment”. An AI agent can read a request, decide which tools to use and work out the steps itself. That makes it more flexible, but it also means you should check its work.

Can I use Google Gemini instead of OpenAI?

Yes. In Step 4, choose the Google Gemini Chat Model instead of OpenAI, and create an API key from Google's AI developer platform. The rest of the tutorial works the same way.

Is it safe to connect my Gmail account?

n8n uses Google's official sign-in to connect, and you approve the permissions. Even so, only connect accounts you're comfortable with, use a personal account while learning, and follow your employer's policy before connecting any work account.

How much does it cost to run this agent?

It depends on your n8n plan and how much your AI model is used. A once-a-day summary of a normal inbox typically uses a small amount of AI usage, but costs vary by provider and model, so set a spending limit and check your usage regularly.

From Your First Agent to Everyday Automation

You’ve just built an AI agent that chats, remembers, reads your inbox and works on its own every morning, without writing a line of code. The same building blocks of triggers, an AI brain, memory, tools and clear instructions can automate many other parts of your work.

Building reliable agents is a skill, and like any skill, it improves with structured practice and guidance. Heicoders Academy’s Generative AI for Automation and Productivity course (GA100) is designed for working professionals in Singapore who want to apply AI practically, including a full lesson on building workflow AI agents with n8n. Explore the GA100 Generative AI Course and turn your first agent into automations you use every day.

Heicoders Academy GA100 course card with an Explore GA100 button, support badges and a classroom photograph.

Sources

Build Your First AI Agent in n8n: A Step-by-Step Tutorial
We reply within 24 hours

Find the right course for you and your team

Our experts will help match you to a learning path tailored to your goals.

Drop us an email

Tell us a little about yourself and we'll be in touch.

⌄

By submitting, you agree to Heicoders Academy processing your data as described in our Privacy Policy.

or

Contact us via Whatsapp for a faster reply