Building an AI Agent with n8n and Gemini

Building an AI Agent with n8n and Gemini

Let's build a chatBot using n8n


Artificial Intelligence (AI) is no longer just a buzzword—it’s powering chatbots, recommendation engines, automated decision-making, and even autonomous agents that can act on our behalf. In this article, we’ll explore how to set up n8n (a powerful open-source automation platform) and build a simple AI agent chatbot using Gemini.


🔹 Step 1: Requirements

Before we begin, make sure you have the following installed:

  • Node.js (version 20.19.x or higher) – Required to run modern JavaScript applications.

  • VS Code – To manage and edit your project files.

🔹 Step 2: Create a Project Folder

  1. Create a new folder for your project.

  2. Open the folder in VS Code.

  3. Initialize it with:

    npm init -y
    

    This creates a package.json file that will track dependencies.


🔹 Step 3: Install n8n & Dependencies

Now let’s install the tools we need.

npm install n8n --global
  • n8n → The automation platform where we’ll build workflows.

  • SQLite → A lightweight database for storing workflows and executions.


🔹 Step 4: Start the n8n Server

Run the following command:

npx n8n start

By default, n8n runs at http://localhost:5678.

On your first launch, you’ll be prompted to enter basic information (name, email, and password).


🔹 Step 5: Create Your First Workflow – AI Chatbot

This is where the fun begins 🎉

  1. Open the n8n dashboard.

  2. Create a new workflow.

  3. Add a Trigger Node (e.g., Manual Trigger or Webhook).

  4. Add a Gemini Node (Google’s Generative AI model).

    • Input → A user’s question.

    • Output → AI-generated response.

  5. Optionally, connect it to another node (Telegram, Slack, or Email) to send responses back to the user.

  6. Save and activate the workflow.



🔹 Step 6: Test Your AI Agent

Now you can test your chatbot:

  • Enter a sample question (e.g., “What is AI?”).

  • The Gemini model will generate a response.

  • Your workflow (AI agent) runs automatically.


🔹 Bonus: Create a Simple Web Chat UI

Instead of just testing inside n8n, we can build a very simple web interface to make it feel like a real chatbot.

1. Create an index.html file

<link href="https://cdn.jsdelivr.net/npm/@n8n/chat/dist/style.css" rel="stylesheet" />
<script type="module">
    import { createChat } from 'https://cdn.jsdelivr.net/npm/@n8n/chat/dist/chat.bundle.es.js';

    createChat({
        webhookUrl: 'YOUR_PRODUCTION_WEBHOOK_URL'
    });
</script>


2. Open with Live Server

  • Right-click index.htmlOpen with Live Server.

  • Now test your chatbot at http://localhost:5500 (default Live Server port).

This way, you can interact with Gemini via your n8n workflow in a simple browser-based UI—without setting up any backend server.

🎯 Conclusion

With just a few steps, we built an AI-powered agent using n8n + Gemini. This demo shows how AI agents can:

  • Take inputs (user queries).

  • Use intelligence (Gemini’s generative AI).

  • Provide outputs (answers, actions, or notifications).

This is just the beginning—n8n lets you chain multiple tools together, meaning you can build agents that not only answer questions but also book appointments, fetch data, send alerts, or even automate business processes.