· Abhishek Srivastava

Agents inside guardrails: write the workflow before the agent

From Architecting for AI: an agent is a loop, and a loop is not a system. Why durable workflows, tool boundaries and human checkpoints come before the agent.

  • Architecting for AI
  • Generative AI
  • AI Agents

The demo takes four minutes. In the composite story that opens Chapter 8 of Architecting for AI, Archie’s team gives a research agent a borrower’s name. It pulls the public filings, searches the news, reads the firm’s own documents and writes a credit research note with citations. The analysts watching have each spent a day a week on that note. The sponsor approves it on the spot.

In its second week in production, the same agent runs for forty minutes on one borrower. A news source has started rate-limiting requests, and the agent reads each refusal as a reason to try again with a slightly different query. It makes something like three hundred calls before anyone notices. Then its container is recycled, and the second attempt starts from nothing. The note is fine in the end. The bill is not.

The agent was clever enough. What it lacked was everything around it: no record of what it had done, no limit on how long it could try, no way to resume and no boundary on what it could call. Each of those is a solved problem in ordinary distributed systems. The team applied none of them, because the thing was called an agent and agents were new. The chapter is about putting that boring machinery back. This article is the short version.

The myth: agents will run the business

The belief has the best demos in the industry behind it. But demos run once, on a good day, on the happy path, with a person watching. Production runs a thousand times, on bad days, on every path, with nobody watching. Then the questions that did not matter in the demo are the only ones that matter. Does it stop? Does it resume? What did it do before it failed? What can it touch? Who said yes?

This is not scepticism about agents. Workflows like the one in the opening story do run in production, and the people who use them would not give them back. But what works is not what was demoed. It is a workflow, with a model inside it, inside guardrails.

A loop is not a system

Under the vocabulary, an agent is a loop: observe, decide, act, repeat until the goal is met or the loop gives up. The model decides; the tools are what it can do. The pattern has four properties that make it dangerous in production.

  • The control path is non-deterministic. The same request can take five steps or fifty. Termination, bounded cost and repeatability have to be added from outside.
  • It runs long and fails partway. Anything that runs for minutes will be interrupted, and an agent that keeps its progress in memory loses it.
  • It has side effects. An agent that only reads is a search engine with a plan. Once it can write, send or pay, the question stops being whether the answer was right and becomes whether the action was safe.
  • Cost compounds. Every step is a model call carrying the whole context so far.

Use the pattern less often than the demos suggest. A loop earns its place when the path through the work depends on what is found along the way, as in research, investigation or triage. When the path does not vary, build a pipeline with a model in a fixed place. The test is to ask the team to draw the steps. If the drawing has a diamond that says “depends what it finds”, that diamond is where the agent goes, and the rest is still a pipeline.

The model decides within a step; the workflow decides between steps

That sentence is the architecture. The steps, their order, their limits, what happens on failure and where a person signs are written down in advance and run by an engine that does nothing clever. Inside a step, the model can read, reason, pick a tool from a short list and draft. When the step ends, the workflow takes over. The model’s freedom stays inside a box whose edges somebody drew.

Durable orchestration

The engine has to be durable. Every step’s inputs and outputs are persisted as they happen, so a run that dies at step seven resumes at step seven with the earlier steps intact. The agent’s progress lives in a durable store, not in a process’s memory.

Retries, timeouts and budgets then belong to the engine, not the loop. Each step declares how often it may retry and with what backoff, which means every tool call has to be idempotent or wrapped so that it is. Had the news step retried three times with backoff and then failed, the workflow would have handled the failure the way a person decided in advance. Limits on steps, model calls and spend per run sit outside the model’s reach: the loop cannot talk its way past a budget it cannot see.

State lives in the engine, and each step’s context is assembled from it by code, not taken from a transcript that grows with every step. That growing transcript is where an agent forgets an instruction given forty steps back.

The tool boundary

Which tools a step can call is the most important design decision in the chapter. Every tool has a typed contract. Every workflow has an allowlist enforced by wiring, not by the prompt: the prompt may say “only use these tools”, but the real control is that the others are not connected. Tools are read-only by default. Anything that writes to a system of record, sends a message, moves money or changes a permission gets a named entry in the architecture decision record, the narrowest scope that works, and a checkpoint in front of it.

The chapter’s second story shows why. Archie’s team gave an early version of the workflow a connection that could read the borrower’s record and could also write. For a week it read. Then it spotted a stale address that disagreed with a filing, decided correcting it would be helpful, and updated the system of record from a document that was itself out of date. Nobody had asked it to, and nobody had told it not to. Archie’s fix was a read-only credential and a rule: “An agent gets the keys its design names, one at a time, and a write key only behind a step where a person says yes.”

The person in the loop is a step

A checkpoint is a step in the workflow, not an email. The run reaches it, saves its state and waits, for an hour or a week. The reviewer sees the proposed action with its exact values and the evidence behind it, then approves, amends or rejects, and the decision is recorded with their name. In Archie’s workflow, the agent gathers and drafts, the analyst corrects and signs, and only then is the note filed. The analyst’s day a week became an hour.

Checkpoints are also how autonomy is earned. When reviewers have approved one kind of action unchanged for long enough to show the rate, the business owner can decide to let that kind through. Autonomy comes one action type at a time, with evidence, not in a demo.

Failure, traces and evaluation

Every step has a written answer for failure: retry up to a limit, fall back to a simpler step, compensate, escalate to a queue a person works, or stop cleanly with partial results saved. The opening story’s agent had one failure behaviour, which was to try again, forever.

Every run leaves a trace of its steps, model calls, tool calls, decisions and cost. An agent without a trace cannot be audited. And the golden set from Evaluation is the new testing gains trajectories as well as answers: did the run call only allowed tools, stay within budget, stop at the checkpoint? Those runs use sandboxed tools, so a wrong action in evaluation costs nothing.

Multi-agent systems, briefly

Most multi-agent systems are one workflow nobody wrote down. The planner is the workflow definition, the specialists are steps, the critic is an evaluation step. Written as a workflow, that is testable. Written as agents negotiating in natural language, it is not. Start with one workflow, and split it when you can say why.

What to do differently

The chapter closes with Archie’s own mistake, which was about order. His team spent a month choosing an agent framework and a week on orchestration, because the framework had a “memory” feature that seemed to cover it. It did not, and the framework was replaced within a year anyway. The workflow engine eventually put underneath has not changed since.

Archie would reverse the month and the week. Choose the durable engine first, write the workflow, draw the tool boundary and the checkpoints, and then use whatever agent loop is current this quarter inside the steps. In his words: “The clever part is the part that changes. The boring part is the part that holds.”

For the wider argument, read Architecting for AI: what changes, and what still holds. The full chapter, with its practices for Monday morning and an architect’s checklist for agentic workflows, is in the book.