Home » Technology » Artificial Intelligence » How to Create a Simple AI Chatbot Using n8n for Free?

How to Create a Simple AI Chatbot Using n8n for Free?

Chatbot in n8n

This article is a continuation of our main module, “How to Build AI Agents for Free?“. Having understood the fundamentals of n8n workflows and the power of integrating tools, it’s time to build your very first functional AI Agent: a simple chatbot. This hands-on example will solidify your understanding of how n8n, Ollama, and external services (conceptually, for now) come together to create an interactive intelligent system. We’ll focus on demonstrating the flow from user input to AI response.

The Goal: A Basic Conversational AI

Our simple AI Chatbot will do the following:

  1. Receive a message (query) from a user via a chat message.
  2. Send that query to a locally running Large Language Model (LLM) via Ollama.
  3. Receive a response from the LLM.
  4. Send the LLM’s response back to the user.

Building the Chatbot Workflow in n8n

Let’s open n8n and start constructing this workflow:

  1. Open n8n: Go to http://localhost:5678 in your web browser.
  2. Create a New Workflow: From the “Workflows” section, click “+ New” to open a blank canvas.
  3. Add the Webhook Trigger Node:
    • Click the “+” icon on the canvas.
    • Search for “On chat message” and select it.
  4. Add the Ollama Node (To Interact with the LLM):

    This is the core of our chatbot’s intelligence.

    • Click the “+” icon extending from the chat-message node.
    • Search for “AI Agent” and select the AI Agent node.
    • In that it asks for “Chat Model” at the bottom. When you click that, a sidebar opens where you can search and select your Ollama Chat Model.
  5. Configure the Ollama Node:
    • Choose your Ollama Credentials. If you’re not sure on how to do that, take a read in this page.
    • Model: Type in the name of one of the models you pulled earlier, e.g., llama3.2, mistral, or any other models. Choose a smaller model for quicker responses if you’re just testing.
    • Messages: This is where you pass the user’s query to the LLM. Click “Add Message” twice.
    • Message 1:
      • Type: System (This sets the context/persona for the AI).
      • Content: You are a helpful AI assistant. Be concise and polite.
    • You can experiment with Temperature (creativity vs. focus) and other settings if you wish, but for a simple chatbot, defaults are fine.

Testing Your Chatbot

  1. Activate the Workflow: At the top right of the n8n canvas, toggle the workflow from InActive to Active.
  2. Get the Chat URL: Click on your Chat Message node. Turn on the “Make Chat Publicly Available” toggle. You’ll get a chat-URL – copy that. You can also edit the “Initial Message” at the bottom of the toggle.
  3. Paste the URL in the browser and you’ll see a chatbot-like UI appearing. Send a Test Message: What are the must-try food items in India?

And there you have it! A simple AI Chatbot built for free, running locally on your computer.

Expanding Your Chatbot’s Capabilities

This simple chatbot is just the beginning. You can expand it significantly by:

  • Adding more tools: Integrate the HTTP Request node with APIs for weather, news, or even your own custom services.
  • Implementing decision logic: Use IF or Switch nodes based on the AI’s response to perform different actions.
  • Connecting to messaging platforms: Replace the simple webhook trigger/response with nodes for Telegram, Slack, Discord, or WhatsApp to build a production-ready chatbot.

This hands-on exercise demonstrates the core principles of building AI Agents within n8n. You’ve now experienced how to connect inputs, process them with local AI models, and deliver an intelligent response.

You’ve built your first AI Agent! Get ready to make your agents even smarter in the next chapter, “What is Prompt Engineering? Why Learning It Matters?”, where we’ll delve into communicating effectively with AI models. Feel free to comment below if you have any doubts or queries!

Key Takeaways

  • Building a basic AI Chatbot with n8n and Ollama is straightforward.
  • n8n workflows can integrate various tools and services.
  • Local LLMs, like those provided by Ollama, enable private AI implementations.
  • Chatbots can be expanded with external APIs and custom logic.

Previous Chapter                                                                                                      Next Chapter →

Join our community by subscribing to our Weekly Newsletter to stay updated on the latest AI updates and technologies, including the tips and how-to guides. (Also, follow us on Instagram (@inner_detail) for more updates in your feed).

(For more such interesting informational, technology and innovation stuffs, keep reading The Inner Detail).

Scroll to Top