← Agentic engineering

Module 1 · Brief the agent

Turn a ticket into a brief an agent can carry out inside an existing codebase: the outcome, the scope, what not to touch and the tests that must pass. Then split the work into steps you can merge or throw away one at a time.

Facts checked

An agent starting work in your codebase knows the programming language and nothing about this particular codebase. It does not know which module is frozen for an audit, which helper everyone is supposed to use, or that the date library is pinned for a reason. It fills each gap with the most common answer it has seen, and it does not tell you that it did.

In a brief you fill those gaps before any code is written. By the end of this module you can turn a ticket into a brief with four parts, have the agent say it back, split the work into steps of one pull request each, and recover when the agent changes things it should not have. You can also set an agent to work in a codebase that is large or old.

Before you read
1.

You asked an agent to add a date filter to one page. It reports done and has changed 14 files. What do you do first?

2.

A ticket says: "Add a CSV export to the orders page." Name the four things a brief for an agent should state.

3.

Which instruction is most likely to cut the number of existing tests an agent breaks?

The four-part brief

A ticket assumes that whoever picks it up already knows the codebase. The agent reading your brief knows none of it and will not ask, so write down what the ticket leaves out.

Outcome. One sentence saying who can do what when the work is done. "A support agent can filter the orders page by a date range, and the range survives a reload."

Scope. Where the change lives: the files or modules in play, the helpers to use, and an existing piece of code to copy the shape of. "Filters on this page follow StatusFilter.tsx" saves the agent from inventing a fourth way to write a filter.

What not to touch. Name each one: the date library and its version, the shared query builder, any test file outside the ones listed, generated code, migrations. The agent cannot infer this line from the code, because the reasons are not in the code.

Tests that must pass. The check that proves the outcome, named by file, and the existing tests that cover the code being changed. Where the check does not exist yet, it is written first. Make the agent prove it covers who writes it and how.

Outcome:  a support agent can filter /orders by a date range, and the
          range survives a reload (it lives in the URL).
Scope:    src/orders/OrdersPage.tsx and src/orders/filters/.
          Copy the shape of StatusFilter.tsx. Dates go through lib/dates.ts.
Do not touch: lib/dates.ts and the date library version, the query
          builder in lib/db/, any test outside src/orders/.
Must pass: src/orders/filters/DateFilter.test.tsx (new, written first),
          src/orders/OrdersPage.test.tsx (existing, unchanged).
If a step needs something on the do-not-touch list, stop and say why.

Keep the brief to one screen. Decisions that are already made go in by reference: point at the decisions file or the rule file. An agent that is not told a question is settled will reopen it.

Have the agent say the brief back

Before it writes any code, have the agent restate the brief in its own words and list every assumption it is making. Read the assumptions. They mark the places where this codebase's answer and the most common answer differ.

"I'm assuming the date range is inclusive at both ends and uses the browser's time zone." On this team, orders are bucketed in the account's time zone, and nothing in the ticket says so. Correct it in the brief, then tell the agent to build.

Restating is different from asking permission. One team that told its agents to ask whenever they were unsure found that they asked too often and reopened decisions that had already been made. Restating worked better. The agent states its reading once, you correct it once, and because the brief points at where settled decisions are written down, they are not reopened.

For a change bigger than one step, the restatement becomes a plan, and an agent-written plan can be wrong while every step of it sounds right. Hand the plan to a fresh agent session with one job, which is to prove the plan wrong against the code. In one team's case a five-step plan had the wrong mechanism in four of its steps, and each of the four could have been caught by opening a single file.

Name the tests; skip the process instruction

Two pieces of evidence bear on how to word the "must pass" part of a brief.

A March 2026 preprint, "TDAD: Test-Driven Agentic Development". Pepe Alonso and two co-authors built an automated tool that maps source code to the tests covering it, so that an agent can look up which tests a change affects before it commits. They ran it on SWE-bench Verified with two open-weight models on consumer hardware. On 100 tasks with one of those models, the share of previously passing tests that broke fell from 6.08% to 1.82% when the agent had the map. When the agent was given test-driven-development instructions and no map, the share rose to 9.94%, worse than giving it nothing.

What that measured is an automated tool on a benchmark. No person briefed anything, the models were open-weight ones run on consumer hardware, and its arXiv listing showed no peer-reviewed version when this module was checked. It supports a narrow claim: telling an agent which tests a change affects did more than telling it which process to follow.

Birgitta Böckeler, August 2026. Writing on martinfowler.com, Böckeler had an agent build three greenfield pieces of business logic. Some runs were told to work test-first and some were not, and a second model judged the results without knowing which was which. She found no clearly discernible difference in quality, and the test-first runs used about 3 to 8.5 times the tokens. She calls it a very small sample and an exploratory setup. She also notes that her token count adds up cached re-reads on every turn, so it tracks how many turns a session took more closely than what it cost. Her own conclusion was to stop telling agents to write tests first, and to keep regression tests and check their strength with mutation testing.

The advice this course draws from the two is to name the tests. "Must pass: these two files" is something an agent can act on and you can verify. "Work test-first" is a process instruction, and the evidence so far does not support paying for it.

One pull request per step, one working copy per agent

Split the work so that each step can be merged alone, reverted alone and read in one sitting. A size test: can you read the whole diff in ten minutes and say what it does? If you cannot, split it into two steps.

Put the shared piece first and on its own: the schema change, the shared type, the helper that two later steps both need. The steps that depend on it follow.

Give each step its own branch and its own working copy. git worktree add ../orders-date-filter -b orders-date-filter creates a second working directory on a new branch, backed by the same repository. Git refuses to check out a branch that is already checked out in another worktree, so two agents cannot end up writing to one branch by accident. A new worktree is a fresh checkout. It needs its own dependency install, and its own ports if the app runs there. git worktree remove deletes one once its branch is merged, and refuses if the tree holds uncommitted or untracked files unless you force it. As of December 2026, Claude Code creates one for you with claude --worktree <name>.

Small steps also help you find a fault afterwards. Say something that worked last week is broken today, with forty agent commits in between. You can find the commit that broke it without reading forty diffs. git bisect start <bad> <good> followed by git bisect run <command> checks out commits by binary search and runs your command at each one. Exit code 0 marks a commit good. Any code from 1 to 127 marks it bad, except 125, which means the commit cannot be tested and is skipped. Forty commits take five or six runs.

Bisecting needs two things from you. Each commit has to build, which is one more reason to have the agent commit working steps. And the command has to be a check you trust. Where agent branches arrive as merge commits, git bisect start --first-parent finds the merge that brought the fault in and ignores the commits inside that branch, which you can bisect in a second pass.

Fourteen files for one date filter

The brief above went to an agent without its do-not-touch line. The agent reports that the filter works. Say what you would do at each step before you read it.

  1. 1 · Look at the shape before the content

    git status and git diff --stat show 14 files changed. Three were expected: DateFilter.tsx, its test, and OrdersPage.tsx. The other eleven were not: lib/dates.ts, package.json and the lockfile, the query builder, two pages that have nothing to do with orders, and five test files elsewhere in the repository. Fourteen files for one filter means this is more than one change.

  2. 2 · Read the unexpected files for the warning signs

    Kent Beck's list, from June 2025, of signs that an agent is going off track has three entries: loops, functionality nobody asked for, and any sign of cheating, such as disabled or deleted tests. Two of the three are here. The date library has been swapped for a different one, which nobody asked for. Two tests in shipping-cutoff.test.ts now begin with .skip. The skipped tests matter most: the swap changed how a cutoff time is computed, and the agent skipped the tests that would have shown it.

  3. 3 · Keep the files you asked for

    Read the diff of the three expected files. The filter is there, it is small, and it does what the outcome line said. Stage those three by name with git add and commit them with a message that says what and why.

  4. 4 · Discard the rest

    git restore --staged --worktree . returns every other tracked file to the last commit, including any changes the agent staged. Do it after the commit in the previous step and never before, because this is the one step here that cannot be taken back. git status then lists any new files the agent created. Delete those by name. Reinstall dependencies from the restored lockfile and run the whole suite. It passes, with the two cutoff tests running again.

  5. 5 · Ask again with the boundary stated

    "Do not change lib/dates.ts, the date library or any test outside src/orders/. If the filter needs one of them, stop. Then tell me why." Put the same sentence in the team's rule file so the next session starts with it. Guardrails covers what belongs in that file and what should become a check.

  6. 6 · Give the next attempt its own working copy

    Had the agent run in its own worktree, the recovery would have been two commands: remove the worktree and delete the branch. The main checkout would never have held the swapped library, and no restore could have reached anyone's uncommitted work.

Finding your way in a large or old codebase

To fill in the scope line you need to know where the change goes. In a large or old codebase, finding that out is the hard part, for you and for the agent. An agent knows only the files it has opened, and in a monorepo it cannot open them all.

Map before you change. Start a session whose only output is a map: the entry point for the behaviour, the files on the path, the tests that cover them, who owns each part, and anything that looks odd and deliberate. No edits. Then check three of its claims by opening the files yourself. If one of them is wrong, expect errors in the parts you did not check.

Ask why before you remove. The reasons for old code are often recorded in its history. git log -S"<string>" lists the commits that added or removed a string, and git blame gives the commit behind a line. The commit message or the ticket it links usually says what broke last time. That goes on the do-not-touch list, with the reason.

Pin the behaviour before you change it. Where the code has no tests, have the agent write tests that record what the code does today, wrong answers included. Review them, commit them, and add them to the must-pass list. Then make the change. A test that starts failing now tells you which existing behaviour moved, and you decide whether it should have.

Scope the session to one package. Start the agent in the package's directory with that package's own test command. Name the two or three neighbouring packages it may read and may not change.

When the same edit is needed across hundreds of files, the usual split is a codemod, which is a script that rewrites code mechanically, for the bulk, and an agent for the cases the script cannot handle. Guardrails covers agents that run in CI.

Try it

Fill the gaps in this brief. The ticket: "Support wants a CSV export on the orders page." The team already has a CSV writer in lib/csv.ts, and money is stored in cents.

Outcome:  a ______ can download the orders currently shown on /orders
          as a CSV file, with the active filters applied.
Scope:    src/orders/OrdersPage.tsx, src/orders/export/ (new).
          Write rows with ______, not a new CSV library.
Do not touch: ______, package.json, any test outside src/orders/.
Must pass: src/orders/export/export.test.ts (new, written ______),
          src/orders/OrdersPage.test.tsx (existing, ______).
Before you write code: restate this brief and list your ______.
If a step needs something on the do-not-touch list, ______.
The misconception

A capable agent works out the boundaries for itself, so a short ticket and "follow good practice" are enough.

Why it’s wrong

Most boundaries exist for a reason, and the code does not state it. Nothing in lib/dates.ts says the library is pinned because a previous upgrade moved a shipping cutoff by an hour. The agent in the worked example had no way to learn that from the file when it swapped the library.

A benchmark that compared the two kinds of instruction points the same way. In the March 2026 TDAD preprint, a general instruction to follow test-driven development left more broken tests than no instruction, 9.94% against 6.08%, and naming the tests a change affects brought the figure to 1.82%. It is one tool on one benchmark, so do not rely much on the exact figures.

The correct model

Each line of a brief should name something: a file, a helper, a test, a thing not to touch, a decision already made and where it is written. Where you cannot name it yet, write the question and get it answered before the build. A short brief is fine as long as it names its boundaries.

Check yourself
  • Name the four parts of a brief.

  • What do you have the agent do before it writes code, and what do you read?

  • What did the TDAD preprint measure, and what did it not?

  • An agent's change touched 14 files for a one-page filter. What are the steps?

  • What does git bisect run need from you to be useful on agent commits?

Before the check

A brief names the outcome, the scope, what not to touch and the tests that must pass. The agent restates it and lists its assumptions before building, and a fresh session tries to prove a longer plan wrong. Work goes in steps of one pull request, each on its own branch and in its own worktree, so a bad step is discarded without touching a good one and a fault can be bisected later. In a large or old codebase, map first, ask the history why, and pin the behaviour with tests before changing it.

Check yourself before you go on:

  • Take a ticket from your own backlog. Can you write its do-not-touch line without opening the code?
  • For that ticket, which existing test files cover the code that will change?
  • When did you last discard part of an agent's change and keep the rest? Which files did you keep, and how did you choose them?
  • Could you bisect your main branch today, or do some commits not build?
Sources
1 lab

Labs

Lab 1

Practise this: Brief to merged change

Clone the starter: https://github.com/codeprepdev/agentic-engineering-lab-1-brief-to-merged-change. It is the reporting tool a parcel depot runs each morning, in Python with the standard library only, and you did not write it. Run python3 -m unittest discover and python3 -m depot.report collected to see it work. Read the README, then read the code the way you would read any codebase you are about to change.

The ticket, in full:

Mia (depot counter): Can the collected report take a date range? I need last week's pickups for the courier invoice.

You asked Mia some questions. Her answers:

  • A week runs Monday to Sunday, and both days count. She will type --from 2026-03-02 --to 2026-03-08.

  • "The day" is the depot's day in Brisbane, because the courier invoices by it.

  • With only --from, she wants that day onwards. With only --to, everything up to and including that day.

  • If she types the dates the wrong way round, tell her so and list nothing.

  • The last line, the count and the fee total, must cover only the parcels listed, because it goes on the invoice.

  • With no dates, the report stays exactly as it is.

1. Write the brief. Before any agent sees the ticket, write BRIEF.md at the root of the repository with the four parts: Outcome, Scope, Do not touch and Must pass, and end it with: "Before you write code: restate this brief and list your assumptions." Fill each part from the repo itself, not only from Mia: which files the change lives in, which existing code it should copy the shape of, which files it must leave alone and why, and which test file you will add.

2. Have it said back. Create a branch. Give the brief to Claude Code, Cursor (now Grok Build) or Codex and have it restate the brief and list its assumptions before it writes any code. Under a heading in BRIEF.md that names them (for example ## Assumptions the agent listed), write each assumption as a list item with what you did about it. Correct the brief where an assumption was wrong, and only then tell it to build.

3. Review it and merge it. When it says it is done, run the tests yourself. Read git diff main --stat before the diff itself: if a file outside your scope has changed, find out why before you merge. Merge the branch into main once the change does what the outcome says and nothing else.

Then upload the repository folder. The .git folder is left out, so the mark comes from what the hidden tests find in your files: the date range working on the depot's days at both ends, the total line, the shared files that a careful do-not-touch list would name still unchanged, the existing tests still there with none skipped, a test file of your own for the new options, and the four parts and the assumptions in BRIEF.md. The marking cannot see your branch or your merge, so keeping them tidy is up to you.

Open the lab · needs a free Tarmac account to have your work marked