AI course

Module 17 of 21 · Part 4: Agentic engineeringBuilders track

Writing tasks for agents

Specs, acceptance criteria and tests as the contract. How to write a task an agent can finish on its own and you can verify without reading every line.

16 min read3 promptsUpdated October 2026

In module 16 you saw what an is: a model with tools and a loop that decides the next step on its own. That autonomy has a price. When an agent works for twenty minutes without asking you, it fills every gap in your instruction itself, and you find out at the end, with the work built on an assumption.

This module is about closing those gaps before the agent starts: a a person reviews, that can be checked, tests that act as the contract, and a plan of small tasks. It is the skill of the 4D framework, taken from a prompt to a system.

Why do agents fail on vague tasks?

For the reason you saw in module 1: the model produces the most plausible text, and when a fact is missing it does not stop, it completes. In a chat that is called a and you catch it while reading. In an agent it is called "a design decision nobody made": it did not know whether the form should accept foreign guests without a national ID, assumed it should not, and built for half an hour on that assumption. The code works. It just solves a different problem.

The Claude Code best-practices guide says it plainly: Claude can infer intent, but it cannot read your mind; the more precise the instruction, the fewer corrections. A vague prompt is fine when you are exploring and correcting is cheap, not when the agent is about to touch real files for half an hour. Module 4 gave you the anatomy of a prompt. A spec is that same anatomy for a task that lasts hours, touches several files and gets read by someone else before it is approved. "Get the price from Stays" leaves four questions open (which units, which rule, what happens when Stays does not answer, what gets removed from the old system), and each one is a coin toss. The spec exists so that you toss those coins yourself, in writing, beforehand.

What does a spec have to say?

One page is enough for most business tasks, as long as every section is there, even when one says "not applicable". They are the ones we use at 77Rentals, and they match what the Claude Code guide calls a self-contained spec: it names files and interfaces, states what is out of scope, and ends with an end-to-end verification step.

  1. 1Goal. What someone will be able to do when this is done, in two or three sentences, from the user’s point of view.
  2. 2Context. What exists today, why it is changing, and which files the agent should read before starting: the from module 2, the from module 12.
  3. 3Scope and non-goals. What is in and, with the same care, what is out: "no online payment", "pages without a calendar do not change". It is the section that saves the most work.
  4. 4Decisions already made. The ones that are yours and the agent must not reopen: which approach was chosen, which were rejected and why. If they are not written down, the agent decides them again.
  5. 5Constraints. What not to touch, which style to follow, which data never leaves the server, what must keep working exactly as it does.
  6. 6Interfaces and data shapes, in words. What goes into and comes out of each piece: "the browser sends only the unit key; the response carries booked nights as ranges and, for every free night, the minimum stay and the rate".
  7. 7Risks and edge cases. What can go wrong and what the user sees when it does. A two-column table beats a paragraph.
  8. 8What "done" means. The acceptance criteria and the tests, which get the next two sections.

Two process rules. First: a person approves the spec before anything gets built. It is the from module 9 at the cheapest point: fixing a sentence takes a minute; a function already built, an afternoon. Second: the agent can help you write it. For larger features, the Claude Code guide recommends having Claude interview you about technical details, edge cases and tradeoffs, write the spec to a file, and start the implementation in a fresh session with clean context. from module 13 is the short version; the spec is the one that outlives the session.

Prompt

Turn my idea into a spec

When the idea is clear in your head and vague on paper. Use it in plan mode or in a normal chat before opening the session that will build.

I want to build this: [THE IDEA IN TWO OR THREE SENTENCES].

Context: [WHAT EXISTS TODAY, WHO USES IT, WHICH FILES OR DOCUMENTS YOU SHOULD READ FIRST].

Before writing anything, interview me. Ask one question at a time about scope, edge cases, what must not change, what data goes in and out, what happens when something fails, and which decisions I have already made. Don’t ask the obvious; ask the hard things I probably haven’t considered. Keep going until no important gaps remain.

Then write a spec of at most two pages with these sections, all of them, even if one says "not applicable": goal, context, scope and non-goals, decisions already made, constraints, interfaces and data shapes (in words, no code), risks and edge cases (table: situation, what the user sees), and what "done" means.

At the end, in a separate list titled "Open decisions", flag everything you assumed because I did not tell you. Do not build anything yet.

Note: Read the open-decisions list more carefully than the rest: those are the coin tosses. Resolve them, ask for the spec to be updated, and save it in the project before going on.

How do I write acceptance criteria that actually work?

An acceptance criterion is a statement about the result that anyone can check with a yes or a no, without having seen the code. It tells the agent when to stop and tells you what to look at. Anthropic’s guide on success criteria asks for them to be specific, measurable, achievable and relevant: instead of "good performance", "accurate classification", with a figure over a defined set of cases. The simplest test: if two people read the criterion and the result, do they reach the same answer? The good ones name a concrete case, an observable fact and a number when there is a number, and they cover the ugly path (what happens on failure), not only the happy one.

  • Bad: "The invoice extractor works well." Good: "On the 20 invoices in the test set, the date, tax ID, subtotal, VAT and total fields match the verified values on at least 19; on any that fails, the field is left empty, never invented."
  • Bad: "The form validates the data." Good: "It rejects an email without an @ and an ID number with letters, shows the error in Spanish under the field, and sends nothing until both are valid."
  • Bad: "The reply to the guest is friendly." Good: "It uses the guest’s name, answers what they asked, promises nothing that is not in the apartment’s bible, and fits in 120 words."
  • Bad: "The system is fast." Good: "With a warm cache, the page shows the calendar without waiting on an external call; without a cache, the user sees the static price while it loads."

Why are tests the contract?

A criterion that can be turned into an is one the agent checks by itself. The Claude Code guide makes it its first recommendation: give Claude a check it can run (tests, a build that passes or fails, a script that diffs output against an expected file, a screenshot to compare). Without that, "looks done" is the only signal it has, and you become the verification loop. With a check that returns pass or fail, the closes on its own: the agent does the work, runs the check, reads the result and iterates until it passes.

That is where the order we recommend comes from: tests first, then the build. If the agent writes the code and then the tests, the tests describe what it built. If they exist first, they describe what you wanted, and the code has to reach them. The same guide even suggests two sessions: one writes the tests and another the code to make them pass, so the one building is not the one grading.

  1. 1Write or describe the checks. For code, tests that fail today. For an AI workflow, the from module 9: real cases with the right answer known, plus a rubric.
  2. 2Confirm they fail before building. A test that passes before the feature exists proves nothing.
  3. 3Let the agent build until they pass. In a single prompt ("implement it and run the tests until they pass") or as a stop condition, with the from module 14.
  4. 4Ask for evidence, not claims: the test output, the command it ran and what it returned.
  5. 5Review the tests more carefully than the code. They are the contract; if they are weak, the contract is weak.

Prompt

Write the acceptance criteria and the tests for this spec

When the spec is approved and you want the contract before building. Run it in a different session from the one that will implement.

Here is the approved spec: [PASTE THE SPEC OR POINT TO THE FILE].

First, write the acceptance criteria: a list of statements anyone can check with a yes or a no without seeing the code. Each criterion names a concrete case, an observable fact, and a number when there is one. Include at least one criterion for every row of the risks table (what happens on failure), not only the happy path. If a criterion cannot be checked, rewrite it until it can, or mark it "not verifiable" and tell me why.

Then, for each criterion, say how it gets verified: automated test (describe the input and the expected output), manual check (the exact steps), or human review (what to look at). For the automated ones, write the tests in [THE PROJECT’S LANGUAGE OR TEST TOOL] using [A REAL SAMPLE FILE OR A RECORDED RESPONSE] as the input, and confirm that they fail today.

Do not implement anything. End with the list of criteria that have no automated test, and why.

Note: When the tests come back, read each one asking: would badly written code pass this? If yes, ask for it to be tightened before moving on.

How do I go from the spec to a plan of tasks?

An approved spec is still too big for a single turn. The next step is a plan: ordered tasks, each small enough for the agent to finish in one session and for you to verify without reading everything else. What makes a task "the right size" is not the number of lines but that it has its own check and its own .

  1. 1Each task names the files it touches and what it receives and delivers, in words.
  2. 2Each task has its check: the test that must pass, the command that must run without errors, or the exact manual steps.
  3. 3Tasks go in dependency order: first the pure piece that can be tested alone (a data transformation, a calculation), then what uses it, and last what gets removed.
  4. 4Each task ends in a commit. If something goes wrong in task 4, you go back to task 3.
  5. 5The plan lists the review risks: the three to five mistakes that worry you most, and which test covers each. If a risk has no test, a task is missing.
  6. 6Non-code work goes in its own section: what a person does before or after (add a key, approve something, switch off the old thing).

The agent can write the plan from the spec, because the hard decisions are already made. You review it like a construction schedule: is everything from the spec in it, is there anything that was not, can each task be verified on its own? And keep the spec and the plan in the repository: in six months, the document that explains why it was decided this way is worth more than the code.

And an idea you have already seen without its name: a brief is the spec for an agent that writes. The instructions for the blog writers from module 14, and the brief this course was written from, have the same sections: goal, context (what to read first), scope, decisions made (the voice, which 77Rentals facts may be used), constraints (no long dashes, no invented figures), output format, and done criteria (required blocks, tests that must pass).

Prompt

Break this spec into a plan of verifiable tasks

When the spec and the tests are ready and you are about to open the session that builds. Works very well in plan mode.

Read the spec in [FILE OR TEXT] and the acceptance criteria in [FILE OR TEXT]. Explore the project as much as you need to know which files exist and how they are organized.

Write an implementation plan with these parts:
1. Goal and architecture in five lines, with a link to the spec.
2. Global constraints: what no task may violate.
3. Review risks: the three to five most likely mistakes, and which task and which test covers each one.
4. Tasks in dependency order. Each task has: the files it creates or modifies, what it receives and what it delivers (in words), numbered steps that start by writing or running the test that must fail and end with the test passing and a commit with its message.
5. What a person must do before or after, outside the code.

Rules: every task must be finishable in one session and verifiable on its own; if a task has no check, split it or add one. Do not implement anything: deliver the plan and wait for my approval.

Note: Approve the plan task by task, not as a block. If a task feels big, ask for it to be split. The plan is the last cheap moment to change your mind.

Try it now · 15 min

Write the spec for a tool of your own

  1. 1Pick a tool or you already thought about in earlier modules: the invoice extractor from module 8, the scheduled task from module 15, the skill from module 14, or something of your own.
  2. 2Write one page with the eight sections from this module. If one comes out empty, write "not applicable" and why; if one is hard, that is the one that mattered.
  3. 3Write five acceptance criteria, at least one for a failure case. Run them through the two-people test: would someone who is not you reach the same yes-or-no answer?
  4. 4For each criterion, note how it gets verified: automated test, manual steps or human review. If none can be automated, ask yourself which observable fact is missing.
  5. 5Give the spec to your assistant with the second prompt in this module and compare its criteria with yours. Save the result in the repository or in your course notebook: it is the input for the capstone.

What you should end up with: A one-page spec with verifiable criteria, ready to hand to an agent (or a person) without them having to guess anything that matters.

What comes next?

With a spec, criteria and tests, you can hand a task to an agent. The next step is handing over several at once: module 18, "Orchestration: many agents at once", shows how a plan is split across working in parallel, how they review each other, and when it is just extra complexity. The spec you wrote today is what each of them will need.

Before moving on to module 18

  • I can name the eight sections of a spec and say what non-goals and decisions already made are for.
  • I can tell a verifiable acceptance criterion from a wish, and I can rewrite a wish until it can be checked.
  • I understand why tests get written before building and why I should review them more carefully than the code.
  • I have the one-page spec for my tool, with criteria and a way to verify each one.
  • I know what makes a task in a plan the right size: its own check and its own commit.

Mini quiz

  1. 1. You ask an agent to "add validation to the booking form" and it comes back with working code that rejects foreign guests without a national ID. What happened?

  2. 2. Which of these is a well-written acceptance criterion?

  3. 3. Why should the tests exist before the agent builds?

  4. 4. You are reviewing an implementation plan and one task says "improve calendar performance" with no check at all. What do you do?

Official resources from Anthropic

Anthropic’s official courses, organized by level and linked to each part of this course.

See all resources