How to Build a Reliable System Around an Unreliable AI Agent
The model will be wrong sometimes. Architecture decides whether that costs a retry or a customer: schemas, validators, state machines, idempotent actions.
Contents
Where do you put the deterministic parts so a bad generation cannot hurt you?
Should the model decide the control flow, or should your code?
How do you stop the model returning something you cannot parse?
What should a validator do when the output is wrong?
The pattern: a deterministic state machine with model-filled slots
How do you stop a retry from sending the same email twice?
When do you retry, and when do you stop and ask a human?
| Failure | Action | Why |
|---|---|---|
| Invalid schema or failed validator | Retry, maximum two, feed the error text back | Usually correctable in one shot |
| Rate limit, 5xx, timeout | Retry with exponential backoff and jitter | Transient, nothing to do with the output |
| Valid shape, fails a business rule twice | Escalate to a human | The model does not hold the missing information |
| Ambiguous or low-confidence input | Escalate before acting | Waiting costs less than being wrong |
| Irreversible action: payment, delete, outbound send | Gate every time | No retry undoes it |
Where does the human approval gate go?
The boundary: what belongs to your code, and what belongs to the model
| Concern | Owner |
|---|---|
| Which step runs next | Your code |
| What counts as valid | Your code |
| Credentials, permissions, database access | Your code |
| Money, deletions, outbound messages | Your code, behind an idempotency key |
| Retry counts, timeouts and spend limits | Your code |
| Reading messy human input | The model |
| Classifying, extracting, summarising | The model |
| Drafting language a human will approve | The model |
| Choosing between options you enumerated | The model, given the list |
Frequently asked questions
Contain the agent before you scale it
buildAcademy teaches builders where to draw the boundary between deterministic code and the model, the same architecture we apply in every buildDay build.
See buildAcademyRelated Guides
Human Approval Before an Automated Send: The Legal and Engineering Case
Why anything your automation sends a customer needs a human checkpoint in Australia, the three approval patterns, and how to stop one becoming a rubber stamp.
AI Evals: How to Know Your Output Is Actually Right
A demo proves an AI feature can work. Evals tell you how often it does: what to measure, how many cases to start with, and where LLM judges quietly lie.
Multi-Agent Orchestration: What Works and What Just Multiplies Your Problems
Anthropic measured a 90.2% gain from multi-agent research. Stanford measured coding success halving with two agents. Both are right, and here is why.