Take the model out of the monthly comparison
Turn the comparison you asked the agent for every month into a tested function and a pipeline step that runs without the model.
2 parts · 2 and 14 min · part 2 on a computer
Free course. Your Maestro, an AI, .
On the previous page, you sorted the seven tasks in agent_routine.md by who should do each one. Step 3, comparing each region's total with last month's and listing any region that moved more than 20%, belongs to a deterministic tool. Arithmetic over the prior month's and this month's totals has one right answer once the rule is fixed.
Until now, the analyst handed that step to the agent by pasting agent_prompt.md into a chat every month: compare reports/history.csv, list every region whose Glossary word moved more than 20% up or down rounded to one decimal, and say if a region has no total last month. That Glossary word reads as if the rule is already decided, yet it leaves three gaps that a model can settle one way in September and another way in October:
- The 20% boundary: Does "moved more than 20%" include a region that moved by exactly 20% (such as from 100 to 120), or only changes strictly above 20%?
- A missing or zero baseline: When a new region appears (or had a total of 0 last month), dividing by last month's total fails. What exact values should replace the number so the next step can read the result?
- Rounding and order of operations: Does the change get compared against the 20% threshold before rounding to one decimal or after, and how is the rounded value stored (such as
37.1for West's move from 350.00 to 480.00)?
Turning a repeated agent request into code that runs without the model takes three moves. If you want to talk through how the prompt's wording maps to each condition in Python, ask your Maestro.
Settle what the prompt left vague
Write the rule as code in
compare.pyso every edge has one answer: a move counts only whenabs(change) > thresholdon the unrounded ratio, a region missing or at0last month gets"change": Noneand"note": "no total last month", and flagged moves storeround(change * 100, 1)sorted by region.Pin the rule with known-answer tests
Before you trust the code, check it in
test_compare.pyagainst cases you can work out by hand: the closed September and October totals, a region that moved by exactly 20% (from 100 to 120), and a new region with no row in the prior month.Run it as a pipeline step that stops on failure
Call the tests at the top of
run_month.pybefore openingreports/flags.csv. If a test fails, the script exits with status1and writes nothing; only when all tests pass does it write the flags for the next step.
Common mistake: Asking the agent to write the script is only half the move
You can ask an agent to draft compare.py for you, and in your own work you often will. Promotion happens when you read the rule it wrote and pin its choices with known-answer tests. Accepting an agent-written script without tests only moves the guesswork from the monthly chat into a file nobody checked.
A good place to stop. Up next: What stays with the agent, and how to use this on your own report · 14 min · on a computer
Try it
Open the workbench below and look at how the files fit together before you edit anything. reports/history.csv holds the closed totals from modules 3 and 4: between September (2026-09) and October (2026-10), East moved from 650.00 to 710.00 (+9.2%), North from 1200.00 to 800.00 (-33.3%), South from 800.00 to 810.00 (+1.3%), and West from 350.00 to 480.00 (+37.1%). Only North and West moved past the 20% threshold.
In test_compare.py, each Glossary word checks one part of the rule: test_september_to_october checks those four regions, test_exactly_twenty_percent_is_not_flagged checks the 20% Glossary word where North moves from 100 to 120, and test_new_region_is_flagged checks a Central region that appears in October with no September row.
Run uv run run_month.py once before changing compare.py. Because flag_moves starts as a stub that returns [], you will see test_september_to_october and test_new_region_is_flagged print FAIL, while test_exactly_twenty_percent_is_not_flagged prints PASS (since an empty list happens to match expecting no flags). run_month.py then stops and prints that no flags were written.
Now complete flag_moves in compare.py:
- Build two dictionaries mapping
regiontofloat(r["total"]): one for rows wherer["month"] == previousand one for rows wherer["month"] == month. - Loop through
sorted(now)so regions come back in alphabetical order. - If a region is missing from last month's dictionary or had a total of
0, append{"region": region, "change": None, "note": "no total last month"}and continue to the next region. - Otherwise compute
change = (now[region] - before[region]) / before[region]. Whenabs(change) > threshold, append{"region": region, "change": round(change * 100, 1), "note": "moved more than 20%"}.
Run uv run run_month.py again. You are done when all three tests print PASS, the terminal prints North: -33.3% (moved more than 20%) and West: 37.1% (moved more than 20%), and the Glossary word writes reports/flags.csv. If a test still fails after you edit compare.py, share the failure line with your Maestro.
What stays with the agent, and how to use this on your own report
Taking the model out of step 3 does not remove the agent from the monthly routine. Instead, it gives each part of the routine the job it fits:
- The tool (
run_month.py) runs the tests, computes the regional changes fromreports/history.csv, and writesreports/flags.csvthe same way every month without opening a chat. - The agent (step 4) reads
reports/flags.csvand drafts the two sentences for finance explaining North's -33.3% drop and West's 37.1% rise, without doing any of the arithmetic itself. - You (step 7) read those two sentences against
reports/flags.csvand decide whether this month's report goes to finance.
Whenever you notice yourself pasting the same comparison, filter, or check into an agent chat every week or every month, apply these same three moves: write down the rule and settle the edge cases your wording left open, pin those choices with two or three known-answer tests, and wrap them in a script that exits before writing output if a test fails. Here in the sandbox, the monthly scheduler is simulated by running uv run run_month.py yourself; on your own machine, a real scheduler runs that exact command alongside the file-arrival, environment, and alert checks you listed at the end of module 4.