Skip to content
The AI Agent Factory

Chapter 14. Structuring Programs in the AI Era: Objects, Data and Async

Approved by
Panaversity ·
5 min read

The point

What does a program an agent builds for you decide without you? What it lets in. Is a credit, an amount below zero, a mistake? Does one bad invoice hold up every payment? Who is told? How long does it wait for a slow answer? A program settles these at its edges, the places where data comes in from outside. These are places in the program, not the edge cases of 13.10. Today's agents often write a check at each edge without being asked. If you know what a check can do, you set its rules. If not, the agent sets them, from the first day's data.

Where do I set those rules? Mostly before any code exists, in your brief, as in Chapter 13. Say where each kind of data comes from and what a bad record must do. Your "Done when" can name the cases the first week's data will not have: "Done when a credit lowers that vendor's payment, and a bad amount stops the run with a list of every bad invoice."

What does an edge not catch? A wrong value in the right shape. 48250, where 482500 was meant, is still a whole number of cents, so it passes (14.4). Your count and total (12.1) and your tests (13.9) still matter.

After this chapter you can plan a program of several files with a coding agent, in TypeScript or Python. You can say where its data comes in, what each edge refuses, and what a bad record does. You can plan a call to another company's service: what to send, how long to wait, and when to try again. And you can find your way around a project an agent split into files. Use the tabs to pick one language, and follow it through the lessons. The lab uses both.

Why it matters

Marcus runs accounts payable for a restaurant-supply distributor in Fort Wayne, Indiana. Every Thursday a script downloads about 2,000 approved invoices from a vendor portal and builds the payment file for the bank: 40 vendors, about $6 million in all. An agent wrote the script in an afternoon and, without being asked, added a check at the edge: each amount must be a whole number of cents, such as 482500 for $4,825.00, and more than zero. The script ran without trouble for months.

One Thursday a poultry supplier sent a credit for $450.00, money it owed back for a short delivery. The portal listed it among the week's invoices, as an amount of -45000. The check refused it and stopped the run: "amount -45000 is not a positive whole number of cents". No payment file was written. About $6 million waited on a $450.00 credit, while Marcus worked out what the program should do with it.

The agent had chosen "more than zero" from the first week's data, which held no credits. Marcus knew that a credit lowers what his company owes that vendor. One sentence in his brief would have said so, and his "Done when" could have tested it. So how do you decide what a program lets in, before it runs without you?

Owner
Panaversity