AI Tutorial: Build a Free Gemini AI Chat Agent with n8n
- By Bruce Nielson
- ML & AI Specialist
n8n is a great tool for building useful AI Agents with minimal coding. And it even has a free version available if you want to self-host.
One of the first tutorials n8n offers is building an n8n chat agent. Let’s go through that tutorial but with a twist: we’ll connect to Google’s Gemini instead of OpenAI. This is consistent with Mindfire’s goal of finding the best low-cost AI resources for smaller clients that can’t afford a huge AI bill but want to add AI to their applications. Plus, my version of the tutorial will walk you through step-by-step visually to make it as easy as possible.
If necessary, install n8n as discussed in the previous post. That post got you running a free working version of n8n running locally. Once that is done, you’re ready to create your first chat agent.
Creating a New Workflow
After running n8n locally (for me that is http://localhost:5678/) and registering or signing in (as covered in the previous post) you’ll see the overview screen.
Click on “Create Workflow”:

Adding a Chat Trigger
You’ll be taken to the workflow building screen where you’ll click on “Add first step…”:

Next you should search for ‘chat trigger’ and select it:

From here you just want to go “Back to canvas”:

Adding an AI Agent
You’ll go back to the workflow screen where you will want to add another node:

Now search for “AI Agent”:

This will take you to the Edit AI Agent View. We need to add a chat model to the chat agent, so select the “+” under the ‘chat model’:

This will automatically take you back to the search screen but filtered on language models (notice the yellow box). You will search for the model of your choice. For this free demo, we’ll use Google Gemini so that it doesn’t cost anything:

The end result should look something like this the below. Notice that for me it defaulted to the right Gemini credentials because I’ve set them up before. It’s smart enough to reuse them. Also note that control to edit the credentials:

However, if you are doing this the first time, you’ll need to setup your credentials:

This will take you to a screen to setup credentials:

Host for Gemini is https://generativelanguage.googleapis.com and you’ll need an API Key which you can get from https://aistudio.google.com/. (See my tutorial for Google’s AI Studio here.)
There is a link to get an API key:

Now fill it into the credentials and it should work. I’ve had some problems with it not initially recognizing a valid Google model. Use models/gemini-2.5-flash (which should be the default). If it doesn’t like that and claims its invalid, I found it worked if I just went back to canvas and started over.
Connecting the Chat Trigger
It should automatically connect to the chat trigger by default, but I found I sometimes have to connect it manually like this:

It should now look something like this:

Adding Persistence
Large Language Models, by default, have no persistence. Each time you type to them they have no idea what you previously were talking about. To fix this problem, we’ll need to add ‘memory’ by clicking the “+” under ‘memory’ and then select ‘simple memory:

The default context window of 5 messages is fine for now, so go back to canvas:

You should have a completed workflow that looks like this:

One mistake I’ve made in the past is accidentally pinning the AI Agent so that it doesn’t execute when run. You can bang your head trying to figure out why your workflow isn’t working when really, it’s in test mode always returning default data. Be sure the pin icon is unselected here:

Let’s add a ‘system message’ which is just instructions for the chatbot to follow that allows you to lock in a specific style of chatbot:

In this case let’s have the chatbot act like a politician that no matter what you ask it finds a way to change the subject.

Save the final workflow

Chatting with Your AI Agent
Click the “Open Chat” button to test it out.

Try asking your chatbot something and see how it responds. For me, it started off with:
“Ah, the weather! A truly fascinating subject, wouldn't you agree? But you know, what's even more fascinating is the incredible progress we're making on the new community initiative. …”
And then it went on to change the subject to talk about its own political initiatives.
Conclusion
And that’s it! You’ve just built your first n8n workflow — for free. But this is only the beginning.
n8n is a powerful tool for automating almost anything. Imagine all those repetitive tasks you dread every day—gone. Need to schedule meetings automatically? Connect an AI agent to your calendar and email, and let it handle the back-and-forth for you. Overwhelmed by your inbox? Set up an AI-powered workflow to read messages, reply to urgent ones, and even text you when something truly needs your attention.
With n8n and AI, you can turn busywork into background work—so you can focus on what really matters.
Ready to see what else is possible?
Contact us at Mindfire Tech, and we’ll help you unlock the full potential of automation before your competitors do.