Skip to content
The AI Agent Factory

Chapter 13. Programming Fundamentals in the AI Era: TypeScript and Python

Approved by
Panaversity ·
6 min read

The point

If the agent writes all the code, why learn to read it? Because you answer for what the code does. Code that runs and matches your check can still be wrong, as Renee's script below was. Reading it is how you find out.

What is left for me to do? Decide what the code must do, and show that it does it. Before the agent starts, you list the cases, such as an invoice dated January 31 on Net 30 terms, and the answer each must give, like an answer key. The agent turns your list into tests, and writes code until they pass.

When can I trust the agent's code? When a run or a test gives the answers you expected, not when the agent says it works. Your check is enough for code that runs once, if a mistake would cost little. For code that handles money, or runs again next week, also read the lines that decide the result.

The rule for every number. In this book, every calculation, such as a due date, a total or a weekend rule, is done by tested code that gives the same answer every time. An AI worker never does the arithmetic in its reply (13.5).

After this chapter you can read a short TypeScript or Python program that a coding agent wrote, and say what it will do before you run it. With the agent, you can run it and its tests, read the error it prints when it breaks, and change it.

TypeScript comes first in each concept, because Brightline's scripts are written in it. Python comes next, because much of the code you will meet later, in data work and evaluation, is Python. Readers who want only Python can follow the Python blocks and skip the TypeScript ones.

Why it matters

Renee manages the office of a building-supply company in Toledo, Ohio. On Monday she asks a coding agent for a script that lists the invoices past due, largest first. She wants to call the biggest vendors before lunch. The script runs on the first try. Its output looks neat, and the top line is a $618.75 invoice from a cleaning supplier. Renee calls them, apologizes, and calls the next one on the page.

The largest invoice, $12,900.00 from a freight company, is near the bottom. The export gives each amount in whole cents, so $12,900.00 is 1290000. The script read the amounts from the export as text, and it sorted them as text. As text, "1290000" comes before "61875", because the first character "1" comes before "6". In the same way, "apple" comes before "banana". So a largest-first sort of the text put "61875" on top. Nobody at Renee's company read the script, and nobody compared the order with the export. On Thursday the freight company stops working with them until it is paid, so Friday's deliveries do not come.

The agent did not fail at writing. It wrote a program that ran. Now suppose Renee had written a check first: from the export, how many invoices are past due, and their total. The output would have matched it. Every invoice was there, and the total was right. Only the order was wrong, and a count and a total cannot see order. So when the check matches and the tests pass, what can reading the code still catch?

Owner
Panaversity