Skip to article frontmatterSkip to article content
Site not loading correctly?

This may be due to an incorrect BASE_URL configuration. See the MyST Documentation for reference.

Lab 12: Prompting a coding agent

Objectives: LO-12.1, LO-12.2, LO-12.3
Prerequisites: the Module 12 reading
Time: about 2.5 hours

In this lab you trace an illustrative coding-agent session, write two task prompts, run the tests of a copy of the fictional shop package from Python, and review three proposed diffs against their task.

No cell runs a coding agent or calls a model. The session in data/agent/session.json and the diffs in data/agent/diffs.json were written for this course, in a simplified format that isn’t Claude Code’s own; they are illustrative, not model output. The package is the course’s starter-repo/, and every test run uses a scratch copy, so the starter folder never changes.

Each exercise ends with a check cell that prints passed or fails with a message that says what is wrong. Run the cells in order, from the top, in a fresh kernel. The checks fail until you finish the exercise above them.

Setup

Identify information sources

Each turn has an event (user, model, or tool), an origin that says where its content came from, and a short detail. Predict which turn tells the agent how underscores work, then print the trace.

Exercise L12.1 (LO-12.1, ★★, about 25 minutes)

Find a decision following evidence. Write decision_positions(turns). Return the zero-based positions of the turns whose event is "model" and whose origin is "tool_result". If a turn lacks either field, don’t count it. In your notes, say exactly what the tool output before each of those turns supplied.

Exercise L12.2 (LO-12.2, ★★, about 25 minutes)

Write a checkable agent task. Write task_prompt(task), where task is the dictionary in data/agent/task.json. Return a prompt that contains the task’s goal word for word, both file names in files, each sentence in constraints, and the verification command, and that asks the agent to report what it did, with the word “Report”. Score your prompt with the prompt rubric. In your notes, draft and score a second prompt, one that prevents a pricing regression (a change that breaks prices that used to be right).

Exercise L12.3 (LO-12.3, ★★, about 25 minutes)

Supply a local check command. Write check_package(path). Run the current Python (sys.executable) with -m unittest discover -v in the folder path, capture the output as text, and return the process’s exit status: 0 when every test passes, and nonzero otherwise. Pass the command to subprocess.run as a list of arguments, without a shell. The check copies the starter to a scratch folder first, so your function never runs in the starter itself.

Exercise L12.4 (LO-12.3, ★★, about 25 minutes)

Review three diffs. Write reviews(). Return a dictionary keyed by the diff IDs "A", "B", and "C". Each value is a pair: the review, one of "accept", "regression" (it breaks behavior the task said to keep), or "out_of_scope" (it changes something the task didn’t ask for), and the changed line that supports it, copied from the diff without its leading + or -. Compare each diff with the task’s goal and constraints, and run the tests on a scratch copy if that helps. Don’t apply a draft to the starter folder itself.

Summary

  • A coding agent’s model turns rest on tool results, the task, or the conversation; the tool turns are the evidence, and a final summary is only a report.

  • A checkable task prompt states the goal, the files, the constraints, the verification command, and the report you expect.

  • A check reports through its exit status, and runs on a scratch copy, never on the original.

  • A review compares every changed line with the task: a passing suite can still hide a regression it doesn’t test, or a change outside the task’s scope.