Worked examples¶
← Technical edition start · The friendly primer
The practices from the technical edition, applied to fifteen jobs: five for system administrators, five for developers and five for ML engineers. Each one has the same parts:
- Its home: the repo or folder, and what lives in it.
- Rules worth adding to that repo's rules file.
- Go ahead and ask me first: what the agent may do alone, and what waits for
you. The second list is the one to turn into
askanddenyrules (GUARDRAILS.md). - A plan in small steps, each with a check.
- Prompts to try.
- Watch out for: where it's most likely to go wrong.
The services, hosts and numbers are made up. Copy what fits and change the rest.
At work: use only the AI tools your employer has approved, with the access they've approved. None of these examples give the agent production credentials. Where production is involved, the agent reads exports, plans and dry runs, and a person or the pipeline makes the change.
Contents: a week with an agent · Sysadmin: 1. On-call triage · 2. Runbook to playbook · 3. Terraform changes · 4. A cluster upgrade · 5. Fleet hygiene · Developer: 6. A bug · 7. A feature · 8. A new codebase · 9. A dependency upgrade · 10. A big migration · ML: 11. A new dataset · 12. Experiments · 13. Notebook to pipeline · 14. An LLM feature · 15. A run that goes wrong · make your own
A week with an agent¶
Here's how a small team might use it in an ordinary week, without handing it the keys.
- Monday: the overnight alert was noisy. The on-call engineer pastes the alert and an exported log slice, and gets back a timeline, three likely causes ranked, and the query that would tell them apart.
- Tuesday: a developer picks up a bug. The agent writes a failing test, then the
fix, on a branch. The pull request shows both, and the test fails on
main. - Wednesday: the ML engineer asks which of last week's twelve runs beat the baseline on the held-out set. It answers from the metrics files, with paths, and points out that two runs used a different split.
- Thursday: the infra repo gets a Terraform change. The agent writes it and runs
plan. A person reads the plan and applies it. - Friday: everyone's agent updates the handoff notes in their repos. Monday starts with "read HANDOFF.md" instead of "where was I?"
Sysadmin¶
1. On-call triage and the write-up¶
The situation: an alert fires at 2 AM. You have dashboards, logs and a vague memory of the last time this happened.
Its home: an oncall repo with runbooks per service, a postmortems/ folder, and
an incidents/ folder where each incident gets a timeline file while it's live.
Rules worth adding:
- During an incident, answer in short lines: what you think is happening, how sure you are, and the one command or query that would confirm it.
- Never suggest a fix without the command to check whether it worked.
- Timestamps in UTC, always, with the source of each one.
- Postmortems are blameless: describe what the system and the process allowed, not who typed what.
Go ahead: read runbooks and exported logs, draft timelines, suggest read-only queries, draft the postmortem. Ask me first: any command that changes a system. In practice the agent has no access to production at all; you run the commands and paste back the output.
A plan in small steps:
- Before the next incident: put each service's runbook in the repo, with how to check health and the usual causes. Check: one runbook per service you're on call for.
- During one: open
incidents/<date>-<service>.mdand paste alerts and outputs as you go. Ask for a running timeline. Check: every entry has a time and a source. - After: ask for a postmortem draft from the timeline, using the template. Check: the action items each have an owner and a ticket.
- Every month: ask which runbooks the last few incidents showed were wrong or missing. Check: the runbooks change.
Prompts to try:
Here's the alert and the last 200 lines of the service log, exported. Give me a timeline in UTC, your top three explanations ranked by likelihood, and for each one a read-only command or query that would confirm or rule it out. Say what you're unsure of.
Turn incidents/
<date>-<service>.md into a blameless postmortem using postmortems/TEMPLATE.md. Keep every timestamp as written. List the action items separately, each one small enough to finish in a week.
Watch out for: a confident story that fits the first few log lines. Ask for the evidence that would rule each theory out, and paste only exported, scrubbed logs.
2. A runbook turned into a playbook¶
The situation: a twelve-step wiki page that someone runs by hand every quarter, and gets slightly differently wrong each time.
Its home: your config-management repo (Ansible here) with roles, inventories for
dev and staging, and the old runbook copied into docs/ for reference.
Rules worth adding:
- Every task must be idempotent: running it twice changes nothing the second time.
- Use the built-in modules before
shellorcommand. Whenshellis the only way, addcreates,removesor achanged_when. - Run
ansible-lintandansible-playbook --syntax-checkbefore saying it's done. - Never touch the production inventory.
Go ahead: write roles and playbooks, run lint, run --check --diff against dev.
Ask me first: any run without --check, and anything against staging.
Production runs go through the pipeline.
A plan in small steps:
- Today: ask it to turn the runbook into a numbered list of desired end states ("nginx 1.x installed", "config file has this line"), not commands. Check: every step in the runbook maps to a state.
- Next: one role per group of states, with tests or
asserttasks for each. Check: lint passes. - Then:
ansible-playbook -i inventories/dev site.yml --check --diff. Check: the diff is what the runbook would have done. - Then: a real run on one
devhost, by you, then a second run. Check: the second run reports zero changes.
Prompts to try:
Read docs/old-runbook.md. Don't write any Ansible yet. List the end state each step is trying to reach, which steps aren't idempotent as written, and anything that depends on the order. Ask me about anything ambiguous.
Watch out for: shell tasks that always report "changed", handlers that never
fire, and secrets that slipped from the runbook into variables. Secrets go in your
vault, not the repo.
3. Terraform changes and drift¶
The situation: a steady trickle of small infrastructure changes, and a suspicion that what's deployed no longer matches what's in the repo.
Its home: the infra repo, with modules, one folder per environment, and the
pipeline that runs plan on pull requests and apply after review.
Rules worth adding:
- Run
terraform fmt -checkandterraform validatebeforeplan. - After
plan, list every resource that will be destroyed or replaced, first, before anything else. - Never run
applyordestroy. Never edit state. - Tag every new resource with
ownerandenv.
Go ahead: edit modules, run fmt, validate and plan against dev with
read-only credentials, explain plans.
Ask me first: anything outside envs/dev/. apply, destroy and state
commands are deny rules, as in the
starter settings file.
A plan in small steps:
- Drift first:
terraform plan -refresh-onlyin each environment, run by you or the pipeline, and paste the output. Check: you know what has drifted. - One change per pull request, written by the agent, with the plan in the description. Check: the plan contains nothing you didn't ask for.
- A person reads every plan and the pipeline applies it. Check: no
-/+ordestroyline gets past without someone's name on it.
Prompts to try:
Here's the output of terraform plan for envs/dev. Start with every destroy and replace, and why each is happening. Then anything that changes networking or permissions. Then the rest in one line each.
Add a storage bucket for
<purpose>to envs/dev using our storage module. Versioning on, no public access, tags owner and env. Show me the diff and run validate and plan.
Watch out for: a rename that becomes destroy and create (a moved block fixes
that), provider version bumps that come along for the ride, and summaries that leave
out the one line that matters. Read the plan yourself.
4. Getting ready for a cluster upgrade¶
The situation: the Kubernetes cluster is two minor versions behind, and the next upgrade removes some APIs your manifests still use.
Its home: the repo with your manifests or Helm charts, plus an upgrade/ folder
for this project's plan and notes.
Rules worth adding:
- Work from the official release notes and deprecation guide for the target version. Paste or fetch them; don't rely on memory.
- For every change, say which API version it moves from and to, and which release removes the old one.
- Render charts with
helm templateand validate the output; don't guess what a chart produces.
Go ahead: search the repo, render charts, update manifests, run
kubectl apply --dry-run=server against the dev cluster.
Ask me first: anything against a shared cluster other than dev. The upgrade
itself is yours.
A plan in small steps:
- Inventory: every
apiVersionin the repo and in rendered charts, with counts. Check: a table inupgrade/PLAN.md. - Ground truth: the API server's
apiserver_requested_deprecated_apismetric, or its audit log, shows what clients actually call, including things not in this repo. Ask whoever runs the cluster for an export. Check: nothing on the list is a surprise. - One component per pull request, each validated against
dev. Check: the dry run passes. - Upgrade
dev, thenstaging, with time between them for things to break.
Prompts to try:
Find every apiVersion in this repo, including what our Helm charts render to. Compare them with the deprecation notes I've pasted for version
<target>. Make a table: file, kind, current version, replacement, the release that removes it, and anything beyond a version bump the move needs.
Watch out for: fields that changed shape between API versions, not just the version string, and operators or charts you don't own that generate old APIs.
5. Fleet hygiene scripts¶
The situation: full disks, expiring certificates, old log files, stale cron jobs. Small scripts would fix most of it, and small scripts are where accidents happen.
Its home: a scripts repo with one folder per script, each with a README, tests,
and a config.example file.
Rules worth adding:
- Every script that changes anything has a dry run, and dry run is the default. Real
changes need
--apply(or-WhatIfand-Confirmin PowerShell). set -euo pipefailin Bash;shellcheckclean.- Print what it will do, per item, before doing it. Log what it did.
- Never hard-code hostnames or paths: they come from arguments or config.
Go ahead: write scripts and tests, run shellcheck, run dry runs against a temp
folder or a test VM.
Ask me first: running anything on a real host. The first real run is always yours,
on one host.
A plan in small steps:
- One script at a time, starting with a read-only report: certificates expiring in 30 days, disks over 80%. Check: the report matches what you see by hand.
- Then a fix with a dry run, like the pruning scripts. Check: the dry run lists exactly what you'd have chosen.
- One real host, then a few, then the fleet, through your usual tooling. Check: the logs match the dry runs.
Prompts to try:
Write a read-only Bash script that reports TLS certificates under
<path>expiring in the next<days>days: path, subject, expiry date, days left. No changes to anything. shellcheck clean. Add a test that uses a self-signed cert it makes in a temp folder.
Watch out for: globs that match more than you meant, find without -maxdepth,
time zones in date maths, and anything that follows symlinks.
Developer¶
6. Fixing a bug from an issue¶
The situation: an issue with a stack trace, a vague description and "it works on my machine" in the comments.
Its home: the service's repo, its rules file, and a branch per fix.
Rules worth adding:
- Reproduce first. A bug fix starts with a failing test, and the test goes in its own commit.
- Never change an existing test's expectation without saying why the old one was wrong.
- Run
make checkbefore saying it's done.
Go ahead: read code, run tests, create a branch, write the test and the fix, commit. Ask me first: pushing, and changing anything outside the module the bug is in.
A plan in small steps:
- Explore: ask where the stack trace leads and what could produce it, with file:line. No edits yet. Check: you agree with the theory.
- Reproduce: a failing test, run and shown failing for the right reason. Check: the failure message matches the issue.
- Fix: the smallest change that makes it pass, then the full suite. Check: the diff touches only what it needs to.
- Pull request: with the cause in one paragraph. Check: the test fails on
mainand passes on the branch.
Prompts to try:
Here's issue
<number>with its stack trace. Don't change anything yet. Trace the path through the code with file:line, tell me your best explanation and one other, and propose a test that would fail today because of this bug.
Watch out for: a fix that handles the symptom (a None check) instead of the
cause (why it was None), and a "flaky test" that's really a race condition.
7. A feature in small pull requests¶
The situation: a feature that touches the API, the database and the UI, and would make one unreviewable pull request if you let it.
Its home: the repo, with a plan file on the feature branch: PLAN.md, from the
template.
Rules worth adding:
- Each step in the plan is one pull request someone can review in fifteen minutes.
- Migrations are backward compatible: the old code must still run against the new schema.
- New behavior goes behind a feature flag until the last step.
Go ahead: write the plan, then one step at a time: code, tests, commits on a branch. Ask me first: starting the next step before the last one is reviewed, adding a dependency, changing a public API.
A plan in small steps:
- Plan mode first: ask for a plan with the steps, their order, what each one proves, and the risks. Check: you'd approve each step as a pull request on its own.
- Schema, behind nothing: an additive migration. Check: the old code passes its tests against it.
- The API, behind a flag. Check: flag off, nothing changes.
- The UI, behind the same flag. Check: a person has clicked through it.
- Turn it on, then clean up the flag in a later pull request.
Prompts to try:
Read PLAN.md and the handoff note. Do the next unchecked step only. When you're done, tick it, update the handoff note with what's next and anything you learned, and stop.
Watch out for: steps that quietly grow. If a step's diff is twice what you expected, stop and split it.
8. Finding your way around a new codebase¶
The situation: a new team, a new repo, a hundred thousand lines and a README from three years ago.
Its home: the repo itself, plus a docs/notes/ folder (or your own notes outside
the repo) for what you learn.
Rules worth adding:
- This week is read-only. Don't edit anything except
docs/notes/. - Cite file:line for every claim about the code. Say when you're inferring from names.
Go ahead: read, search, run the tests and the build, write notes. Ask me first: everything else.
A plan in small steps:
- The map: entry points, the main modules and what each owns, where config comes
from, how a request flows through. Check:
docs/notes/MAP.md, with paths. - The build: how to run it and test it locally. Ask it to try. Check: you can run the tests from what it wrote.
- One real request, traced end to end. Check: you could explain it to someone.
- The rules file: ask it to draft one from what it learned, for you to edit. Check: it's short and true.
Prompts to try:
I'm new to this repo. Without editing anything, explain how a request to
<endpoint>flows through the code, from the router to the database and back, with file:line at each step. Then list the three parts of the code you'd read first, and why.
Watch out for: confident explanations from file names alone. Ask "did you read that file, or are you guessing from its name?"
9. A major dependency upgrade¶
The situation: a framework or library is a major version behind, the changelog is long, and the last person who tried gave up.
Its home: a branch for the upgrade, with UPGRADE.md listing every breaking change
and its status.
Rules worth adding:
- Work from the library's own migration guide and changelog, pasted or fetched, for the exact versions involved.
- One breaking change per commit, with the test that covers it.
- Don't upgrade anything else while you're there.
Go ahead: read the guide, edit code, run the suite, commit.
Ask me first: installing, adding or removing packages (ask rules), and
suppressing a warning or a test.
A plan in small steps:
- The list: every breaking change in the guide between your version and the
target, and whether this code is affected, with file:line. Check:
UPGRADE.md. - Bump the version in one commit, with the lock file. Check: you know what else the lock file moved.
- One breaking change at a time. Check: the suite passes after each.
- Deprecation warnings last, in their own commits.
Prompts to try:
Here's the migration guide from version
<x>to<y>. For each breaking change, tell me whether our code is affected, with file:line for every place. Don't change anything yet. Mark the ones you're not sure about.
Watch out for: fixes based on the agent's memory of a different version, and transitive upgrades in the lock file that nobody asked for. Read the lock file diff.
10. A large mechanical migration¶
The situation: the same change in 300 files: a renamed function, a new logging call, a config format.
Its home: a branch for the migration, a script that does the mechanical part, and a list of the files that need a person.
Rules worth adding:
- Prefer a script or codemod you can rerun over hand edits. Commit the script.
- Split the work by directory, one pull request each.
- Anything the script can't handle goes on a list, not into a hand edit.
Go ahead: write and run the script on the branch, run tests, commit per directory. Ask me first: pushing, and any hand edit outside the list.
A plan in small steps:
- The script, with a dry run that prints the diff. Check: run it on one directory and read every change.
- The exceptions: everything the script skipped or couldn't parse, in a list. Check: the list is short enough to do by hand.
- One directory per pull request. For speed, run several at once in worktrees. Check: each pull request is small and the tests pass.
- The exceptions by hand, last.
Prompts to try:
Write a script that replaces
<old call>with<new call>across src/, preserving arguments and comments. It must have a dry run that prints a unified diff. List every match it doesn't handle with file:line, instead of guessing.
Watch out for: regex-based changes inside strings and comments, generated code that will be overwritten, and the long tail the script quietly skipped.
ML¶
11. A new dataset¶
The situation: a new table or a folder of files, a deadline, and a stakeholder who wants a model by Friday.
Its home: the project repo with data/README.md describing every source, an
eda/ folder for notebooks or scripts, and a reports/ folder.
Rules worth adding:
- Never print more than a few rows of raw data. Summaries, not dumps.
- Every number in a report comes from a script in the repo that produced it.
- Treat anything that looks like personal data as a stop: tell me, don't use it.
- Never modify raw data. Derived data goes in a new file with the script that made it.
Go ahead: write and run profiling scripts on the approved copy of the data, draft the data README. Ask me first: dropping rows or columns, joining in another source, anything that leaves your machine.
A plan in small steps:
- Profile: row counts, types, missing values, distributions, duplicates, the time
range, label balance. Check:
reports/profile.md, generated by a script. - Questions: what each column means, how it's collected, and when it's known. Check: the open questions go to whoever owns the data.
- Leakage check: anything computed after the thing you're predicting, and the same users or time periods on both sides of a split. Check: a written split strategy.
- A baseline before anything clever. Check: one number to beat.
Prompts to try:
Write a script that profiles data/raw/
<file>: shape, dtypes, missing rate per column, top values for categoricals, summary stats for numerics, duplicate rows, and the time range of<date column>. Save the output to reports/profile.md. Don't print raw rows.Here's the column list and the profile. Which columns could leak the target, or be known only after the event we're predicting? For each one, say why and how to check.
Watch out for: an ID or a timestamp that encodes the label, and a random split where the real world splits by time or by user.
12. Running and comparing experiments¶
The situation: a dozen runs with slightly different configs, and nobody quite sure which one is the good one.
Its home: the training repo, with configs in version control, a run log
(experiments.md or your tracking tool), and each run's metrics written to a file.
Rules worth adding:
- Every run has a config file, a seed, the git commit and the data version, logged.
- Quote metrics from the run's metrics file, with the path. Never from memory.
- Before comparing two runs, list everything that differs between them.
- Change one thing at a time unless I say it's a sweep.
Go ahead: write configs, launch runs on the dev queue within the budget, read logs and metrics, update the run log. Ask me first: anything over the budget or on shared hardware beyond your quota, deleting checkpoints, changing the evaluation code.
A plan in small steps:
- Reproduce the baseline from its config. Check: the number matches within noise.
- One change per run, with a line in the run log saying what and why. Check: every run in the log has a config and a result.
- Compare against the baseline, on the same split and eval code, with several seeds when the difference is small. Check: the difference is bigger than the seed-to-seed spread.
- Clean up checkpoints with a dry run first, keeping the best per run, like
prune_checkpoints.py. Check: the dry run keeps what you'd keep.
Prompts to try:
Compare runs
<a>and<b>. First list every difference in config, code commit, data version and seed. Then their metrics from metrics.json, with paths. Say whether the difference is bigger than the spread across seeds of the baseline, and if we don't know that yet, how many runs it would take to find out.
Watch out for: a "better" run that evaluated on a different split, a metric computed slightly differently, and one lucky seed.
13. A notebook turned into a pipeline¶
The situation: the notebook works, mostly, if you run the cells in the right order. Now it needs to run every week without you.
Its home: the same repo, with a src/ package, tests/, and the notebook kept as
a reference until the pipeline matches it.
Rules worth adding:
- Match the notebook's output first; improve it later, in separate commits.
- Every step is a function with typed inputs and outputs, and a test with a small fixture.
- Paths, dates and credentials come from config or the environment, never the code.
Go ahead: convert, refactor into functions, write tests, run the pipeline on the sample data. Ask me first: changing what the pipeline computes, scheduling it, writing anywhere other than the output folder.
A plan in small steps:
- Export it:
jupyter nbconvert --to scriptgives a starting point. Ask for the hidden state: cells that depend on order, variables redefined, outputs used as inputs. Check: a list of every surprise. - Golden output: run the notebook once, top to bottom on a clean kernel, and save its outputs. Check: you have a file to compare against.
- Functions and tests, one step at a time. Check: the pipeline's output matches the golden output.
- Then improve, one change per commit.
Prompts to try:
Read analysis.ipynb. Before writing any code, list the hidden state: cells that only work if run in a particular order, variables that are redefined, files read that another cell wrote, and hard-coded paths or dates. Then propose the functions the pipeline should have.
Watch out for: a pipeline that runs cleanly and produces slightly different numbers. Compare against the golden output, not against "looks right".
14. Evaluating an LLM feature¶
The situation: a feature built on a language model (a summarizer, a classifier, a support bot) and a prompt that everyone keeps tweaking.
Its home: the feature's repo, with the prompt in a file, an evals/ folder with
cases and results, and the eval harness.
Rules worth adding:
- Every change to a prompt, a model or a parameter is run against the eval set before and after, and both results go in the pull request.
- Every bug report from real use becomes an eval case, scrubbed of real data.
- Never put real customer data in eval cases.
Go ahead: write cases, edit the prompt on a branch, run evals within the budget. Ask me first: anything over the budget, changing the model or anything in production.
A plan in small steps:
- Twenty real cases, scrubbed, with checks: the things a good answer must and must not contain. Check: the current prompt's pass rate, run three times.
- One change at a time, with the eval before and after. Check: the pass rate, and which cases moved.
- Add every failure you see in real use. Check: the set grows each week.
Prompts to try:
Here are ten real inputs, scrubbed, and what a good answer does for each. Write evals/cases.jsonl in the harness's format: for each case, two or three checks a script can run. Prefer checks on facts and format over exact wording.
Here are the eval results before and after my prompt change. Which cases changed, in which direction, and is any of it more than run-to-run noise?
Watch out for: a prompt tuned to pass the eval instead of serving users, checks so loose everything passes, and a model grading its own answers.
15. A training run that goes wrong¶
The situation: the loss goes to NaN at step 40,000, or the run is three times slower than last week and nobody changed anything.
Its home: the training repo, with logs and the config of the failing run, and a small config that reproduces the problem fast.
Rules worth adding:
- Find a small, fast reproduction before changing anything.
- Change one thing at a time, and log each attempt with its result.
- Don't paper over it: no lower learning rate, no gradient clipping and no skipping bad batches until we know the cause.
Go ahead: read logs, write and run small repro configs on the dev queue within the budget, add logging. Ask me first: long runs, anything on shared hardware beyond your quota, changes to the main config.
A plan in small steps:
- Narrow it: what changed since the last good run: code, data, config, library versions, hardware. Check: a list with evidence for each.
- Reproduce small: the shortest run that shows the problem. Check: it fails in minutes, not hours.
- Instrument: for NaNs, log the loss, gradient norms and activation stats per
step, and try
torch.autograd.set_detect_anomaly(True)on the small run (it's slow). For slowness, profile one step withtorch.profilerand check the data loader on its own. Check: you know where it goes wrong. - Fix the cause, then rerun the small repro and the real one.
Prompts to try:
The run with config
<file>hits NaN loss around step<n>. The last good run used<other file>. List every difference between them, including library versions from the two environment files. Then propose the smallest experiment that would tell the top two causes apart.
Watch out for: fixes that hide the symptom, like a lower learning rate that just makes it fail later, and a "data problem" that's really one corrupt file. Ask which batch it was.
Make your own¶
Every example has the same shape, so you can make one for any job. Paste this into your agent, in the repo:
I want to set up this repo for
<job>. Read the repo first. Then ask me a few questions, one at a time, and write: what should live where, five lines for the rules file, a "go ahead" and "ask me first" list (and the permission rules for the second), a plan in small steps with a check for each, and two prompts I'll use a lot.
← Back: Verifying the work · Next: Rules files → · Technical edition start