DEV Community

Cover image for Build AI Agents with n8n on Linux Ubuntu
Chirag Patel
Chirag Patel

Posted on

Build AI Agents with n8n on Linux Ubuntu

Want to build your own AI agents but don't know where to start? n8n might be the answer. It's a tool that makes building AI agents easier, even if you don't know a lot of code. This guide will show you how to install n8n on a Linux Ubuntu computer and create a simple AI agent.

What is n8n?

n8n is a tool that helps you create AI agents. You can use it to design agents that do different things, like answer questions or find information. The best part is, you don't need to be a coding expert to get started.

In this guide, we'll build an AI agent that can:

  • Get a question from a user.
  • Use a large language model (LLM) called Llama 3.2, which runs on your computer.
  • Search Wikipedia for answers.
  • Give the answer back to the user.

The large language model runs on your computer. But, the AI agent can still use the internet to find information on Wikipedia.

Getting Started: Install Node.js

To use n8n, you first need to install Node.js. Here's how:

Go to the Node.js website: Look for the download section.

Install cURL: Before installing Node.js, you need to install cURL. Open a terminal and type these commands:

sudo apt update
sudo apt upgrade
Enter fullscreen mode Exit fullscreen mode

Enter your password when asked. This will update the packages on your system.

Install cURL: Type this command in the terminal:

sudo apt install curl
Enter fullscreen mode Exit fullscreen mode

Check cURL Version: Verify the cURL version by typing:

curl --version
Enter fullscreen mode Exit fullscreen mode

This shows that cURL is installed and ready to go.

Install Node.js: Go back to the Node.js website and follow the instructions to install Node.js. This involves using several commands in the terminal.

Install Ollama and Llama 3.2 latest

Next, you need to install Ollama and download the Llama 3.2 latest model. This model will help your AI agent understand and answer questions.

1. Go to the Ollama website: Find the download section.

2. Copy the installation command: Make sure Linux is selected. Copy the command.

3. Open a terminal and run the command: This will install Ollama.

4. Verify the installation: Type ollama in the terminal. You should see a generic reply.

5. Download the Llama 3.2 model: Go back to the Ollama website and search for "llama 3.2 latest".

6. Select the latest 3.2 model: Copy the command, but change "run" to "pull". This will download the model without running it. The command should look like this: ollama pull llama3.2

7. Run the pull command: Paste the command into the terminal and press Enter. Wait for the model to download.

8. Check the model: After downloading, type ollama list to see the model.

9. Test the model: Type ollama run llama3.2:latest to run the model. Then, ask a question like "Who are you?" to see if it works.

10. Exit: Press Ctrl+D to exit.

Installing n8n

Now that you have Node.js and Llama 3.2 installed, you can install n8n.

1. Open a terminal and type this command:

npm install -g n8n
Enter fullscreen mode Exit fullscreen mode

This might take a few minutes.

2. Start n8n: Type n8n start in the terminal.

3. Open n8n in your web browser: Copy the address from the terminal and paste it into your browser.

4. Sign up: You'll need to enter your email, name, and password.

5. Get a license: n8n will send you an email with a free license key. Open the email and click on the link to activate the license.

Building Your First AI Agent

Now you can build your first AI agent in n8n.

1. Click "Start from scratch".

2. Click the "+" button and search for "AI Agent". Select it.

3. Use the default settings.

4. Click "Back to Canvas". You'll see several blocks: Chat, AI Agent, etc.

5. Add the chat model: Click the "+" button again and search for "Ollama Chat Model".

6. Set the credentials: Click "Create New Credentials". The default settings should work on Linux Ubuntu. If you're on Windows, you might need to enter a specific address.

7. Test the credentials: Click "Retry" to make sure everything works.

8. Add memory: Click the "+" button and select "Default Memory". Keep the context length at 3.

9. Add a tool: Click the "+" button and add "Wikipedia".

10. Write a system message: You can add a system message to tell the agent how to act. For example, "Your helpful assistant that answers user questions and uses Wikipedia if necessary".

11. Save the model.

12. Test the model: Open the chat and ask a question.

Testing the AI Agent

To test the AI agent, simply open the chat window and ask a question. For example:

  • "Are you working?"
  • "How to solve a quadratic equation?"

The AI agent will use the Llama 3.2 model and Wikipedia to find the answer and give it to you.

What Else Can You Do?

This is just a simple example, but you can do much more with n8n. You can use different tools, like weather apps or email services. You can also connect to databases or build a system to answer questions using specific documents. The possibilities are endless.

Ready to start building? Dive into n8n and explore the possibilities of AI agent creation. What kind of agent will you create?

Top comments (0)