All chapters
Chapter 3 / 7
Join the course
The Agent a circuit that runs while you sleep
Chapter 3 · The Agent

Set it up once, never do it again

In the first two chapters you got to know me and learned to write me the right request. But you're still the one writing it, every time. In this chapter we remove that last step too: we'll build flows that do repeating work without you touching it — in order, the same way every time. Our tool is n8n. You don't need to know code; we'll connect boxes.

Reading time ~40 minutes · Prerequisite: Chapter 2

By the end of this chapter

  • You'll know what a flow, a node and a trigger are — the whole field in three words
  • You'll have built and run your first flow in n8n
  • You'll be able to explain a webhook and an API in a plain sentence
  • You'll see how data travels from node to node
  • You'll put me inside a flow and write Chapter 2's formula into the node
  • You'll understand how an agent that picks its own tools loops
  • You'll have set up, in advance, what happens when a flow breaks
The Claude GuideIn this chapter we put me inside a flow. If you've forgotten what I do well and where I get things wrong — on one page, in four languages.

01How many times a week do you do the same thing

Reading an incoming message and giving one of the same three replies. Copying a form submission into a table. Adding up yesterday's sales every morning and sending them to someone. Filing an invoice when it arrives. None of this is hard; all of it is repetition. And every job that repeats is a job that can be described once.

That's exactly what automation is: you describe a job once, and from then on it happens by itself. While you sleep, while you're on holiday, while ten customers write at the same time. What we call a «flow» in this chapter is that description itself.

The formula you learned in Chapter 2 takes on a new meaning here. There, you wrote the request yourself every time. Here you'll write it once and put it inside a box; every time the box is triggered it fills the request in for me again. Having learned the formula means you've already finished half of this chapter.

Do this now: Write down three jobs you did at least three times this week that were the same every time. By the end of this chapter one of them will be doing itself.

02Three words: flow, node, trigger

Every intimidating word in this field comes down to three simple ideas. Know the three and you'll discover the rest by clicking around on the canvas.

Flow

A job described from start to finish. «Form comes in → write to table → message me» is a flow. n8n calls it a workflow; on the canvas it reads left to right.

Node

A single step in the flow — one box. «Write to table» is a node, «send email» is a node, «ask Claude» is a node. Boxes are connected by wires.

Trigger

The flow's first node; the thing that wakes it up. «Every morning at 09:00», «when a form is filled in», «when someone sends data to this address». Without a trigger the flow keeps sleeping.

There's a fourth word, but it follows from the three: execution. When a trigger wakes once and the flow runs from start to end once, that's an execution. Every execution is recorded; you can see afterwards where it stopped and what it produced.

Do this now: Take one of the three jobs from 01 and pour it into this mould: «when ___ → ___ → ___». The first blank is the trigger, the rest are nodes. Your flow is ready on paper.

03What n8n is, and why

n8n is a tool where you build flows visually: put boxes on a canvas, connect them with wires, run them. It has ready-made connections to hundreds of apps — email, spreadsheets, messaging, CRM, databases — and reaches everything else through an API. There are three reasons I built this chapter on it:

1

Source code is public; runs on your own server too

You can use n8n's cloud or install it on your own server. The second way, your data never leaves and you pay nobody per flow. For an agency that difference is big.

2

Open to non-coders, limitless for coders

Most jobs you build by clicking. But where clicking isn't enough you drop in a code node and write ten lines — or have them written. Chapters 4 and 5 teach exactly that.

3

The AI node is already inside

To put me into a flow you don't install anything extra: add a node, enter your key, write your request. There's an agent node too, one that uses tools and has memory — we get there in section 12.

Honest note: other tools do this job as well, and some are easier for some jobs. I chose n8n because what you learn doesn't stay tied to it — the concepts of flow, node, trigger, webhook and API are the same in every tool. Learn one properly and you'll move to the others in an afternoon.

Do this now: Go to n8n's site and open an account — the cloud version's trial period is enough for this chapter. Don't bother with installation; learn the concept first, think about servers later.

04The anatomy of a flow

The drawing below is the kind of flow you'll build by the end of this chapter. Read it left to right: something happens, data passes from node to node, at one point the road splits in two, and in the end it arrives somewhere.

Left to right: a flow
Each box does one job and hands off to the next. The condition node splits the road in two; both roads do their own work. That's all — every automation is a variation on these four parts.

Ignore what's inside the boxes for now. What matters is the shape: one entry, connected steps, one or more exits. Everything you build on the canvas ends up looking like this picture.

Do this now: Draw the flow you wrote on paper in 02 as boxes and arrows. If there's an «if … then» anywhere, put a condition box there.

05How a flow wakes up: four triggers

Choosing the trigger is the first and most important decision in building a flow. There are four kinds; nearly every real job falls into one of them.

On a schedule

«Every morning at 09:00», «every Monday», «every hour». For reports, summaries, reminders, backups. The schedule node in n8n.

When something happens in an app

«When a new email arrives», «when a row is added to the table», «when a meeting lands in the calendar». The app has its own trigger node; you pick it and connect your account.

When a call comes from outside

Webhook. A website form, a payment system, another piece of software — something outside sends data to your address, and the flow wakes. The next section is entirely about this.

By hand

When you press the button. You use it while building and testing; when you go live you usually replace it with one of the above.

A rule: triggering on a schedule is the easiest, triggering on an event is the right one. «Check every five minutes for new messages» is slower and costlier than «wake when a message arrives». If an event trigger exists, take it; if not, fall back to a schedule.

Do this now: Which of these four is the trigger of your flow on paper? Write it next to it. If you're torn between «event» and «schedule», pick the event.

06Webhook: the world ringing your doorbell

This word scares people; it shouldn't. A webhook is an address given to your flow — like a website address. When an outside system sends something to that address, your flow wakes up and takes what was sent. That's all.

How a webhook works
The outside system site form · payment system · another piece of software
Your flow wakes, takes the incoming data, carries on
The address in the middle is yours. n8n gives it to you itself; you copy it and tell the other system «when something happens, send it here». Like a doorbell: pressed from outside, heard by you inside.

It works in both directions. Your flow can receive a webhook — as above. And your flow can send one to another address: «the job's done, tell this place.» The second is sometimes called an «HTTP request»; different name, same idea.

Security note: anyone who knows the webhook address can ring that bell. When you hand the address out, protect it with a secret (n8n offers options for this) and don't blindly trust incoming data. We come back to this in section 15.

Do this now: Open a new flow in n8n and pick Webhook as the trigger. Open the address it gives you in your browser. You'll see the flow wake — that's your first webhook.

07API: two programs talking

Everything an app does for you also has a version done for programs. You click to add a row to a table; a program does the same by sending a request to an address. The whole of that address and its rules is called an API: the door an app opens to programs, not to people.

You

Open the browser, log in, find the table, click new row, type, save. Six steps, two minutes.

Your flow

Sends a single request to the table's API address: «add this row to this table.» One step, half a second. And a thousand times a day without tiring.

Here's the beauty of n8n: it has already learned the APIs of the common apps for you. You pick the «add row to table» node, connect your account, fill in the columns — you never see the API. If you need to talk to something with no ready node, there's the HTTP request node; you give it the address and what to send, and it does the talking.

Using an API usually needs a key: a long string the app gives you that says «these requests are from me». A key is like a password — in section 15 we'll talk about where to keep it. For now, know this: every API has a door, and every door has a key.

Do this now: Look in the settings of an app you use for a page called «API» or «integrations». If there is one, that app can be connected to your flows.

08Your first flow, in fifteen minutes

Concepts done; now the canvas. The animation below shows what to click on screen while building your first flow. It moves on its own, and you can click the steps.

The first flow on the canvas
New workflowRun
Scheduleevery morning 09:00✓
Send emailgood-morning message✓
This is a drawing, not a screenshot — button names and positions change between versions. What you're looking for is always the same: a «+», a node list, a wire dragged between nodes, and a «run».
  1. 1Open a blank flow. Press the «+» in the middle of the canvas; a node list opens for you.
  2. 2Pick the trigger: schedule. Set the time to «every morning 09:00». Your first node is on the canvas.
  3. 3Drag from the small circle on the node's right onto the canvas; the list opens again. Pick «send email». The wire draws itself.
  4. 4Click the node. Connect your account (it asks the first time), make yourself the recipient, put «good morning» as the subject and a single sentence in the body.
  5. 5Press «run». Green ticks appear in the corners of the nodes; the email lands in your inbox. Save the flow and set it «active» — tomorrow at 09:00 it runs by itself.

Do this now: Finish these five steps today. A flow that emails you good morning may look silly; but that email tomorrow morning is the first instance of the «I built it and it works» feeling.

09How data travels from node to node

You may have noticed something in your first flow: what did the email node receive from the schedule node? The answer: a small envelope. Every node hands the next one an envelope; inside are labelled pieces of information — «name: Ayşe», «amount: 1200», «date: today».

Inside the envelope
form node
email node
Each line is a label and a value. The next node calls the labels by name: «recipient = email», «subject = name + amount». The technical name is JSON; but all you need to think of is a labelled envelope.

When you click a field in a node's settings, n8n shows you the labels coming from the previous node; you drag and drop them. The only thing you sometimes type by hand is a label's name. That drag-and-drop is moving data without writing code.

Sometimes there isn't one envelope but many: if a table has fifty rows, fifty envelopes arrive and the next node runs fifty times — once for each. Getting used to this takes a few tries; «why did the email go fifty times?» usually has this answer.

Do this now: Run your first flow once, then click the schedule node and look at the «output» tab. What you see is the envelope. Read its labels.

10Condition and branching

In real work not everything takes the same road. Let the urgent one reach me as a message, let the non-urgent one drop onto the morning list. The node that does this is called IF: it asks a question and sends the data down one of two roads depending on the answer.

One question, two roads
envelope arrivesurgent: yes
urgent = yes?
yesmessage me at once
noadd to morning list
The condition node has two outputs: yes and no. You connect separate nodes to each. If the «urgent» label in the envelope is yes the upper road runs, otherwise the lower one — the other never wakes in that execution.

Questions are kept simple: one label, one comparison, one value. «Is amount greater than 1000», «does subject contain 'cancel'», «is email empty». For more complex decisions you chain two IFs — or, as you'll see in the next section, you hand the decision to me.

Do this now: Add an IF to your first flow: «is today Monday?» If yes, make the email subject «start the week well». You'll see how branching works in a single try.

11Put me inside the flow

The flows you've built so far are «mechanical»: they carry data, check a condition, send. When reading, understanding or writing is needed, an AI node goes in between — that is, me. Classifying an incoming message, summarising a long email, drafting a reply to a customer: these aren't mechanical, they're language work.

After you add the node and enter your key, one field remains: the request. And you already know what to write there — Chapter 2's formula. The difference: you write role, context, task, constraint and format once; into the «context» part, instead of fixed text, you drag the label coming from the previous node. Every time the flow wakes, that label fills with its new value and the request renews itself.

The request inside the node

Act as the customer representative of a small furniture workshop. Read the customer message below: {{message}}. Classify the message as «order», «complaint» or «question» and write only that single word — nothing else.

There's a role, there's context (coming from the label), the task is precise, the constraint is tight, the format is a single word. The IF node that follows looks at that one word and picks the road.

In a flow the format constraint matters more than ever. In a chat, my writing an extra sentence is no problem; in a flow that extra sentence confuses the next node. Never skip the «write only this, nothing else» constraint in flows — or switch on the node's structured-output option, and it returns with envelope labels.

Do this now: Add an AI node to your flow and paste in an adapted version of the request above. Type a message by hand, run it, see the one-word answer.

12Autonomous agent: the node that picks its tools

The node in the previous section reads something, writes something, and is done. The agent node is different: you give it a goal and a few tools — read the table, check the calendar, send an email — and it decides which tool to use in what order. You don't write the steps; you describe the result.

The agent loop
  1. Takes the goal«suggest the customer a suitable time»
  2. Thinks«I should check the calendar first»
  3. Calls a toolcalendar · table · email
  4. Reads the result«Tuesday 14:00 is free»
  5. Enough?no → back to the start; yes → answer
The fifth box is the heart of the loop: if the result isn't enough for the goal, the agent goes back to the second box and tries another tool. When it's enough, it stops. You don't write this loop; you give the goal and the tools.

You can also attach memory to the agent node: it remembers earlier conversations with the same customer. In Chapter 1 I said «every conversation starts from zero» — in a flow you change that rule yourself with a memory node.

Honest warning: the agent is the flow's most powerful and least predictable part. You don't decide which tool it calls when. So the tools you give an agent should be reversible things: reading, drafting, suggesting. Don't give an agent tools like deleting, paying or sending; leave that step to a separate node, and if possible to your approval.

Do this now: Add an agent node, give it a single tool (reading the table) and a single goal: «is anyone in the table having a birthday today — if so, say their name». Watch the loop in the executions.

13From Instagram DM to CRM: a real flow

This is the flow I promised on the card. A job that repeats every day for an agency: a message comes in, someone has to read it, reply to it and record it. The chain below does it without a person — dropping to your approval at only one point.

Five nodes, one approval
  1. 1Trigger: when a new DM arrives (webhook)
  2. 2Me: classify the message — order / complaint / question
  3. 3Me: draft a reply according to the class
  4. 4Email to you: draft + «approve / edit»
  5. 5Save to CRM: person, class, date, what was replied
The fourth step is deliberately human: you press send. Once ninety percent of the drafts go out untouched, you remove that step — but not on day one.

Once this flow is built, however many messages arrive in a day they're all handled to the same standard, none is forgotten, and all are on record. You only look at drafts. A one-person agency looking like a ten-person agency starts exactly here.

Do this now: Turn these five nodes into your own work — a form instead of a DM, a table instead of a CRM. The structure stays. Change only the first and fifth node; the middle is ready.

14What happens when it breaks

Every flow breaks one day: an app renews a key, a service doesn't answer for five minutes, a customer writes something in a form you never expected. Breaking isn't the problem; breaking silently is. Setting this up from the start takes four steps:

1

An error flow

In n8n you define a separate flow that runs whenever any flow errors: let it message you «which flow, which node, what error». That way you hear about the break before the customer does.

2

Retry

Nodes that talk to outside services have a «on error wait this long and try again» setting. Most temporary outages pass on the second attempt; keeping this on is free.

3

Look at the execution log

Every execution's record stays: which node received what, gave what, where it turned red. When something goes wrong this is the first place to look — you see instead of guessing.

4

Prepare for unexpected data

Empty field, missing label, very long message. A constraint in the AI node like «if the message is empty write 'empty'»; a «none of these» branch in the IF node. Thinking through edge cases is half of building a flow.

Do this now: Build an error flow — one node, it messages you — and attach your first flow to it. Then break it on purpose: delete the recipient in the email node and run. The message should arrive.

15Keys and security

Your flows access your accounts: your email, your tables, your customer list. That access happens through keys, and keys are like passwords. Four rules, all simple:

The key goes in the vault, not the node

n8n has a separate place called «credentials». You put the key there once and nodes use it from there. Pasting a key by hand into a node's settings is like writing your password on a sticky note and leaving it on the desk.

Least privilege

Don't give write permission to a flow that only reads a table. When creating a key, apps usually ask «permission for what»; pick only what's needed. If the flow breaks, the damage stays small too.

Put a secret on the webhook

Anyone who knows the webhook address can trigger your flow. Switch on one of the verification options n8n offers; at the very least, add a part to the address nobody could guess.

Don't trust incoming data

Chapter 1's warning about hidden instructions applies doubly here: a customer message can contain «forget the previous instructions», and that message goes into my node. Keep the constraints tight, don't give irreversible jobs to the agent.

Do this now: Look at every node in the flows you've built. Is a long key string typed by hand inside any of them? If so, move it to credentials — five minutes now saves you a day later.

16When not to automate

Everyone who learns these tools wants to automate everything for a while. That's a mistake, and an expensive one. The honest measure:

Leave it manual

Jobs done once a month. Jobs that need a different decision every time. Jobs where one mistake loses a customer or money. Jobs you don't yet fully know how to do — you can't automate what you don't know.

Automate

Jobs that repeat more than three times a week. Jobs done with the same steps every time. Jobs that do damage when forgotten. Jobs that must also happen at night or at the weekend.

A practical rule: do it by hand three times first, then automate. By the third time the steps are clear and the edge cases have shown themselves. A flow built on the first time breaks on the second.

Do this now: Sort the three jobs from 01 into these two columns. If anything lands in the right-hand column, that's your next flow.

17Five common mistakes

1 · Building the first flow too big

Start with a fifteen-node flow and you'll never find which part is broken. Start with two nodes, get them working, then add the third. Run after every addition.

2 · Leaving the manual trigger in production

You use the «manual» trigger while testing, then forget to change it when going live. The flow never wakes and you say «it doesn't work». Check the trigger before going live.

3 · Not telling the AI node the format

The extra sentence that's harmless in a chat breaks the next node in a flow. The «write only this» constraint, or structured output. No exceptions.

4 · Going live without an error flow

The flow breaks silently; three days later a customer says «I never got a reply». An error flow is ten minutes' work; build it on day one.

5 · Giving the agent an irreversible tool

Deleting, paying, bulk sending. The agent picks the wrong tool in good faith and there's no way back. Keep these steps in a separate node, preferably under your approval.

Do this now: Check the flow you built against these five. Especially 2 and 4 — both are the source of the sentence «I thought it was working».

18What everyone asks

Does it really work without code?

Everything in this chapter does — by clicking. When code is needed you have two options: add a ten-line code node and have me write the code, or leave that step to an AI node. Chapters 4 and 5 will teach the code side from zero; you got this far without it.

n8n cloud or my own server?

While learning, the cloud: no installation, you start in minutes. When going live, your own server: data stays with you, unlimited flows, the monthly cost is the server's. Switching between them is easy — flows are exported and imported. We'll see server setup in Chapter 6.

How much does the AI node cost?

As much as the text sent to me and returned from me on each execution; prices change, check the provider's page for the current figure. Intuitive measure: a short classification is almost free, a long summary a few cents. A flow classifying a hundred messages a day doesn't cost most businesses a coffee. What brings the cost down are Chapter 2's constraints: short request, short answer.

The flow runs slowly, what do I do?

First look at the execution log: which node takes long? It's almost always a node waiting on an outside service — or you're giving the AI node very long text. Trim the text, remove the needless node, switch from «check every five minutes» to an event trigger.

What if the agent does something wrong?

It will — one day, certainly. That's why the tools you give an agent stay at the reading and drafting level, irreversible steps pass through your approval, and the error flow tells you at once. Think of the agent as an intern: give it work, but not signing authority.

Can I hand a flow over to someone else?

Yes — a flow is exported, becomes a single file, gets uploaded to another account. Credentials don't go into the file; the recipient connects their own. That's why delivering a flow to a client is possible too: build, export, deliver. That's the subject of Chapter 6.

Do this now: If you're stuck on a node, ask me — paste the screenshot and say «why did this node turn red?». I know n8n's nodes; I read most errors off the screen.

19Exercises

1 · The good-morning flow

Complete the five steps in 08 and activate the flow. Wait for the email to arrive tomorrow at 09:00.

Aim: to feel «I built it and it ran by itself» once. That feeling is the fuel for learning the rest.

2 · The doorbell

Build a flow with a webhook trigger. Give its address to a site form or another app. When the form is filled in, see the envelope arrive in the execution log.

Aim: to end the scariness of the word «webhook» in one go.

3 · The classifier

Build an AI node that classifies an incoming text as «order / complaint / question», and a three-way IF after it. Test with ten different sample messages.

Aim: to see Chapter 2's formula working inside a node — and to experience why the format constraint is a must.

4 · Break it on purpose

Build the error flow. Then deliberately break a node in your working flow and confirm the message reaches you. Fix it, run again.

Aim: to see what breaking looks like before going live.

Do this now: The first today, the second tomorrow. Three and four after the first two are working. Don't break the order; each builds on the one before.

20Test yourself

Answer for yourself first, then open.

Flow, node, trigger — in one sentence?

A flow is a job description, a node is a single step in it, a trigger is the event that starts it. Without a trigger the flow sleeps.

What is a webhook?

An address given to your flow. When an outside system sends data to it, your flow wakes and takes the data. A doorbell: pressed from outside, heard by you inside.

What is an API?

The door an app opens to programs rather than people. What you do by clicking, a program does by sending a request through that door. n8n has already learned most apps' APIs for you.

Why is an event trigger better than a schedule?

«Check every five minutes» runs for nothing and is late; «wake when it arrives» is instant and free. If an event trigger exists, take it.

How does data travel from node to node?

In a labelled envelope: «name: Ayşe», «amount: 1200». The next node calls the labels by name. If there are many rows, many envelopes arrive and the node runs once for each.

What goes into the AI node?

Chapter 2's formula: role, context, task, constraint, format. The difference: the context isn't fixed text but the label from the previous node. And the format constraint is tighter than in a chat — «write only this».

The difference between an agent node and an ordinary AI node?

The ordinary node reads something, writes something, and is done. To the agent node you give a goal and tools; it decides which tool to use in what order and loops until it reaches the goal.

Which tools are not given to an agent?

Irreversible ones: deleting, paying, bulk sending. These stay in a separate node and preferably under your approval. An agent is an intern — it's given work, not signing authority.

The one thing to set up before going live?

An error flow. A separate flow that messages you when a flow breaks. Without it the break is silent and you hear about it from a customer three days later.

Where does a key go?

Into credentials — n8n's vault. Never typed by hand inside a node. And each key gets only the permission it needs: if it reads, don't give it write.

This chapter in one sentence

Describe a repeating job once — trigger, nodes, a condition, me in between if needed — then set it active and never do it by hand again; with an error flow you'll hear when it breaks, and keys kept in the vault.

Next up

Chapter 4 · The Workshop

You've come as far as clicking can take you. Next is where clicking isn't enough: the terminal, files, and the version of me that works directly on your computer.