Automating Tasks with AI Agent Using n8n

Automating Tasks with AI Agent Using n8n

Credit: Thachlh (Tech lead)

To create an effective workflow, it’s essential to first understand what n8n and an AI Agent are.

What is n8n?

n8n is an open-source tool that allows you to automate workflows by connecting various services. In this guide, we’ll explore how to use n8n to build an AI Agent that can respond to user input and perform specific tasks.

What is an AI Agent?

An AI Agent is an application or system that uses artificial intelligence to automate tasks, answer questions, or perform actions based on user input. AI Agents can be used in a wide range of scenarios, from customer support to task management.

In this tutorial, you’ll learn how to create a simple AI Agent using n8n, integrated with Google Calendar API and Gemini API.

Requirements

  • Docker
  • A Google project with Calendar API enabled
  • Gemini API key

Installing n8n with Docker (or using n8n Cloud)

docker run -it —rm \
-p 5678:5678 \
-v ~/.n8n:/home/node/.n8n \
n8nio/n8n

Creating a Workflow in n8n

1.Open your browser and go to http://localhost:5678.

2. Create a new workflow by clicking the “New” button in the top-right corner.

3. Drag and drop the required nodes onto the canvas. You will need the following nodes:

  • Chat Trigger: to receive user input.
  • AI Agent: to process and respond to the input.
  • Google Calendar: to create calendar events.
  • Gemini API: to enable AI tasks via Gemini.

Configuring the Nodes

1. Chat Trigger

Select the “Chat Trigger” node and configure it to receive user input.

You can name this trigger something like “User Input”.

2. AI Agent

Connect the “Chat Trigger” node to the “AI Agent” node.

In the configuration of the AI Agent node, set the following:

  • Credential to connect with: Choose the credential linked to the Gemini API.
  • Hosthttps://generativelanguage.googleapis.com
  • API Key: Enter your Gemini API key from Google.
  • Model: Choose the AI model you want to use, for example: models/gemini-2.0-flash-001.

3. Google Calendar

Connect the “AI Agent” node to the “Google Calendar” node.

In the configuration:

  • Tool Description: Set to “Set Automatically”.
  • Resource: Event.
  • Operation: Create.
  • Calendar: Select the calendar you want to use.
  • Start Time & End Time: Use the star icon to let the AI Agent dynamically determine the event timing.

You can click Test to ensure Google Calendar is connected and functioning correctly. And just like that, you’ve finished creating a simple workflow that links Google Calendar API and Gemini API to schedule events automatically.

Running the Workflow

  • Type a question or request into the “Chat Trigger” node.
  • The AI Agent will process the input and respond.
  • If your request includes a calendar event (e.g., “Create an event tomorrow at 8–9PM”), the Google Calendar node will automatically add it.

Note: Initially, you might find that the event is created with the wrong date. This is because the AI doesn’t know what “tomorrow” refers to unless it’s given a current timestamp.

How to Fix the “Tomorrow” Problem

Click on the AI Agent node and add the following context so it knows today’s date and can infer tomorrow’s:

here is the current date/time: {{ $now }}
here is my timezone: +07:00

Now, when you enter your request again via “Chat Trigger,” boom — your schedule is accurately created on Google Calendar with the correct time and date.

 

Conclusion

In this tutorial, we learned how to use n8n to build a simple AI Agent that can answer questions and create calendar events in Google Calendar. You can expand this workflow by adding more nodes to handle complex tasks or integrate with other services. Hopefully, this guide helps you get started with n8n and AI Agents.

What do you think?

Related articles

Contact us

Partner with Us for Comprehensive IT Solutions

We’re happy to answer any questions you may have and assist you in determining which of our services best meet your needs.

Your benefits:
What’s the next step?
1

We schedule a call at your convenience.

2

We conduct a discovery and consultation meeting.

3

We prepare a proposal based on your needs.

Book a free consultation