Key Concepts
- n8n: A workflow automation platform.
- Docker: A platform for running applications in containers.
- Ollama: A tool for running large language models locally.
- AI Agent: An entity that can interact with the environment and perform tasks.
- Chat Interface: A user interface for interacting with a chatbot.
- Trigger Node: A node in n8n that initiates a workflow.
- Ollama Chat Model: A specific language model running through Ollama.
- Host-based Networking: Docker networking configuration that allows containers to use the host machine's network.
- Persistent Volume: A Docker volume that persists data even when the container is removed.
Setting Up the Environment
- Prerequisites:
- Ollama must be installed and running locally, configured to listen on all interfaces (or a specific IP address). This is assumed to be completed from a previous "Ollama basics lab."
- Docker must be installed and configured with host-based networking.
- Starting Ollama:
- The command
export OLLAMA_HOST="0.0.0.0"; ollama serve &is used to set theOLLAMA_HOSTenvironment variable to0.0.0.0(all interfaces) and start the Ollama server in the background. curl http://localhost:11434is used to verify that Ollama is running.
- The command
- Creating a Docker Volume:
docker volume create n8n_datacreates a Docker volume namedn8n_datato persist n8n workflow data. This ensures that workflows are preserved even if the n8n container is removed or updated.
- Installing n8n with Docker:
docker run -d --restart unless-stopped -p 5678:5678 -v n8n_data:/home/node/.n8n --name n8n n8nio/n8npulls the latest n8n image from DockerHub and runs it as a container.-d: Runs the container in detached mode (in the background).--restart unless-stopped: Restarts the container automatically unless it is explicitly stopped.-p 5678:5678: Maps port 5678 on the host machine to port 5678 in the container.-v n8n_data:/home/node/.n8n: Mounts then8n_datavolume to the/home/node/.n8ndirectory in the container, where n8n stores its data.--name n8n: Assigns the name "n8n" to the container.n8nio/n8n: Specifies the n8n image to use from DockerHub.
Configuring n8n
- Accessing n8n:
- After the Docker container is running, n8n can be accessed in a web browser at
http://localhost:5678.
- After the Docker container is running, n8n can be accessed in a web browser at
- Setting up an Owner Account:
- The first time n8n is accessed, a setup screen appears, prompting the user to create an owner account with an email address, first name, last name, and password.
- Activating the Community License:
- n8n offers a free community license. A license key is requested via email and then activated in the n8n settings under "Usage and Plan." The key is entered, and the "Activate" button is clicked.
Building the Hello World Workflow
- Creating a New Workflow:
- Click the plus sign (+) at the top left to create a new workflow.
- Adding a Trigger Node (Chat Message):
- Add a "Chat Trigger" node to initiate the workflow when a chat message is received. This node listens for messages sent through the n8n chat interface.
- Adding an AI Agent Node:
- Add an "AI Agent" node after the "Chat Trigger" node. The AI Agent acts as an intermediary between the chat interface and the language model.
- Adding an Ollama Chat Model Node:
- Add an "Ollama Chat Model" node and connect it to the AI Agent node. This node specifies the language model to use for generating responses.
- Configuring Ollama Credentials:
- In the Ollama Chat Model node, create new credentials.
- The host IP address of the Ollama server must be specified.
localhostwill not work because the container has its own localhost. Use the actual IP address of the host machine (e.g.,192.168.1.223). - Test the connection to ensure that n8n can communicate with the Ollama server.
- Connecting the Nodes:
- Connect the "Chat Trigger" node to the "AI Agent" node, and the "AI Agent" node to the "Ollama Chat Model" node. This establishes the flow of data from the chat interface to the language model and back.
Testing the Workflow
- Sending a Chat Message:
- Type a message in the chat interface (located in the lower-left corner of the n8n interface).
- Observing the Output:
- The message is sent to the AI Agent, which then passes it to the Ollama Chat Model. The Ollama Chat Model generates a response, which is sent back to the chat interface. The response is displayed in the chat interface.
- Example: Sending "Hello World" results in a response like "Hello! It's nice to meet you. Is there something I can help you with or would you like to chat?"
Exploring Advanced Features
- Memory Options:
- The AI Agent node has options for adding memory, which allows the agent to remember previous conversations. This can be done using various database integrations or native memory.
- Tool Options:
- The AI Agent node has options for adding tools, which allow the agent to interact with external services like GitHub, YouTube, or ServiceNow. This enables the agent to perform tasks based on user input.
- Example: Connecting to a ticketing system as a tool would allow the agent to check for open tickets based on a trigger word like "tickets."
Conclusion
This lab demonstrates how to set up a basic "Hello World" application using n8n, Docker, and Ollama. It covers the steps required to install and configure these tools, create a simple workflow that connects a chat interface to a language model, and explore advanced features like memory and tools. The key takeaway is understanding how to use n8n as a workflow automation platform to connect different services and create AI-powered applications.
AI summaries can miss context or contain errors. Check important details against the original video.





