Agents are long-running processes. Build them like it.
A lot of AI agents are still built like API calls. Send a request, get a response, done.
That works for a demo. It stops working the moment an agent does real work: it keeps a workspace, builds up context, calls tools, waits for a human to approve something. Some runs take a few minutes. Others stay open across several days. The agent is no longer a request. It is a long-running process, and long-running processes have a well-known list of problems.
The boring problems show up first
The first is waiting. Agents spend a surprising amount of their life idle: for a person to answer, for a build, for a rate limit, for another system. If the agent holds a process open while it waits, you pay for compute that does nothing, and that cost adds up quickly once you have many sessions open at once.
The second is crashes. A worker gets restarted during a deploy, or runs out of memory, or the node just disappears. If the agent’s state lives in that process, the working directory and the conversation history go with it. You can retry from the start, but by then the agent may have made expensive calls, edited files, or sent something to an external system. Starting over is not free, and sometimes it is not safe.
The third is one-size-fits-all infrastructure. Steps in an agent flow need very different things: a sliver of CPU for glue work, a GPU for one heavy step, a sandbox for generated code, nothing at all while it waits on a person. In one long process, you size everything for the hungriest step.
Keep the agent’s state outside the machine
The idea that helped me most is simple: treat the agent as a durable workflow, and keep its state somewhere other than the worker that is currently running it.
Every step it takes is recorded. When a worker dies mid-turn, another one picks up the history, replays it, and continues from the exact point where the first stopped. Completed steps are not run again. The expensive tool call that already happened stays happened.
Something has to own that history. I think of the workflow engine as an observer and orchestrator: it watches every step, decides what runs next and where, and is the one place that remembers, while workers just do the work. That is the kind of generic engine, with all the primitives built in, that I’m building at Elastic today, and built before at Anecdotes. Both ran for enterprise customers.
Waiting becomes cheap too. A workflow that is blocked on input does not need a live process. It can be parked until a signal arrives, whether that is a message, an approval or a timer, and then it wakes up with its full state. A short pause and a long one cost about the same.
Once state is recorded outside the worker, each step can also run on the machine built for it. That deserves its own post.
Here is a rough sketch of a workflow engine’s step loop:
async function runWorkflow(runId: string, engine: Engine) {
const history = await engine.loadHistory(runId);
for (const step of engine.plan(history)) {
if (history.has(step.id)) continue; // already done, skip it
const output = await engine.dispatch(step, history.inputsFor(step));
await history.append(step.id, output); // persisted before moving on
}
}
The details are not the point. What matters is that the loop can be started from scratch on any machine, read the history, skip what is finished, and carry on.
Execution history makes the rest easy
Once the history of steps is explicit, a lot of things that felt hard become ordinary. Debugging a bad run means reading what each step received and returned, not guessing. An audit trail comes for free. Resuming on another worker is just loading the same history somewhere else.
None of this is specific to one kind of agent or one kind of runtime. It applies to a coding agent in a sandbox, a support agent waiting on a customer, or a back-office flow that needs a manager’s sign-off. If it runs longer than a single request, it has the same problems.
What to watch out for
Durability is not free of tradeoffs. Replay only works if your steps are deterministic or if their results are recorded, so anything that touches the outside world needs to be treated as a recorded step, not something you can casually re-execute. Side effects need idempotency keys. And long histories need compaction.
These are solvable, and they are the same problems distributed systems engineers have been solving for years. That is really my point.
Smarter prompts and better models matter. But once agents run for days, most of the work is not prompting. It is state, failure and coordination.