The script has flipped: AI writes the logic, a compiler derives the plumbing
Models and agent frameworks change every few weeks. The code that moves money once should not have to change with them.
AI agents have changed what a business application does. A request is no longer one call and one answer. An agent asks a model, waits for tools, waits for a person, and asks again. Every run is a flow of many steps, on machines that fail.
They have also changed how fast the ground moves. Models, agent frameworks and protocols change every few weeks. Code tied closely to this month's tooling is next year's rewrite.
Software as a service grew into a business worth hundreds of billions of dollars a year, and it is everywhere. Much of it is not only used but built on, and a service that is built on comes with an SDK. Through the SDKs it made its way all the way into the business logic. Teams accepted that as the price of not building it themselves. With AI writing the logic, that price has become friction: the part that should change every week is tied to the part that must not.
Here are both parts in one piece of code: 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 marked lines are the platform.
Compensations undo = engine.compensations();
try {
String posting = engine.step("debit", () -> bank.debit(t));
undo.add(() -> engine.step("reverse", () -> bank.reverse(posting)));
String sent = engine.step("send", () -> rail.send(posting));
outcome = "sent " + sent;
} catch (Exception e) {
undo.run();
outcome = "refused by the rail - the debit is reversed";
}
And here is the same code, split in two.
Part 1: the business logic. It stays in your file. It is the part that changes every week, and a person can read 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";
}
Part 2: the plumbing. It moves out of the file. Nobody writes it; a compiler derives it from part 1.
| Derived from part 1 | What it does |
|---|---|
A step for debit |
Recorded as a row when it finishes; a finished step is not run again |
A step for send |
Runs after the debit, because it needs the posting |
| The undo | If the send fails, the debit is undone first, then the catch runs |
| Recovery | After a crash the work goes on from the rows |
Five lines of platform left the business code, and nothing was lost. The rest of this article is about why that split is now necessary, what it saves, and what it takes to make it.
Here is the flip. Writing code used to be the cost. Now an AI writes it in a minute, and the cost is checking what it wrote. Seen that way, there are two kinds of code: one a person can check by looking at it, and one a person cannot.
Two kinds of code
| Layer 1: the business logic | Layer 2: the infrastructure | |
|---|---|---|
| What it is | The rules of the business and the agent's loop: judge the risk, screen the payee, ask a person when in doubt, move the money | Durability, calls that run in parallel safely, the undo when a step fails, knowing where the work was when the machine died |
| What it looks like | Small, rule-based, one step after another | Many machines, listeners, retries and timing; the order of things is not on the page |
| Writing it | Easy with domain knowledge, and an AI helps | Notoriously hard, even with an AI |
| Who can check it | Anyone who knows the business, by reading it | An extremely seasoned engineer, and not by reading alone |
| What should check it | A person | A compiler |
Layer 1 stays free only if it is written with the language's own types: Function<A, B> in Java, Callable in Python, a function type in TypeScript. No SDK. Then it is tied to no model, no agent framework and no engine.
Nobody knows where AI goes next. This split is already clear, though, and it means rethinking development from its first point of contact: the IDE.
The first contact is the IDE
The first decision is made before a line of code is written: what you install.
| What you install | What it ties you to |
|---|---|
| An IDE plugin | One platform's way of writing a flow |
| A command-line tool or a local server | One platform's way of running it |
| An SDK in the build file | One platform's types, in every file that uses them |
The SDK is the one that matters most. The moment it is installed, the code is written against that platform. When platforms change as fast as they do now, the team that installed it is the team that carries the cost of moving.
So the IDE should open in a browser. No plugin, nothing to install, and no SDK. The code is written against the language itself: pure Java, pure Python, pure TypeScript.
What an SDK looks like in the code
Here is the whole bank transfer written against the same invented SDK. MyEngine is no product's API. Real SDKs differ in their names. The shape is familiar.
import com.myengine.sdk.Engine;
import com.myengine.sdk.Workflow;
import com.myengine.sdk.Pending;
import com.myengine.sdk.Compensations;
@Workflow
public class CoreTransferWorkflow {
private final Engine engine = Engine.current();
public String run(Transfer t) {
Pending<RiskVerdict> risk = engine.async(() -> {
Transcript question = engine.step("riskPrompt", () -> prompts.risk(t));
LlmResponse answer = engine.step("riskModel", () -> model.ask(question));
return engine.step("readVerdict", () -> verdicts.read(answer));
});
Pending<ScreeningVerdict> screening = engine.async(() ->
engine.step("sanctions", () -> sanctions.screen(t)));
engine.awaitAll(risk, screening);
String decision = "approved";
if (risk.get().level().equals("high") || screening.get().result().equals("hit")) {
decision = engine.waitForSignal("review");
}
String outcome = "rejected in review";
if (decision.equals("approved")) {
Compensations undo = engine.compensations();
try {
String posting = engine.step("debit", () -> bank.debit(t));
undo.add(() -> engine.step("reverse", () -> bank.reverse(posting)));
String sent = engine.step("send", () -> rail.send(posting));
outcome = "sent " + sent;
} catch (Exception e) {
undo.run();
outcome = "refused by the rail - the debit is reversed";
}
}
return outcome;
}
}
The marked lines name the engine. They are the lines you do not want in your code. And they are only the ties you can see.
| Ties you can see in the code | Ties you cannot |
|---|---|
| The imports | The SDK's version in the build file, kept in step with the server's |
engine.step around every effect |
Rules on what the code between steps may do: the clock, random numbers, threads |
engine.async and engine.awaitAll for parallel calls |
The workers, queues and registrations a flow needs before it starts |
| The undo, added by hand | What a change to the code does to runs already under way |
Where is the infrastructure?
One would expect to open a file and see it: here is the business logic, there is the infrastructure. There is no such file. The infrastructure is in-band: it is part and parcel of the business logic.
This has three costs.
You cannot review the logic on its own. When an AI produces a flow, you want to look at it and say yes or no to the business. You cannot: every change touches both layers, so every review needs someone who knows the engine as well as the business. The logic cannot be upgraded or refined independently.
The plumbing is the hard part to get right. Platform code runs across many machines, with listeners, retries and timing between them. That is where the race conditions live. You can test for the bugs you know. You cannot test every order in which things may happen, so a test can show that a bug is there, and never that none is left.
Checking such code takes an extremely seasoned engineer, and concurrency bugs get past seasoned engineers too. If an AI writes this code again each time the logic changes, it must be checked again each time, by the few people who can. The tokens are spent on the part nobody can validate by reading.
The durable execution engines of today are carefully engineered and widely used, and they make layer 2 dependable. Most of them are libraries, and a library has to be called from the code it serves. That is useful, but it does not keep the two layers apart.
Where the tokens go
There is a third cost, and it is the one that shows up on a bill. An AI is paid by the token: for every line it reads and every line it writes. In a working session it reads the code again at each turn. So the cost grows faster than the code does: twice the code is more than twice the cost, because there is more to read, more turns to get it right, and more to read again at every turn.
The plumbing is where that cost is highest, three times over.
| The cost of | Why the plumbing costs more |
|---|---|
| Writing it | In the transfer above, 20 of the 36 lines name the engine, and they are written again whenever the logic around them changes |
| Getting it right | They are the lines that take the most turns, and then a seasoned engineer |
| Testing it | The largest of the three |
Testing is the largest because the two kinds of code are tested in different ways. Business logic is tested with examples: this transfer is risky, that one is not. A few lines each, and an AI writes them in one pass. Plumbing is tested against what might go wrong: 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. So the tests grow larger than the code they test, they are written in the hope of catching most of it, and every line of them is read and written by the token.
| The two layers mixed | The two layers split | |
|---|---|---|
| What the AI reads and writes | Both layers, every time | The business logic only |
| A change to one rule | The plumbing around it is read again, and often written again | The plumbing is not in the file |
| Getting the plumbing right | Many turns, then a seasoned engineer | No turns: a compiler derives it |
| The tests | Harnesses for crashes, orderings and retries; many lines, never complete | Examples of the business rule; a few lines |
| Tokens spent on plumbing | A large share, and the costliest | None |
A small sum shows the size of it. 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 counts the code only. Add the tests the plumbing needed, which are no longer written at all, and the saving is larger still.
So here is the argument, stated plainly. Infrastructure code that is generated, and entangled with the business code, will soon be an albatross around the neck of every enterprise system that carries it. Each change costs more than the last: more to read, more to test, more to have checked. And it grows with every feature the AI adds.
The cost is removed where it was highest. A compiler is not paid by the token, and a platform is tested once, by the people who build it, not again by every team that uses it.
The glue between them is harder still
There is a third piece of code. It lives at the boundary, where the business logic meets the infrastructure.
| The glue | The question it answers |
|---|---|
| Versions | Which version does a run follow, when the code changed while it was waiting? |
| Contracts | When what a service is sent or answers changes, what happens to its callers? |
| Typed wiring | Does every call reach something of the right type, and every component the right kind of machine? |
| Routing | A canary, a split, a rollback: who gets the new version, and how is it taken back? |
| Conversations | Some end in a second, some wait days for a person. Who keeps them while they wait? |
| Upgrades | What happens to the conversations under way when a new version arrives? |
One might think the glue is the easy part. It is the hardest of the three.
| Why | What it means |
|---|---|
| It has two masters | It must fit the business code as it is today and the platform as it is today. Every publish moves one side; every platform upgrade moves the other. |
| It lives in time | The old version and the new one run at the same moment. A conversation that began last week is still waiting for a person. |
| It fails quietly | A mistake here does not crash. It sends a good message to the wrong version, and shows up days later. |
When the glue is written into the business code, it looks like this. MyEngine again, invented:
int v = engine.version("add-sanctions-check", 1, 2); // runs begun before the change keep the old path
if (v >= 2) {
screening = sanctions.screen(t);
}
String rail = engine.flag("canary-rail-v2") ? "rail-v2" : "rail-v1";
A version check and a canary flag, in the file a person who knows banking is supposed to read. Glue should never be part of the business logic. The further it is pushed to the infrastructure side, the better.
How to solve the glue: eight rules
Take two small changes to what the risk agent answers.
record RiskVerdict(String level) {} // contract 1
record RiskVerdict(String level, String reason) {} // a field added: still contract 1
record RiskVerdict(int score) {} // a field removed, another kind: contract 2
The transfer that calls the agent was built against contract 1. Runs are under way. What should happen?
| What changed | The contract? | What should happen |
|---|---|---|
| A comment | No | Nothing; it is not even a new version |
| A setting | No | The same version; the change is recorded beside it |
| The code inside the risk agent | No | A new version of the same contract; callers are not touched |
The answer gains reason |
No | An added field is compatible: a caller that does not read it is not touched |
| A field a caller reads is removed, or changes its kind | Yes | A new contract. Old callers keep contract 1, through an adapter |
Behind that table are rules. They hold for any platform, whoever builds it.
| Rule | What it means |
|---|---|
| 1. The contract is what a caller can see | What a service is sent and what it answers. A field that is added and that no caller reads does not break it; a field that is removed or changes its kind does. Everything else is not the contract. |
| 2. A version never changes | A change is a new version. The old one stays as it was. |
| 3. The compiler works out the version | From what changed. Nobody types a version number, so nobody types the wrong one. |
| 4. No contract without an endpoint | A contract is published together with an endpoint, even an empty one. If the code behind it is not ready, a message is held until it is, or is answered by an older version through an adapter, or the caller is told before anything is sent. A message is never left with nowhere to go. |
| 5. Wiring is type-checked before anything runs | A call that does not fit is refused when it is built, not found in production. |
| 6. Adapters are upgraded automatically | When a contract moves, the adapter between the old and the new is brought up to date by the platform, not by hand in the business code. |
| 7. A run keeps the version it began on | New runs follow the new routing. A run that is under way finishes on the version of the code it began on. |
| 8. Routing is cleared first, and can be undone | A canary is checked before it takes traffic. Routing changes are recorded, and the newest can be taken back exactly. |
Rule 4 deserves a word. A message that finds nobody listening becomes a dead letter, and dead letters create more problems than they solve: someone has to find them, understand them and send them again. It is better that every route ends somewhere. So a new contract can be published early: until the new code is ready, its messages wait, or are answered by the older version through an adapter. A team that thought it was ready and was not loses nothing, and its callers get time to move.
Not one of these rules needs a line in the business logic. Each can be held by a compiler and a platform, which is why the glue belongs on that side:
| In the business code | On the infrastructure side |
|---|---|
| Version branches, kept until the last old run ends | Rules 2, 3 and 7 |
| A wrongly typed call, found in production | Rules 4 and 5 |
| A hand-written conversion between old and new | Rule 6 |
| A canary flag in the flow | Rule 8 |
| A rollback by redeploying | Rule 8 |
What a person cannot check, a compiler should
Code that cannot be validated by reading it, or by testing it, has to be checked another way: by a compiler, before it runs.
Some compilers do far more of this than others. Rust is the well-known one. Its compiler refuses a data race before the program ever runs: the engineer does not hunt for that bug, because the program that has it does not compile.
The same idea belongs one level up, in the flow. A compiler that reads the business logic can derive the plumbing instead of anyone writing it. It runs two steps together only where it has shown that to be safe, and it refuses a hint that would race, naming the line. The plumbing is then not written again by an AI at each change. It is derived, the same way every time.
The same transfer, one layer only
This is what the business logic should look like. Plain Java; it imports nothing but the JDK.
import java.util.function.Function;
public class CoreTransfer {
private Function<Transfer, Transcript> riskPrompt; // the AI agent's question
private Function<Transcript, LlmResponse> riskModel; // the model that answers
private Function<LlmResponse, RiskVerdict> readVerdict; // its answer, read as a verdict
private Function<Transfer, ScreeningVerdict> sanctions; // the bank's screening service
private Function<Transfer, String> review; // a person, minutes or hours later
private Function<Transfer, String> debit;
private Function<String, String> send;
public String invoke(Transfer t) {
Transcript question = riskPrompt.apply(t);
LlmResponse answer = riskModel.apply(question);
RiskVerdict risk = readVerdict.apply(answer);
ScreeningVerdict screening = sanctions.apply(t);
String decision = "approved";
if (risk.level().equals("high") || screening.result().equals("hit")) {
decision = review.apply(t);
}
String outcome = "rejected in review";
if (decision.equals("approved")) {
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";
}
}
return outcome;
}
}
| In the code | What a compiler can derive |
|---|---|
riskPrompt, riskModel, readVerdict |
Three steps, one after the other: each needs the answer before it |
sanctions.apply(t) |
A step that runs beside the agent's three: it needs only the transfer |
if (risk ... || screening ...) |
Waits for both answers, then decides |
review.apply(t) |
The flow waits for a person, for minutes or for days; no thread waits with it |
try { debit ... send ... } |
Two steps, in order |
catch (Exception e) |
If the rail refuses, the debit is undone first, then the catch runs |
Nobody wrote "run these two together". Nobody wrote the undo. An AI can write this file, and a person who knows banking can read all of it.
The separation
A compiler reads the plain code, checks it once, and produces two things. They should go to two different places.
| The worker | The infrastructure | |
|---|---|---|
| What is in it | The steps of your business logic: its calls to your systems and its blocks of code, prepared by the compiler to run one after another, or together where the compiler has shown that to be safe | The execution graph (the order, the branches, the loops), the parallel routing, the undo, and the state, all kept by the platform |
| Who wrote it | You, or your AI | Nobody: it is derived |
| Where it runs | Separately from the platform: on your own machines or on a public cloud. Both should be offered | On the platform |
| The glue | None of it | All of it: versions, typed wiring, routing |
| What changes it | A change to the business | The next compile |
Who calls whom
The two halves talk to each other, and the direction matters. The platform should never call the worker. The worker holds the business logic. Wherever it runs, privately or publicly, no outside system should be calling into it. So every conversation is started by the worker.
| Step | What happens |
|---|---|
| 1. Start | The worker is started, wherever you chose to run it |
| 2. Handshake | The worker opens the connection and says who it is |
| 3. Ask | The worker asks for work |
| 4. Work | It runs the step: your code, where you chose to run it |
| 5. Done | It reports the step done |
| 6. Ask again | It asks for more |
Why this is the safer way round:
- No door is opened into the place the worker runs
- The platform holds no address of the worker and no way in
- Stop the worker, and no call reaches your systems
- More work to do? Start more workers; each one asks for its own
Pulling work is not a new idea, and careful engines do it too. What is different is what sits on each side of the line: only your logic on yours, all of the plumbing on the other.
What you expect out of the box
While all of this goes on, you expect a good deal more, and none of it has anything to do with the business.
| You expect | Meaning |
|---|---|
| Scale | More machines, and close to that much more work done |
| Machines that fail | The work goes on when a few servers are down |
| Observability | What ran, where and how long, with nothing to add |
| Agent tools | A tool call that is a simple service call |
| Limits on tools | A say over what each tool may reach and expose |
| A review | A way to look at a change before it goes live |
Not one of these is a business rule. So not one of them should cost a line in the business logic.
What changes, and what you touch
| What changes | What you touch |
|---|---|
| A new model | Nothing in the code: the model is chosen when the flow is deployed |
| A new agent pattern | The loop, a few lines of ordinary code |
| A new business rule | The logic; an AI writes it, you read it |
| The plumbing | Nothing: it is derived again at the next compile |
The tokens go to the part a person can check. The part that must be right every time is not generated at all; it is derived.
Who can do this, and who cannot
Every engine below is carefully engineered and useful in the form it offers. Most chose a library over a compiler, which is a fair choice: there is no new toolchain to trust. The questions are the ones this article raised.
| Question | Cube Root | Temporal | AWS Step Functions | Google Cloud Workflows | AWS Lambda durable functions | Azure Durable Functions | Inngest | Restate | DBOS | Vercel Workflow | LittleHorse |
|---|---|---|---|---|---|---|---|---|---|---|---|
| Infrastructure generated by a compiler | ✓ | ✗ | ✗ | ✗ | ✗ | ✗ | ✗ | ✗ | ✗ | ✓ | partly |
| The graph, derived from plain code | ✓ | ✗ | — | — | ✗ | ✗ | ✗ | ✗ | ✗ | partly | ✗ |
| Parallel calls checked for races before they run | ✓ | ✗ | partly | partly | ✗ | ✗ | ✗ | ✗ | ✗ | ✗ | ✗ |
| Recovery without replaying your code | ✓ | ✗ | ✓ | partly | ✗ | ✗ | ✗ | ✗ | ✗ | ✗ | ✓ |
| Wiring type-checked before anything runs | ✓ | ✗ | ✗ | ✗ | ✗ | ✗ | ✗ | ✗ | ✗ | ✗ | partly |
| Version worked out by the compiler | ✓ | ✗ | partly | partly | ✗ | ✗ | ✗ | ✗ | ✗ | partly | ✓ |
| A safe canary, cleared by the compiler | ✓ | ✗ | partly | ✗ | ✗ | ✗ | ✗ | ✗ | ✗ | ✗ | ✗ |
Where we stand
This article is published by Cube Root, and the first column is ours. We built a compiler because of the argument above: it turns plain Java, TypeScript and Python into a graph of durable steps kept in PostgreSQL, and the IDE is a browser tab.
Our own limit, stated plainly: the compiler checks the code it can see. What a third-party library does inside, it takes at your word.
Use AI where its work can be checked. Use a compiler where the work must be proved.
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 short version of the token argument: Dude, where are my tokens?