Appendix
Field notes: building this booklet with an agent
What DuckDB 2.0's agent mode changed in practice: measured output size with it on and off, its order-independent result hash as a regression check, and the review process behind each chapter.
Every chapter in this booklet was written by an AI agent that ran DuckDB from a shell and read what it printed. These notes cover three things that shaped the work: how much text DuckDB prints to an agent, how its result hash catches a changed output, and how each chapter was reviewed before it was merged.
Output size
DuckDB 2.0's CLI switches to agent mode when an AI_AGENT environment variable is set and its output goes to a pipe. Results print as Markdown tables with typed headers. A result of more than 1,000 rows or 10,000 bytes is cut to its first and last rows plus a count. Errors are JSON on standard error, and a footer gives the row count and a hash of the whole result. -agent and -no-agent force either mode. The measurements below ran the same commands both ways on the same machine.
| Ch 7 checks.sql (row counts and known-value checks) | 94,891 | 13,385 | 8,924 | 4,740 |
| Explore a table: DESCRIBE, SUMMARIZE, 20 rows | 26,164 | 11,564 | 6,824 | 5,007 |
| Select every row of a 63,247-row table | 15,591 | 8,736 | 3,981 | 3,292 |
Running Chapter 7's checks.sql printed 94,891 bytes in the default mode and 13,385 in agent mode, 86% less. Most of the difference is the default mode's boxes. Box-drawing characters alone took 68,100 bytes, at 3 bytes each in UTF-8. Tokens fell less, from 8,924 to 4,740, because a tokenizer packs long runs of the same character into few tokens. Exploring a table (DESCRIBE, SUMMARIZE and 20 rows) went from 6,824 tokens to 5,007. Selecting all 63,247 rows of the store table printed the first and last rows in both modes, since the default box mode also shortens long results, so the saving there is smaller.
The bigger change was not in size. An agent reading a box table has to count columns of padding, while a Markdown table with name:TYPE headers parses in one pass. A cut-off result says so and gives the count, where in a box table a shortened result is easy to read as complete. And because errors arrive as JSON, the agent can read the error type and message without matching on text.
Result hashes as a regression check
When agent mode reads a whole result, the footer carries a 16-digit hash of it. The hash does not depend on row order, so two queries that return the same rows in a different order get the same hash, and any changed value changes it.
| as stored | 0938f621a7ab352e |
| sorted by geoid | 0938f621a7ab352e |
| sorted by ratio, descending | 0938f621a7ab352e |
| ratio rounded to 3 decimals | bef43f53e29b71a0 |
Unsorted, sorted by geoid and sorted by ratio, the hash is 0938f621a7ab352e. Rounding one column to three decimals changes it to bef43f53e29b71a0. That makes the hash a quick check that a refactor did not change a pipeline's output: run the final queries before and after, and compare one line.
Each chapter's out/manifest.json stores a hash of every output, computed in SQL as bit_xor(hash(row)). It follows the same idea, and a script can compare it without the CLI. Rerunning Chapter 7 end to end on 2026-10-26 gave the same row count for all 51 outputs. 3 of them hold run timings and are left out of the comparison. Of the other 48, 45 had the same hash and 3 did not: the tract table and the Map Lab tract files for Chicago and Detroit.
The hash only says that something changed, so the next step was to find what. In Chicago, 3 tracts have two dollar stores at exactly the same distance, and the pipeline's arg_min(id, d) may return either one, so a rerun can name a different nearest store. The fix is a tie-break, arg_min(id, (d, id)). Detroit has no such tie, and the cause of its change has not been found yet. Without the hashes, neither difference would have been noticed: every row count matched.
Review before merge
Each chapter was built by one agent working in its own branch, and reviewed by a second agent that started with no context from the first, reading only the diff, the guide and the data. The reviewer sorted findings into Important (wrong numbers, unsupported claims, broken checks), Nit (wording, small consistency fixes) and Pre-existing (problems outside the diff). The author agent fixed the Important and Nit findings. A fresh reviewer then read only the new diff. Chapter 8's first review found 3 Important and 9 Nit findings, and Chapter 4's found 3 Important and 12 Nit. Chapter 1 went through a second round. Follow-ups that did not block a merge were posted as a comment on that chapter's pull request.
Three rules came out of those reviews and were applied from the start to the later chapters:
- Every number on a page carries a trace. A comment next to it names the output file, column and row it came from, like the ones in this page's source. Chapter 5's
check_prose.pyreads each cited cell, rounds it as printed, and fails on a mismatch or on a number with no trace. - Free-text fields stay out of page data. Brand, store and employer fields can hold a person's name. Pages ship them only through an allowlist or not at all, and a check enforces it.
- Inferences are worded as inferences. "Default" and "cause" are claims about the world, while the trip and product files record transactions and labels, so the pages say "associated with" unless the design supports more.
Run it yourself: python appendix/a-field-notes/pipeline/measure.py after Chapter 7's pipeline. appendix/a-field-notes/pipeline/.