← All guides

Build your first AI automation

An AI assistant that reads your customer sheet and writes email drafts. Ask it who your highest paying customer is, or ask for a thank you email. It looks up the answer in Google Sheets and leaves a draft in Gmail. No code.

0 of 8 steps done
STEP 1 OF 8

Add the chat trigger

  1. Click "Add first step".
  2. Search for "chat" and pick "Chat". On the canvas it is named "When chat message received".
  3. Click "Open chat" and send the message below.
  4. Click the trigger node. You should see three fields: action, sessionId and chatInput.
Chat message
Hello, my name is Svetlana.
I searched "chatTrigger" and nothing came up
Search for just "chat". The node is listed as "Chat", the first result.
STEP 2 OF 8

Add the AI Agent

  1. Click the + on the right side of the trigger.
  2. Search for "AI Agent" and pick it.
  3. Leave "Source for Prompt" as "Connected Chat Trigger Node".
  4. Close the panel. A red warning under Chat Model is normal for now.
Error: A Chat Model sub-node must be connected and enabled
That is expected. The agent has no AI model yet. The next step fixes it.
STEP 3 OF 8

Connect a model with OpenRouter

  1. Create an API key at openrouter.ai under Settings, API Keys. Keep it private.
  2. Click the + under Chat Model and pick "OpenRouter Chat Model".
  3. Create a new credential and paste your key.
  4. Pick a low cost model.
  5. Under Options, add "Maximum Number of Tokens" and set the value below.
Maximum Number of Tokens
1024
Authorization failed, please check your credentials
Paste the key again with no space before or after it. Check on OpenRouter that the key is switched on.
Payment required: you requested up to 65536 tokens
No token limit is set. Add "Maximum Number of Tokens" under Options and set it to 1024.
STEP 4 OF 8

Add memory

  1. First say your name, then send the question below. The agent does not know the answer.
  2. Click the + under Memory and pick "Simple Memory".
  3. Leave Session ID as "Connected Chat Trigger Node".
  4. Set Context Window Length to 5.
  5. Say your name and ask again. Now it remembers.
Chat message
What's my name?
It still forgets my name
Both messages must be in the same chat session. Also check that Simple Memory is connected to the agent.
STEP 5 OF 8

Connect Google Sheets

  1. Download the mock customer file below.
  2. Open sheets.new, then File, Import, Upload, and choose "Replace spreadsheet".
  3. In n8n click the + under Tool, pick Google Sheets, then "Get row(s) in sheet".
  4. Sign in with Google.
  5. Choose your document, then choose the tab under Sheet.
Download: workshop-customers.csv
Sheet with ID not found
The Sheet field is empty. Set it to "From list" and pick your tab, or choose "By ID" and type 0.
I cannot see my file in the Document list
Switch Document to "By URL" and paste the address of your sheet. Check you signed in with the same Google account.
STEP 6 OF 8

Give the agent its instructions

  1. Open the AI Agent node.
  2. Click "Add Option" and pick "System Message".
  3. Replace the text with the prompt below.
  4. Reset the chat session, then ask: Who is the highest-paying customer?
System message
You are a helpful customer support assistant.

Today's date and time: {{ $now.toISO() }}

You have access to a Google Sheets tool containing mock customer information and a Gmail tool for creating email drafts.

When the user asks about a customer, consult Google Sheets rather than inventing an answer.

When comparing customer spending, use the numeric spending values from the sheet.

When asked to create an email draft:
- Find and verify the customer's email in Google Sheets.
- Write a professional, friendly subject and email body.
- Use Gmail to create a draft only.
- Never send an email automatically.
- If an email address is missing or ambiguous, ask for clarification.
- Do not claim a draft was created unless the Gmail tool succeeds.

Keep your responses clear, short, and helpful.
The agent says it has no access to customer data
The agent did not use the sheet. Check this prompt is saved, then reset the chat session so the old answer is gone from memory.
STEP 7 OF 8

Connect Gmail for drafts

  1. Click the + under Tool, search for Gmail and pick "Create a draft".
  2. Sign in with Google. Only "Manage drafts and send emails" is needed.
  3. Click the sparkle button next to Subject and Message so the agent fills them in.
  4. Under Options add "To Email" and click the sparkle button there too.
My Gmail node shows "Approval Options"
That is the approval action. Delete the node and add Gmail again with "Create a draft".
The draft has no recipient
"To Email" is missing. Add it under Options and let the agent fill it in.
STEP 8 OF 8

Create your first draft

  1. Reset the chat session.
  2. Send the prompt below.
  3. In the logs, Google Sheets should run first and Gmail second.
  4. Open Gmail and look in Drafts. Nothing was sent.
Chat message
Create a thank-you email draft for Elma. Thank her for being a valuable customer and for her continued support. Use the email address from our Google Sheet. Don't send the email.
It found no customer named Elma
Check the sheet has a row for Elma and that the Sheets tool has no filter, so it returns every row.
QUICK CHECK

You want a workflow to start every morning at 9:00. Is that a trigger or an action?

Pick one.

QUICK CHECK

The agent answers a customer question without calling Google Sheets. Where do you look first?

Pick one.

Workshop demo