AI Engineering from Scratch / Stage 2. The model in the product
Turn a new feature into a spec with criteria, watch tests fail before the code and pass after it, and prove they catch a bug.
Outcome: `specs/repeat-tickets.md` + tests
What you do today. You build the lesson's feature, repeat-tickets ("repeat requests"): its spec, tests and code live in the l04 tag, and you walk the whole path from requirement to verified change. After the lesson you build your own feature with the same loop, in the "In your project" block.
The path every change to a program goes through is called the SDLC (software development life cycle): requirement, plan, code, check, and the decision to keep it. With an agent, code gets written in minutes. Most of the time now goes into decisions before the prompt and checks after it.
The support team lead asks: "Show me when a customer writes again." In five minutes the agent adds a counter, and the tests are green. The next day an operator sees "1 repeat" on every new request: the service first saved the request to history and then found that same request there. Nobody wrote down what exactly counts as a repeat.
On the left of the diagram is what the agent does in minutes: code, SQL, tests, an endpoint. On the right is what stays with you: what counts as a repeat, the boundaries, where the state lives, whether the tests catch a bug. The agent won't tell you what you missed on that side. That part is filled in by the spec you will write today.
For this lesson you need: the l03 tag with the finished service from lesson 3, which your branch starts from, with uv run pytest -q green on it; Git with your first commits; an assistant open in the starter folder. At the start of the lesson, in the starter folder:
If the second command says error: pathspec ... did not match or fatal: invalid reference: lesson-03, you don't have the branch or the file with your own cases, and that's fine: skip it (tags and branches are explained at the start of lesson 3). If git switch refuses because of uncommitted changes, commit them on the lesson 3 branch first: git add -A, then git commit -m "кінець уроку 3". Run this lesson's Python blocks the way the "Where to run Python blocks" box in lesson 3 describes.
What changed in the contract. The card stays at v1, CardResult is unchanged. New: the table tickets(ticket_id, customer_id, order_id, text_hash, created_at) (a table is rows of records with the same columns, like a sheet in Excel) in the file data/support.db, the function count_repeats(conn, order_id, now) -> int and the endpoint GET /api/repeats?order_id=DEMO-1042. normalize_order_id from lesson 3 now understands Cyrillic "е", "о" and "м" in the number. The finished version of all this lives in the l04 tag.
Recall from lesson 2. You type "commit", and the pre-commit-check skill stays silent. What do you fix first, and why?