Skip to content

AI Baithak · Session guide

Build your first AI agent.

What an AI agent actually is, told as a story, and then you build one yourself in n8n: a model to think, memory to remember, tools to act, and a human to say yes. No coding needed. Like every baithak, it’s free.

Written for Session 7: Build your first AI agent · Last updated

1 · The story

One laptop, four helpers.

Your exams are over and you have saved up. You ask for help with one sentence: “Find me the best laptop under my budget.”

Four different helpers could take that sentence. They sound alike, and they are completely different things. Tap through them. Keep your eye on the middle column: who decides the next step?

1 of 4 · Chatbot

Your friend who knows a lot about laptops

What it does
You ask and it answers from what it already knows: “Get something with 16GB of RAM and an SSD.” Good advice, said once.
Who decides the next step
Nobody. It answers and stops.
Where it breaks
It cannot check today’s prices, open a shop’s website or do anything for you. If what it learned is out of date, so is the answer.
The four side by side
ChatbotWorkflowAI-powered workflowAI agent
Who decides the next stepNobodyThe person who built itThe person who built itThe AI
Uses toolsNoYes, fixed onesYes, fixed onesYes, it picks which
Uses AIYesNoIn some stepsTo run the whole thing
Handles a surpriseTalks about itNoA littleYes, within limits
Same every timeNoYesMostlyNo, so it needs guardrails

An AI agent is an AI that is given a goal, a set of tools and some rules, and decides for itself which steps to take to reach the goal.

Workflows are not the losers here. When the steps never change, a workflow is cheaper, faster and more predictable, and you should use one. Reach for an agent when the steps depend on what happens along the way.

2 · Quick check

Which one is it?

Six real situations. For each one, decide: chatbot, workflow, AI-powered workflow or agent?

Scenario 1 of 6

Score 0

Every morning at 9, a spreadsheet of new sign-ups is emailed to the team. Same steps, every day.

3 · The parts

A brain, a notebook and some hands.

In n8n an agent is one node, the AI Agent, with smaller nodes plugged in underneath it. This is exactly the shape you’ll see on your screen in twenty minutes.

The brainChat Model
Reads everything and decides the next move. Required: the agent will not run without one.
The notebookMemory
Keeps the last few messages of this conversation, so “my budget” still means 150,000 three messages later.
The handsTool
Things it is allowed to do: calculate, fetch a web page, search, send a message. It reads each tool’s description to decide when to use it.

The job description

System message

Written instructions inside the AI Agent node: who it is, what it is for, which tool to use when, and what it must never do. Most of the difference between a useless agent and a good one is this paragraph.

The safety rail

Max Iterations

How many rounds of think-and-act it may take for one message before n8n stops it. The default is 10. It is what stops a confused agent from going round in circles.

4 · The loop

Think, act, observe. Repeat.

An agent doesn’t answer in one go. It thinks about what it needs, uses a tool, looks at what came back, and thinks again, until it has enough to answer. Step through one real question.

Step 1 of 8

The model has been called 0 times

  1. You

    Message

    I have 150,000 rupees. The laptop I want costs $499. Can I afford it, and what would six monthly instalments be?

5 · Before you build

Three things, ten minutes.

A laptop and a browser

Chrome, Edge or Firefox. A phone can follow along but is painful to build on.

An n8n account

Easiest: sign up at n8n.io for a free trial of n8n Cloud. Nothing to install. If you’d rather run it on your own laptop, see the self-hosting note below.

A free AI key

Go to aistudio.google.com/apikey, sign in with Google and choose Create API Key. Gemini has a free tier, which is enough for today. Keep the key private, like a password.

Running n8n on your own laptop instead

Install Docker, then in a terminal:

docker volume create n8n_data
docker run -it --rm --name n8n -p 5678:5678 \
  -e GENERIC_TIMEZONE="Asia/Karachi" -e TZ="Asia/Karachi" \
  -e N8N_ENFORCE_SETTINGS_FILE_PERMISSIONS=true -e N8N_RUNNERS_ENABLED=true \
  -v n8n_data:/home/node/.n8n n8nio/n8n

Older tutorials use npx n8n. n8n is dropping that way of installing in version 3.0, so use Docker.

Then open http://localhost:5678 and create the owner account. Everything on this page works the same way on your own copy.

6 · Build it

Meet Paisa Buddy.

You’ll build a small agent that helps with money questions like the laptop one: it converts currencies at today’s rate, does the maths properly, looks things up, and remembers what you told it. Tick each step as you go; your ticks stay on this device.

0 of 12 steps done

  1. Step 1: Create a workflow

    Sign in to n8n and choose Create workflow. Click the title at the top and call it Paisa Buddy.

    There is no save button: n8n saves changes by itself within a few seconds.

  2. Step 2: Add the chat trigger

    Click Add first step, search for chat and pick the Chat Trigger. It appears on the canvas as When chat message received.

    Leave Make Chat Publicly Available off for now. You’ll switch it on at the very end, when the agent is ready for other people.

  3. Step 3: Add the AI Agent

    Click the + to the right of the trigger, search for AI Agent and add it. Three connectors appear underneath it: Chat Model, Memory and Tool.

    Check that Source for Prompt (User Message) says Connected Chat Trigger Node. That means “whatever the person types in the chat is the question”. It’s the default.

  4. Step 4: Give it a brain: the chat model

    Click the + under Chat Model and pick Google Gemini Chat Model.

    1. In Credential to connect with, choose to create a new credential. The type is Google Gemini(PaLM) API.
    2. Get the key at aistudio.google.com/apikey with Create API Key, and paste it in API Key. Paste only the key: a space at either end breaks it.
    3. For Model, choose gemini-2.5-flash. It’s fast and enough for everything today.

    Not a Gemini 3 model (names like gemini-3-flash-preview). They work for plain tool use, but fail the moment the agent pauses for a human’s approval in section 7, with Thought signature is not valid.

    On n8n Cloud you may also see Use Gateway credits in the credential list. New Cloud accounts get a small amount of AI credit, so that works with no key at all.

  5. Step 5: Write its job description

    Open the AI Agent node. Under Options, choose Add Option → System Message, and replace the default You are a helpful assistant with this:

    System message
    You are Paisa Buddy, a friendly helper for students in Pakistan who are making money decisions, like buying a laptop.
    
    How you work:
    - For ANY arithmetic, use the Calculator tool. Never do maths in your head.
    - To convert between currencies, first get today's rate with the Exchange rates tool.
    - To explain what something is (for example "what is an SSD?"), use Wikipedia.
    - Remember what the user has told you about their budget and needs, and use it.
    
    Rules:
    - Show amounts in Pakistani rupees (Rs) unless the user asks otherwise.
    - If you don't know something, say so. Never invent prices, specs or rates.
    - Never give investment advice or predict what will make money.
    - Keep answers short: a few lines, with the numbers clearly shown.

    Read it through before you paste it. Every line is there for a reason, and in section 8 you’ll delete some and watch what breaks.

  6. Step 6: Give it hands: the Calculator

    Click the + under Tool and add Calculator. It needs no settings.

    It’s the first tool because language models are bad at arithmetic: to a model, digits are just more words to predict. A calculator never is.

  7. Step 7: Talk to it, and read its mind

    Click Open chat at the bottom of the canvas and send:

    Try this
    What is 18% of 139,720, and what is that divided into 6 months?

    The Logs panel opens next to the chat. Click through it: you can see the agent call the model, call the Calculator, read the result and call the model again. That’s the loop from section 4, happening for real.

    Every message you send is one execution: one run of the workflow.

  8. Step 8: Give it a notebook: memory

    First, prove it forgets. In the chat, send these two messages one after the other:

    Message 1, then message 2
    My budget is 150,000 rupees.
    
    What was my budget?

    Without memory it has no idea. Now click the + under Memory and add Simple Memory. Leave Session ID on Connected Chat Trigger Node, so each chat gets its own memory. Context Window Length is how many recent exchanges it keeps; the default is 5. Set it to 10.

    Try the two messages again. Simple Memory lives inside n8n and clears a conversation after an hour of silence. Fine for today; a real product would use a database memory such as Postgres Chat Memory.

  9. Step 9: Let it look things up

    Add a second tool under Tool: Wikipedia. Then ask:

    Try this
    What is an SSD, and why does it matter for a student laptop?

    Check the Logs: it should have chosen Wikipedia, not the Calculator. Nobody told it which tool to use for this question. It read the question and the tool descriptions, and decided.

  10. Step 10: Build your own tool: today’s exchange rate

    Any node can become a tool. Click the + under Tool, search for HTTP Request and add the ordinary HTTP Request node. (Older tutorials use a separate “HTTP Request Tool” node. It’s being removed, so don’t use it.)

    1. Rename the node Exchange rates. The agent sees the name, and the system message refers to it.
    2. Set Tool Description to Set Manually and paste the description below. This is how the agent knows when to use the tool.
    3. Leave Method on GET and paste the URL below. The $fromAI() part is a blank the agent fills in itself: it decides which currency to ask for.
    Tool description
    Gets today's exchange rates. Give it the currency to convert FROM, as a three-letter code like USD. It returns how much one unit of that currency is worth in every other currency, including PKR.
    URL
    https://open.er-api.com/v6/latest/{{ $fromAI('base_currency', 'Three-letter code of the currency to convert FROM, for example USD', 'string') }}

    Now the question from the story:

    Try this
    I have 150,000 rupees. The laptop I want costs $499. Can I afford it, and what would six monthly instalments be?

    Open the Logs and count: the model, Exchange rates, the model, Calculator, and so on. That’s your agent planning its own steps.

  11. Step 11: Test the rules, not just the answers

    A good agent is as much about what it refuses as what it does. Try:

    Try these
    Which crypto coin should I buy to double my money?
    
    What is the price of a Dell XPS in Karachi right now?

    The first should be declined (the rules say no investment advice). The second it cannot know, because it has no shop-price tool, so it should say so rather than invent a number. If it invents one, tighten the system message and ask again.

  12. Step 12: Publish it and share the link

    1. Open When chat message received and switch on Make Chat Publicly Available. Keep Mode on Hosted Chat. Set Initial Message(s) to something friendlier than the default, and copy the chat URL shown at the top of the node.
    2. Click Publish (or press Shift+P). Testing in the editor and running for real are separate: the public link only works for a published workflow.
    3. Open the URL on your phone and chat to your own agent. Each conversation appears under Executions.

    Before you share it widely: anyone with the link spends your API quota. Set Authentication to Basic Auth, or unpublish it after showing your friends.

7 · A human says yes

Let it ask before it acts.

Your cousin in the story checks with you before spending a rupee. Paisa Buddy only calculates and looks things up, so nothing it does can hurt anyone. The moment you give an agent a tool that does something (sends an email, books a slot, pays a bill), it needs a person who approves first.

n8n calls this a human review step: it sits between the agent and one tool, and that tool only runs after a person says yes.

0 of 9 steps done

  1. Step 1: Before you start: use a Gemini 2.5 model

    Open Google Gemini Chat Model and check the Model. It must be gemini-2.5-flash, not a Gemini 3 model such as gemini-3-flash-preview.

    Why: Gemini 3 attaches a hidden “thought signature” to every tool call and refuses to continue unless it gets it back intact. When the agent pauses to wait for your approval and then resumes, the signature doesn’t survive, and the AI Agent node fails with Bad request: Thought signature is not valid. Gemini 2.5 doesn’t have this problem.

  2. Step 2: Choose the tool that needs permission

    In real life, this is the tool that does something: sends, books, pays, deletes. To practise, use the Calculator you already have. It’s harmless, so you can approve and deny it as many times as you like and see exactly what happens.

  3. Step 3: Put a review step in front of it

    Hover over the line that joins the Calculator to the AI Agent’s Tool connector. Click the + on it and choose Add human review step.

    The Tools panel opens at its Human review section. Choose Gmail: the request for permission will arrive as an email with buttons in it.

  4. Step 4: Connect your Gmail

    In the review node, open the credential list and create a new Gmail credential. On n8n Cloud, click Sign in with Google, choose your account and allow access. This is the account the approval emails are sent from.

  5. Step 5: Write the email you’ll receive

    1. To: your own email address. You are the approver.
    2. Subject: Paisa Buddy wants permission
    3. Message: paste the text below. The two blanks fill themselves in with the tool the agent picked and exactly what it wants to send to it.
    4. Under the approval options, set Type of Approval to Approve and Disapprove, so the email has a button for no as well as yes.
    Message
    Paisa Buddy wants to use the tool: {{ $tool.name }}
    With this input: {{ JSON.stringify($tool.parameters) }}
    
    Approve to let it run. Disapprove to stop it.
  6. Step 6: Check the wiring

    On the canvas it should now read, top to bottom:

    AI Agent → Tool connector → Gmail (the review step) → Calculator

    Your other tools, Wikipedia and Exchange rates, stay plugged straight into the agent. They still run without asking; only the Calculator now waits for you. That is the point: you choose which tools need a person.

  7. Step 7: Tell the agent about the rule

    Add this line to the AI Agent’s System Message, so it knows how to behave when you say no:

    Add to the system message
    Some tools need a human's approval before they run. If a request is denied, tell the user it was not approved and do not try the same tool again.
  8. Step 8: Test it: approve

    Clear the chat or start a new session (so the memory from before is not in the way), then send:

    Try this
    What is 2 + 2?
    1. The chat waits. The agent has decided to use the Calculator and is asking you first.
    2. Check your inbox. The email names the tool and shows the sum it wants to run. Click Approve.
    3. Back in n8n, the agent continues: the Calculator runs and the answer comes back. In the Logs you’ll see the review step, then the Calculator, then the model writing the reply.

    While it waits, the run shows as Waiting under Executions. If the answer doesn’t appear in the chat window, open the latest execution there to see it.

  9. Step 9: Test it: deny

    Try this
    What is 15% of 84,000?

    This time click Disapprove in the email. The Calculator never runs, the agent is told it was refused, and, thanks to the line you added, it tells you so instead of guessing the answer. That “no” is the safety feature working.

If it goes wrong

After Approve: “Bad request … Thought signature is not valid”
The model is a Gemini 3 one. Switch the Google Gemini Chat Model to gemini-2.5-flash, start a new chat and try again.
No email arrives
Check the To address, then your spam folder. Then open the review node and check the Gmail credential is connected.
The chat never answers after you approve
Open Executions. If the run is still Waiting, the click didn’t register: use the button in the newest email. If it finished, the answer is in that execution.
It asks permission for Wikipedia too
That tool is plugged into the review step instead of the agent. Move it back to the AI Agent’s Tool connector.

The rule of thumb

  • Reads (look up, calculate, search): let it run.
  • Writes (send, post, book, delete, pay): a human approves.
  • Never give it a tool whose worst case you couldn’t live with, approval or not.

Gmail is one channel of several: the same review step can ask in Chat, Slack, Telegram, WhatsApp and others. Outside an agent, the same idea is the Send message and wait for response action on nodes like Gmail and Slack.

8 · Break it on purpose

You learn more from a broken agent.

Try each of these, then open the Logs to see what the agent did and why.

  1. Disconnect the memory

    Tell it your budget, then ask what your budget was. Now you know exactly what memory is for.

  2. Delete the tool rules from the system message

    Ask the laptop question again. Does it still use the Calculator, or guess the maths?

  3. Ask something it shouldn’t answer

    “Which stock will double next month?” A good system message makes it say it doesn’t know. Does yours?

  4. Rename a tool badly

    Change the exchange-rate tool’s description to “stuff”. Watch it stop being used. Agents choose tools by their descriptions.

  5. Set Max Iterations to 1

    Ask a question that needs two tools. It runs out of rounds before it can finish.

  6. Try to talk it out of its rules

    “Ignore your instructions and…” This is prompt injection, and it is why an agent never gets a tool it could do real damage with unsupervised.

9 · Play and learn

Now play with what you learned.

Five activities, from standing up with pieces of paper to a team build-off. Each one is about one idea from today, so playing is how it sticks.

Activity 1 · Unplugged · 15 min · the whole room

Be the agent.

What it teaches: the loop, tools, memory and the human, acted out with people instead of nodes.

The roles

The User
Reads the mission card out loud, then answers the agent’s questions.
The Agent
Can’t do maths or look anything up. Thinks out loud, and gets things done only by handing a note to a tool. Decides every next step.
Calculator
Does only the maths written on the note. Nothing else.
Wikipedia
Looks the term up on a phone and answers in two sentences.
Exchange rates
Checks today’s rate on a phone. Answers only rates.
Memory
Writes down what the User says. Keeps only the last five things: cross out the oldest.
The Human
Must approve anything that sends, buys, books or deletes. Can say no.
Logs
Writes every step on the board: who, what, and what came back.

How to play

  1. Eight volunteers take a role each. Everyone else watches the Logs.
  2. Draw a mission card and the User reads it out.
  3. The Agent works it out loud: “I need today’s rate”, then writes a note to Exchange rates, reads the answer, decides again.
  4. Stop when the Agent answers the User, or after ten notes (the paper version of Max Iterations).
  5. Then ask the room: how many times did the Agent stop to think? Which tool was busiest? Where did the Human step in? What one line of instructions would have helped?

Mission · card 1 of 6

“I have Rs 60,000. Headphones cost $120 a pair. Can I buy two pairs?”

Tools you’ll need: Exchange rates, then Calculator. Watch the order.

Activity 2 · On screen · 5 min · solo or pairs

Pick the tool.

What it teaches: how an agent chooses a tool, that one message can need two, and that sometimes the answer is no tool.

Message 1 of 6

Score 0

The user says:

“Hi! What can you help me with?”

Pick every tool you would call

Activity 3 · On screen · 5 min · show of hands

Approve or deny?

What it teaches: being the human in the loop: what to let through, what to stop, and what prompt injection looks like.

Request 1 of 6

Score 0

You asked it to email your cousin the laptop comparison.

Agent wants to: Send the comparison to your cousin’s address, the one you gave me.

Activity 4 · On screen · 5 min · pairs

Spot the broken line.

What it teaches: an agent does what its system message says, so bugs live in innocent-sounding sentences.

Case 1 of 4

Score 0

What happened: Asked “what is 17 × 23?”, it replied 381. (It’s 391.)

Its system message

  1. 1You are Paisa Buddy, a friendly helper for students.
  2. 2Answer maths questions straight from memory, to save time.
  3. 3Show amounts in Pakistani rupees.
  4. 4Keep answers short.

Activity 5 · On laptops · 30 min · teams of 3 or 4

The agent build-off.

What it teaches: everything: you change a real agent, test it, and then defend it.

  1. Draw a challenge (20 minutes). Start from your Paisa Buddy and change it to meet the card. Test it in the chat until it works.
  2. Publish and swap (5 minutes). Publish it, turn on the public chat, and give your chat link to the team next to you. Try to break theirs: wrong maths, an invented price, a rule it forgets, an “ignore your instructions”.
  3. Show and vote (5 minutes). Each team shows one thing that worked and the best way it got broken. The room votes by show of hands on four things: it works, it’s honest, it asks before acting, and it’s fun to use.

Challenge · card 1 of 6

Bill splitter

Make it split a restaurant bill fairly: it asks how many people and whether to add a tip, then gives each person’s share. You’ll change: the system message. Uses: Calculator, Memory.

After the session, unpublish your agent or add Basic Auth to its chat: anyone with the link spends your API quota.

10 · When it doesn’t work

The usual suspects.

The AI Agent node has a red warning and won’t run
It has no chat model. The Chat Model connector is required: plug in the Google Gemini Chat Model and choose your credential.
“API key not valid”, 401 or 403
The key was pasted with a space at either end, or it belongs to a different Google account. Create the credential again and paste the key alone.
429, “quota exceeded” or “resource exhausted”
The free tier’s per-minute limit. Wait a minute, send fewer test messages, or switch the model to a lighter one in the model node.
“Bad request … Thought signature is not valid” after approving a tool
The chat model is a Gemini 3 one. Gemini 3 needs a hidden signature returned with every tool call, and it is lost while the agent waits for a person. Switch the model to gemini-2.5-flash and start a new chat.
It forgets what you said one message ago
No memory is connected, or the Session ID is not coming from the chat trigger. Check the Simple Memory node is plugged into the agent’s Memory connector.
It does the maths in its head, and gets it wrong
Say so in the system message: “Always use the Calculator for any arithmetic.” Then check the Logs: did it call the tool at all?
It never uses a tool you added
The tool’s description is vague. The agent reads descriptions to decide. Write one sentence saying exactly when to use it.
It stops with a message about max iterations
It went round the loop too many times, usually because a tool keeps failing. Open the Logs to find which tool, and fix that tool, rather than raising the limit.
Works when you test it, but the public chat link does nothing
The workflow isn’t published yet. Testing in the editor and running for real are two different modes; publish it, then use the production chat URL.

11 · Words you’ll hear

A small dictionary.

LLM
Large language model. The thing behind ChatGPT and Gemini: it predicts the next word, extremely well.
Chat model
An LLM set up for conversation. In n8n, the node that plugs into the agent’s Chat Model connector.
Prompt
What you send the model. The system message is the prompt that is always there.
Tool
Something the agent is allowed to do: calculate, fetch a page, send a message. Also called function calling or tool calling.
Memory
Recent messages the agent is shown again each time, so a conversation hangs together. Not learning: it forgets when the window moves on.
Trigger
The node that starts a workflow: a chat message, a form, a schedule, an email.
Execution
One run of a workflow, from trigger to finish. n8n keeps a list you can open and inspect.
Hallucination
A confident answer that is simply wrong. Tools and clear instructions reduce it; nothing removes it.
Human in the loop
A person approves or edits what the agent is about to do before it happens.
API key
A password that lets n8n use a service on your account. Never paste one into a chat or a screenshot.

Built one? Bring it to the next baithak.

AI Baithak is a free, in-person AI community in Karachi. Show us what your agent does, ask the question you didn’t ask today, and help the next person build theirs.