---
title: Create Your First n8n AI Workflow
privateVideoUrl: https://stream.mux.com/GnkrXA4DDvzUBoUBnwYpiMD02d35okJSZV6bNSl02cjt00.m3u8
isPublicLesson: true
---

Welcome to Lesson. In Lesson 5, we launched n8n and explored the interface. Now, we’re diving into the fun part: **building the first pieces of our AI agent workflow**! We’ll create a trigger node, add an AI agent node, and set up a chat model with memory so our AI can actually talk back. By the end, you’ll have a basic AI chat setup ready to grow. Let’s get started!

## Adding the Trigger Node

Alright, let’s create our first node, and you guessed it — it’s a **trigger node** to kick off the workflow. Here’s how:

1. In the n8n Workflow Canvas, click the **plus button** (the “Add Node” button).
2. You’ll see a ton of trigger nodes — n8n has a huge variety, so you can explore later based on what you want to automate.
3. For our workflow, choose the **On Chat Message** node (listed as “Chat Trigger” in the menu). This starts the workflow when someone sends a chat message, perfect for our AI agent that’ll chat with Linear.

A settings window pops up for the node. For now, we don’t need to change anything — the defaults work fine. You’ll see an option to “Make chat publicly available,” but we don’t need that, so just click **Back to Canvas** or click the gray area outside the window. Boom, you’re back, and your first node is on the canvas.

Let’s test it quick. Click **Open Chat** on the Chat Trigger node, type something like “Hi,” and hit send. You’ll see “Node executed successfully,” but nothing else happens. Why? Because the node isn’t connected to anything yet — it’s like sending a message to an empty room. Let’s fix that next.

## Adding the AI Agent Node

Now, we need an **action node**, but since we’re building an AI agent, we’ll use an **AI Agent node** to give our workflow some brains. Here’s how to add it:

1. Click the **plus button** next to the Chat Trigger node (this auto-connects to it) or the plus button in the canvas (you might need to connect manually).
2. In the node menu, go to **AI** > **AI Agent** and select it. n8n has other AI nodes too, but we’re sticking with AI Agent for now — feel free to explore the others later!

The AI Agent node’s settings window opens. Again, the defaults are fine for now, but notice a couple of cool things:

- **Input and Output**: The left side shows what data comes into the node (like the chat message), and the right side shows what it sends out. This helps you track data flow, which is super useful.
- **Chat Model, Memory, Tool**: At the bottom, you’ll see options for these — we’ll set up the chat model next, and memory after that.

Close the settings for now by clicking outside. If the AI Agent node isn’t connected to the Chat Trigger, hover over the trigger’s plus sign, drag the arrow to the AI Agent node, and it’ll snap together like a magnet. Move the nodes closer if you want a cleaner look.

Let’s test again. Open the Chat Trigger’s chat, type something, and send. You’ll get an error or no response because the AI Agent is empty — it needs a chat model to actually do something. Let’s add that now.

## Setting Up the Chat Model

To make our AI Agent smart, we need to give it a **chat model** (a language model, or LLM). Here’s how:

1. Open the AI Agent node’s settings and click **Chat Model**.
2. Choose **OpenAI Chat Model** from the list (n8n supports others, but OpenAI’s a solid pick).
3. You’ll need an **OpenAI API key**. If you don’t have one, go to `platform.openai.com`, sign up, and create an API key. In n8n, click “Create New” under Credentials, paste your key, and save it. If you already have a key set up (like we saw in the Credentials tab), select it.
4. Once the key’s added, pick a model. We’ll use **gpt-4o-mini** — it’s capable, affordable, and great for testing (check pricing at platform.openai.com/docs/pricing).
5. Click outside to close the settings.

n8n tests the API key connection, and if it’s good, you’re set. The chat model is now part of your AI Agent node, and you can drag it around the canvas to keep things tidy.

Let’s test! Open the Chat Trigger’s chat, type “Hi,” and send. Magic! You should see a response from the AI, and the canvas visually shows the data flowing from the trigger to the AI Agent. You can also check the **Execution Log** (bottom of the screen) to see the data flow and node activity — super helpful for understanding what’s happening or debugging.

## Adding Memory to the AI Agent

Our AI is chatting, but there’s a problem. Let’s test it with two messages:

1. Type “What’s one plus one?” in the chat. The AI should reply, “One plus one equals two.” Great!
2. Now type “And plus one?” The AI might get confused and not know you mean “add one to two,” because it doesn’t remember the first message.

Why? Right now, each chat message is treated as brand new — the AI has no memory of past interactions. Let’s fix that by adding **memory**:

1. Open the AI Agent node’s settings and click **Memory**.
2. Choose **Simple Memory** — it’s built into n8n, stores chat history locally, and needs no extra setup. Perfect for us!
3. Check the **Context Window Length** setting. This controls how many previous messages the AI remembers. The default is 5, which is good for testing, but you can increase it for more context or decrease it for less. Leave it at 5 for now.
4. Click outside to save.

Simple Memory just stores messages as text and sends them as context to the AI, so it can recall past chats. Let’s test again:

- Clear the chat by clicking the **Refresh** button in the chat window to start fresh.
- Ask “What’s one plus one?” The AI says “Two.”
- Now ask “And plus one?” The AI should say “Three,” because it remembers the first question.

Awesome! The memory works, and our AI is now smarter, keeping track of the conversation.
