Dude, where are my tokens?
You asked the AI to change one business rule. The bill says it did a great deal more than that.
The change was small: screen one more kind of payee before the money moves. One rule. The AI took a dozen turns and a surprising number of tokens. Where did they go?
Look at what it had to read. Here is the money-moving end of a bank transfer, written against an engine's SDK. The
engine, MyEngine, is invented for this article; it is no product's API. The lines marked // plumbing are not your
business.
Compensations undo = engine.compensations(); // plumbing
try {
String posting = engine.step("debit", () -> bank.debit(t)); // plumbing
undo.add(() -> engine.step("reverse", () -> bank.reverse(posting))); // plumbing
String sent = engine.step("send", () -> rail.send(posting)); // plumbing
outcome = "sent " + sent;
} catch (Exception e) {
undo.run(); // plumbing
outcome = "refused by the rail - the debit is reversed";
}
Five of the ten lines are plumbing. The AI is paid by the token for every line it reads and every line it writes, and it reads them all again at each turn.
Where they went
| The tokens went to | Why |
|---|---|
| Reading the plumbing | It is in the same file as your rule, so it is read at every turn |
| Writing the plumbing again | A change to the rule moves the steps, the retries and the undo around it |
| Getting it right | Plumbing is the part that takes the most turns |
| Testing it | The largest share. A machine dies between the debit and the send; two answers arrive in the wrong order; a retry lands twice. Each case needs a harness of its own, and nobody can list all the cases |
Your business rule needed a few lines and a few examples. The plumbing needed the rest.
It is not a straight line
Twice the code is more than twice the cost: there is more to read, more turns to get it right, and more to read again at every turn.
So turn it round. Suppose taking the plumbing out makes the code half as large. If the number of turns grows with the size of the code, and every turn reads all of it again, the cost does not fall to a half. It falls to about a quarter. And that is before counting the tests nobody has to write any more.
Getting them back
Keep the plumbing out of the file. Here is the same code with only your business in it:
try {
String posting = debit.apply(t);
String sent = send.apply(posting);
outcome = "sent " + sent;
} catch (Exception e) {
outcome = "refused by the rail - the debit is reversed";
}
The steps, the undo and the recovery after a crash are still needed. But they can be derived from these lines by a compiler, and a compiler is not paid by the token.
| Plumbing in the file | Plumbing derived | |
|---|---|---|
| What the AI reads and writes | Your rule and the plumbing, every turn | Your rule |
| Tests | Harnesses for crashes, orderings and retries | Examples of your rule |
| Who checks it | A seasoned engineer | Anyone who knows the business, by reading it |
| Tokens spent on plumbing | A large share, and the costliest | None |
Dude, your tokens went to the plumbing. Spend them on the business.
Try it
This article is published by Cube Root; deriving the plumbing with a compiler is what we build. The transfer above is one of the sample projects in the browser IDE at cube-root.com: open it, right-click and choose View execution graph. Nothing to install.
The longer argument, with the full transfer, the diagrams and a comparison of engines: The script has flipped: AI writes the logic, a compiler derives the plumbing