AI Tutorial: Build a Free Gemini AI Chat Agent with n8n

AI Tutorial: Build a Free Gemini AI Chat Agent with n8n

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”:

Image 1. Will add more detailed description at a later date.

Adding a Chat Trigger

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

Image 2. Will add more detailed description at a later date.

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

Image 3. Will add more detailed description at a later date.

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

Image 4. Will add more detailed description at a later date.

Adding an AI Agent

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

Image 5. Will add more detailed description at a later date.

Now search for “AI Agent”:

Image 6. Will add more detailed description at a later date.

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’:

Image 7. Will add more detailed description at a later date.

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:

Image 8. Will add more detailed description at a later date.

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:

Image 9. Will add more detailed description at a later date.

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

Image 10. Will add more detailed description at a later date.

This will take you to a screen to setup credentials:

Image 11. Will add more detailed description at a later date.

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:

Image 12. Will add more detailed description at a later date.

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:

Image 13. Will add more detailed description at a later date.

It should now look something like this:

Image 14. Will add more detailed description at a later date.

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:

Image 15. Will add more detailed description at a later date.

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

Image 16. Will add more detailed description at a later date.

You should have a completed workflow that looks like this:

Image 17. Will add more detailed description at a later date.

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:

Image 18. Will add more detailed description at a later date.

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:

Image 19. Will add more detailed description at a later date.

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.

Image 20. Will add more detailed description at a later date.

Save the final workflow

Image 21. Will add more detailed description at a later date.

Chatting with Your AI Agent

Click the “Open Chat” button to test it out.

Image 22. Will add more detailed description at a later date.

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.

SHARE


comments powered by Disqus

Follow Us

Latest Posts

subscribe to our newsletter