Skip to content
The AI Agent Factory

33.1 The ideas first

Approved by
Panaversity ·
10 min read

In everyday life. A good bookkeeper writes each entry in the ledger the moment it happens, not at the end of the day. If the power goes off at three o'clock, everything up to three o'clock is in the book. And when the bookkeeper pays a bill, the cheque number goes in the book first, so nobody writes a second cheque for the same bill.

What you will learn. Four ideas that every durable worker depends on, whatever product it runs on: the loop, the checkpoint, the safe replay and the wait.

Why it matters. Claude Code will write the code. You decide whether the code is correct. You can only do that if you know what correct means.

The loop

An AI worker runs a loop. The model reads the conversation and decides what to do. If it asks for a tool, the harness runs the tool and adds the result to the conversation. Then the model reads again. The loop ends when the model gives a final answer, or when a limit is reached, such as a number of turns or a budget.

The harness is the software that runs this loop. It sends the conversation to the model, calls the tools, keeps the state and enforces the limits. The model does not run anything itself. It only asks.

The checkpoint

A loop that lives only in memory is lost when the process dies. A durable harness saves the run's state after every step, before it starts the next one. A step is one model turn or one tool call. The saved state is a checkpoint.

After a crash, the harness loads the last checkpoint and carries on from there. Work that was finished is not done again. Work that was not finished is done again.

That last sentence is the whole problem. A step can finish outside the worker and still not be finished inside it. The tool tells the ledger to post an invoice. The ledger posts it. Then the process dies, before the harness has saved the result. After the restart, the checkpoint says that the tool has not finished. So the harness runs it again.

In Pi Durable, only a tool call marked replay: "safe" is run again. A tool call that is not marked safe is not run again: the model is told the call was interrupted, and decides what to do.

The safe replay

A step that can run again after a crash must have the same effect the second time as the first. Such a step is replay-safe.

Some steps are safe by nature. Reading an invoice changes nothing, so reading it twice is harmless. Asking the model again costs a few tokens, but changes nothing outside.

A step with a side effect is safe only if the outside system can tell that the second call is the same as the first. The usual way is an idempotency key: a unique label sent with the action. The ledger keeps the keys it has seen. If it sees the same key again, it does nothing and answers "already posted".

But the key must be the same on the second run. If the tool makes a new random key each time it runs, the ledger sees two different keys and posts twice. So the tool must save the key before it makes the outside call. After a crash, it finds the saved key and sends the same one.

Save the key, then act. Never act, then save.

Two lanes of five steps. Top lane, act then save, ends with the supplier paid twice: the tool makes a new random key, k1; the ledger posts the invoice with k1; the worker crashes before the result is saved; the replay makes a new key, k2; the ledger sees a new key and posts again. Bottom lane, save the key then act, ends with the supplier paid once: the tool saves key k1 with api.memo(); the ledger posts with k1; the same crash; the replay finds the saved key k1; the ledger knows k1 and answers "already posted".

Figure 33.1. The same crash, at the same moment. Only the order of saving and acting differs.

The wait

Some steps cannot finish now. An approval waits for a person. A reminder waits for a date. A report waits for another worker.

A worker can wait in two ways. It can stay awake and check again and again. That is simple, but it pays for every minute of waiting, and a crash during the wait loses the place. Or it can park: save the run, record what it is waiting for, and stop. When the answer arrives, or the deadline passes, the harness wakes the worker, loads the run and gives the answer to the step that asked for it.

A parked worker costs almost nothing while it waits, and survives any restart during the wait, because there is nothing running to lose.

What the three foundations do for you

Claude Managed AgentsOpenAI Agents SDKPi Durable
Runs the loopYes, on Anthropic's serversYes, in your processYes, in your Durable Object
Saves a checkpoint after every stepAnthropic keeps the sessionNo, only at a pauseYes
Makes a side effect safe to replayYour tool's jobYour jobYour tool's job, with saved keys built in
Waits for a personTool approval in the sessionRunState saved at the pauseA parked tool, object asleep

Checked on 29 November 2026. On every foundation, the idempotency key is your job. A harness can save the key for you. Only you can decide that a tool needs one.

The invariant. Every step a worker takes is saved before the next one starts, and every step with side effects is safe to run twice.

Check yourself. A tool sends an email to a supplier, then the process dies before the result is saved. The tool has no idempotency key. What happens after the restart? (The harness runs the tool again from the last checkpoint, and the supplier gets the email twice.)

  • Building Affordable, Self-Improving AI Workers (Panaversity, 29 November 2026), section 4.1
Owner
Panaversity