Skip to content
The AI Agent Factory

13.1 You read, the agent writes

Approved by
Panaversity ·
10 min read

In everyday life. You do not need to write a contract to sign one safely. You need to read it, and ask what happens when the other side is late.

What you will learn. How to predict what code will print, and the five steps you will use in every lesson.

Why it matters. Code repeats its choices every time it runs, as Renee's script did with a Saturday due date. You are the one who checks them.

What is my job when an agent writes the code?

You say what the program must do, and you show that it does.

The old jobThe new job
Write the program line by lineSay exactly what the program must do
Remember the exact syntax, the rules for writing codeRecognize the syntax well enough to question what you read
Get it to runShow it is correct, not just that it runs
Leave it however it comes outKeep it readable, because you and the agent both read it next

Recognition, not recall. You need to see ["V001", "V002"] and know it is a list of two values. You do not need to remember how to write one.

10-80-10 for code. As in Chapter 3: you decide what to build and what "correct" means, the agent writes the code, and you check it against what you decided.

How do I learn to read code with an agent beside me?

PRIMM-AI+ is this book's method, in five steps. The agent is your partner at every step, and nothing it says is accepted without a check.

StepWhat you doThe agent's role
PredictSay what the code will do before anything runsStays quiet. The guess is yours
RunRun it and see the real outputRuns it for you, with your permission
InvestigateCompare your guess with the output, and ask whyExplains a line when you ask: "What does line 3 do?"
ModifyChange one thing, predict again, run againMakes the edit you describe
MakeSpecify your own version, let the agent build it, then verifyWrites code against your specification

Why predict before I run?

A wrong guess shows you which part of your picture is wrong. It works like a bank reconciliation: a $25 difference sends you to the fee you forgot. So write your guess down first. A guess made after the output is not a guess.

A first program. Here is one vendor. Pick your language on the tabs. These words are enough to read it:

  • A value is one piece of data.
  • A string is a value made of text, in quotes, such as "Net 30".
  • A list holds values in order, between square brackets. Here vendor is a list of three strings.
  • A variable is a name for a value. const makes one.
  • vendor[0] takes one item from the list. The number is its position.
  • console.log(...), or print(...) in Python, prints a line.
const vendor = ["V001", "Midwest Packaging Co.", "Net 30"];
console.log(vendor[0]);
console.log(vendor[2]);

Now predict. Write down the two lines it prints before you read on.

Both print:

V001
Net 30

Expected the name on the second line? You counted from 1. Code counts positions from 0, so [0] is the first item and [2] is the third.

At work. Ana Morales, the accounts payable (AP) analyst at Brightline, guessed the second line would be the name, because [2] looked like "the second item". It printed Net 30. She asked, "Why is vendor[2] the terms?" Now she counts from 0.

Where the languages differ. Python needs no const and no ;.

How do I set up to try this?

Once, for the whole chapter.

  1. Download brightline-practice-ch13.zip, and unzip it.

  2. Open the brightline-practice-ch13 folder in your agent. Set the agent to ask before it acts: Manual in Claude Code, Ask for approval in Codex. In OpenCode, first add the rules that 13.11 describes.

  3. You need three programs: Git, Node.js, which runs TypeScript files, and uv, which runs Python. Ask first:

    Do I have Git, Node.js 24 or later, and uv? Please don't install anything. For anything missing, tell me the official way to install it here, and wait for my yes.

  4. The folder's AGENTS.md, the rules file from Chapter 12, says TypeScript. For Python, send: "Please set my language in AGENTS.md to Python."

Try it

Run. Send: "Please run the file in 13-1 and show me what it prints. Don't explain it yet." Compare it with your guess.

Investigate. If you were wrong, ask: "I thought it would print [my guess], but it printed [what I saw]. Which line does that, and why?"

Modify. Send: "Please change vendor[0] to vendor[1] in the file. Don't run it yet." Write down what each line will print. Then ask the agent to run it.

Make. Send: "Please make a new file in 13-1 called mine that prints the terms, then the id. Don't run it yet." Say what it will print. Then ask the agent to run it.

What you should see. The first line is now the name, Midwest Packaging Co. mine prints Net 30, then V001.

The operating rule: predict before you run, every time.

Figure 13.1. The PRIMM-AI+ loop as five steps: Predict, Run, Investigate, Modify and Make. At each step you predict, compare, explain or specify, and the agent waits, runs, explains, edits or builds. The loop repeats with the next piece of code, and claims are checked by running code and tests.

Figure 13.1. The PRIMM-AI+ loop. Predict, Run and Investigate build reading. Modify and Make are where you start directing the agent. The agent explains on request. A run or a test decides.

Next. 13.2 shows the tools that check a file before you read it.

Check yourself

Question 1 / 8

0 answered

An agent wrote this TypeScript. invoice is a list of three strings.const invoice = ["INV-6201", "V014", "Net 30"]; console.log(invoice[1]);What does it print?

Owner
Panaversity