Claude courses
Course 3 · Lesson 4 of 6

Course 3 · Lesson 4 · about 20 minutes

An agent that starts when something happens

By the end, a new order at a tea shop starts an agent that checks stock, and a free test shows you what it wrote. Your prompt decides what starts the agent, what it may touch and what it may cost, and Claude writes a one-page handover for whoever will host it.

From lesson 3
Your rules already say when Claude may answer. Why add a rule that says what to reply when it can't?

Without it, Claude picks its own words for the refusal, and its explanation can give things away, such as that an order exists under another name. The rule fixes the reply to one line: "I can't confirm that order." Today you write the limits into the prompt for an agent that runs with nobody watching.

ThinkDelegation

What should start work by itself?

An agent on a server waits for something to happen, such as a new order, then does one job without anyone opening a chat. Nobody watches it work, so its prompt has to settle three things first: what starts it, what it may touch and what it may cost.

A new order, a new support ticket, a form someone sends in. The practice kit uses a tea shop's new orders.

Keep the job to a check or a draft that a person acts on. Then name the file or system that stays off limits.

PredictDiligence

What costs money, and what does a free test prove?

Guess before you build anything. The reveals and the Check answer both.

An agent runs on a small server around the clock. Over a month, which bill is usually bigger?
Show the answer

What Claude charges, usually by ten times or more. Anthropic's hosting guide puts a minimal server at roughly $0.05 an hour, while one long agent session can spend dollars. That's why your prompt caps what one order may cost and leaves the server alone.

Your free test passes. A stand-in played Claude's part. What has the test proved?
Show the answer

The parts around Claude. The secret word check, the stock lookup and the file the lines go into are the real ones, and only Claude's part was played by the stand-in. Whether the real Claude looks up every product and stays under the cost limit, only a real run can show, and a real run costs money.

Do

Describe the agent and let Claude build it

Five steps, about 15 minutes. Tick each one when it's done.

WHAT STARTS IT WHAT IT COSTS AT MOST WHAT IT MAY TOUCH New order + secret word Front doorchecks the secret word Wrong word: turned away Stops at 25 cents an order The agentClaude checks each product Dashed line: in the free test, a stand-in plays Claude stock.csvreads it, never changes it stock-check.txtadds one line a product Your prompt settles all three before the agent first runs, because nobody watches it on a server.
What you're buildingThree limits go in the prompt. In the free test, only Claude's part is played by a stand-in.
  1. Put the kit in a folder and open it in the Code tab.

    Unzip the kit and open the lakeside-tea folder in the Code tab with the mode set to Manual, as you did in lesson 1.

    The Lakeside Tea kit

    Lakeside Tea is a made-up online tea shop. The ZIP holds stock.csv (5 products and how many of each are on the shelf), sample-order.csv (one new order, A-5001, with three lines) and a short README.txt. Unzipping it gives you a folder called lakeside-tea.

    Download the ZIP (under 1 KB)
  2. Give Claude the build prompt.

    Paste it into the Code tab and press Enter.

    Build a small agent for our tea shop that checks stock when a new order comes in. Our stock list is stock.csv and a sample order is sample-order.csv, both in this folder. What starts it: the shop sends each new order to the agent's web address with a secret word. If the secret word is wrong or missing, it turns the order away and does nothing else. What it does: it looks up each product in the order and adds one line per product to stock-check.txt, like "A-1000 LT-100 OK" or "A-1000 LT-100 short by 4". What it may touch: it only reads stock.csv and only adds lines to stock-check.txt. It never changes stock.csv. What it costs at most: when it runs for real with Claude, it stops any one order at 25 US cents. I have no API key, so make a free test that stands in for Claude. It starts from an empty stock-check.txt, then sends the sample order once with the right secret word and once with a wrong one. It must run with what's already on my computer: don't install what a real run needs, just tell me what that is. Run the test and show me stock-check.txt before you say it's done.

    It opens with the job and the data, and "What it does" fixes how each line looks, so you can check it.

    "What starts it", "What it may touch" and "What it costs at most" are the three limits. For your own agent, these are the lines to rewrite.

    "I have no API key" asks for a free test. An API key is a paid password that lets a program use Claude, and here a stand-in plays Claude so nothing is charged.

    The last line asks for proof you can read before Claude calls it done.

  3. Approve what Claude asks.

    Expect a request to create files in your folder: the agent and the free test, maybe a short note. Then requests to run commands while Claude runs the test. The test may open the agent's web address on your own computer for a few seconds to send it the sample order twice. Nothing should need installing, because your prompt told Claude to list what a real run needs instead.

    Read each request before you approve it. You can say no to any of them and ask Claude why it needs it. Before it says it's done, Claude shows you stock-check.txt: three lines for order A-5001, and none from the send with the wrong secret word.

  4. Ask Claude to explain what it built.

    Send this in the same session and read the answer:

    Explain what you built as if I've never seen code. One line per file. Then tell me what the free test proves and what it can't prove.

    The answer should say the test proves the secret word check, the stock lookup and the lines in stock-check.txt, and can't prove what the real Claude does or spends. If it claims more, ask: "Which part of that did the stand-in play?"

  5. Ask for a handover.

    Whoever hosts the agent, your IT person or an outside firm, needs to know what they're running. Send this:

    Write handover.txt for the person who will host this agent: one page in plain words. Say what starts it, what it may touch, what it costs at most, what the computer that runs it needs, what a real run needs that the free test didn't, and how to run the free test to check it still works.

    Open handover.txt from your folder and read it. It should repeat your three limits and say that a real run needs an API key, a computer that stays on and can reach Anthropic over the internet, and money for what Claude charges.

    The 25 cent limit is only as good as the prices behind it. If the handover says Claude assumed them, ask: "Check the prices your 25 cent limit uses against Anthropic's pricing page, and fix them if they're different."

If you see this instead

Claude says it can't find stock.csv
The Code tab is open on a different folder. Open the lakeside-tea folder and paste the prompt again.
Claude asks to install something
Your prompt said not to install what a real run needs. Before you approve, ask: "Is this for the free test or for a real run? Can the test run without it?"
LT-102 shows as OK, or the lines look different
Paste: "The order wants 5 of LT-102 and only 3 are on the shelf, so it's short by 2. Use the line format from my prompt. Fix it and run the test again."
stock-check.txt has lines from the wrong secret word
The front door let it in. Paste: "The send with the wrong secret word must be turned away and write nothing. Fix it and run the test again."
CheckDiscernment

Does a new order start the agent, and only with the secret word?

1 · NEW ORDER Order A-5001 2 of LT-101 5 of LT-102 1 of LT-103 + secret word The shop sends it with the secret word 2 · FRONT DOOR Right word the agent starts Wrong word turned away Only the right word starts the agent 3 · STOCK CHECK stock-check.txt A-5001 LT-101 OK A-5001 LT-102 short by 2 A-5001 LT-103 short by 1 nothing from the wrong word One line a product, in a file you open
Why the order mattersThe secret word is checked before the agent starts, so a stranger's order never reaches Claude or costs anything.

Open stock-check.txt from your folder yourself, by double-clicking it.

Claude can read stock.csv too, so in the chat it could tell you the right answer without running the agent at all. The file is what the agent wrote.

You pass when stock-check.txt holds three lines, all for order A-5001: LT-101 OK, LT-102 short by 2, and LT-103 short by 1. Nothing came in from the wrong secret word, and stock.csv still shows 40, 3 and 0 on the shelf for those three.

Check the sums yourself: the order wants 2 of LT-101 (40 on the shelf), 5 of LT-102 (3 on the shelf) and 1 of LT-103 (none left).

Then send a second order: "Put a second order through the free test with the right secret word: A-5002, 12 of LT-104 and 6 of LT-105." LT-104 should be OK, because exactly 12 are on the shelf, and LT-105 short by 1.

Two questions from memory

Your free test passed. What has it proved, and what hasn't it?

It proved the parts around Claude: the secret word turns other senders away, the agent reads only stock.csv and writes only to stock-check.txt, and the lines come out right. It hasn't proved that the real Claude checks every product or stays under 25 cents. Only a real run shows that, and a real run costs money.

Which three things must the prompt for an agent like this settle?

What starts it, what it may touch, and what it costs at most. Nobody watches the agent while it runs, so the prompt decides them in advance.

Lesson 5 opens by asking the first one again.

What a real run needs

An API key from the Claude Console at platform.claude.com, and a computer that stays on to host the agent. Anthropic bills the API per use, separately from your Claude plan. Max, Ultra and Team plans include a monthly API credit; Pro doesn't. The 25 cent limit in your prompt is the most one order may cost.

Course 3 so far

What you've built

Lesson 1: Gym connector
Lesson 2: Two agents, one inbox
Lesson 3: Agent in team chat
Lesson 4: Stock agent
Lesson 5 stops an agent from paying a trick invoice.