The third MCP server was reasonable. The rest were not
MCP was the right answer for giving an agent a project's documentation. As the count grew, the servers themselves became the thing needing maintenance.
Book III of III The Unreliable Systems Trilogy
Tools, authority, state, bounds and records for agents in production
A practical guide to building AI agents that can be trusted in production: tools, authority, state, bounds and records, from design to incident review.
Page of the Türkçe edition: /tr/kitaplar/engineering-reliable-ai-agents/
No sign-up, no email. License: © 2026 Muhammet Şafak — free to download and read
trusting the model to be right
making its mistakes survivable
Assume the model will sometimes be wrong, and design for that from the first line.
Bound what the agent can do with permissions, checks and hard limits.
Record every decision and action so it can be reviewed, measured and investigated when it goes wrong.
One run called the same lookup 40 times in a row; nobody noticed until a person happened to watch it. The scene is set at Parcelport, a fictional mid-sized fulfillment company, in the week its first agent went live.
By Wednesday the team had learned three things. Besides the lookup loop, one ticket produced a reply that promised a delivery date no tool had returned, and one customer email contained a paragraph addressed to “the assistant”, which the run treated as an instruction from Parcelport. None was a catastrophe, all were predictable, and none could be fully reconstructed, because the only record of what the agent did was its final answer.
The book’s thesis is one sentence: AI agents should be engineered as unreliable decision-makers operating inside reliable control systems. The model proposes and the system decides, so the book starts not with a better prompt but with a question: if the model will sometimes be wrong, what must the surrounding system guarantee so that being wrong is survivable?
It is not a prompt engineering book, nor one about training, a framework or a vendor, and it is not a book of attacks. Every control comes with its cost, and the book says when a control is theater. The numbers in it are illustrations, not recommendations or measurements.
An excerpt from one chapter; the full text is in the downloadable edition.
Now put it in the gate. Chapter 4’s tool-call branch checks the model’s proposal against a choice set and refuses with not_in_choice_set, and the contracts of Chapters 5 and 6 list “the order belongs to the customer of this run” as a precondition. The choice set is an earlier, separate layer: it narrows what the model is offered, it is checked against what the model proposed, and its refusal keeps its own code. I would not implement the ownership sentence twice more, though. The ownership decision has one owner, checkAuthority below, and one code, not_permitted, and the contract’s precondition is satisfied by calling it. A proposal can fail the choice set and never reach this function, and that is fine. What matters is that when an order outside the delegation does reach the gate, the verdict about ownership comes from here, with one observation text and one count in the record. It also runs before preconditions that read more data, because there is no reason to read an order the principal may not see.
function checkAuthority(run, call):
delegation = run.delegation // assigned at run creation
if delegation.expired or delegation.revoked:
return { kind: "refuse", reason: "not_permitted" } // an expired delegation is no authority
authority = intersect(grantsFor(run.agent, call.tool),
delegation.grantsFor(call.tool),
run.taskScope)
if authority is empty:
return { kind: "refuse", reason: "not_permitted" }
for each ref in resourceRefs(call): // order id, shipment id
owner = ownerOf(ref) // read from the owning service
if owner is unknown:
return { kind: "refuse", reason: "upstream_unavailable" } // cannot verify: refuse, retryable
if owner != delegation.on_behalf_of:
return { kind: "refuse", reason: "not_permitted" }
return evaluatePolicies(run, call, authority) // ceiling, window, environment
The block is correct under the failure it is about. The reasons come from the gate’s vocabulary in Chapter 5 (the Appendix lists it), not from a vocabulary of this chapter’s own, and checkAuthority is a partial view of the gate in Chapter 5: it is the permitted step, and an approval outcome it returns is acted on last, after the preconditions (Chapter 6). When the owner lookup fails, the call is refused with upstream_unavailable, which is retryable: an unreachable orders-service must not turn into permission, and it must not turn into a permanent denial either, so the retry runs under the retry policy (Chapter 14) and not at the model’s request. When the delegation has expired because the ticket was closed while the run was suspended, the call is refused with not_permitted. When the model proposes an order that is not the customer’s, the call is refused the same way, without the model ever being asked whether it is sure.
The refusal text matters. The observation returned to the model should say that the order is not available for this ticket, and nothing more. It should not confirm that the order exists, and it should not include any field of it. A refusal that echoes the other customer’s data is a read that happened by another route.
A suspended run may sit in a queue for minutes or hours before Sam approves it. In the meantime the ticket may have been reassigned, the delegation revoked, or the order refunded by someone else. If the orchestrator resumes the run and applies the call on the strength of the earlier verdict, it acts on stale context (F5, runaway loop or stale context). I would re-run checkAuthority and the preconditions when the run resumes, and treat an approval as one input to that second check, never a replacement for it. The approval says a human accepted the exact call. It does not say the world is still as it was.
The key terms used in the book, with short definitions.
8 questions
Backend and platform engineers, SREs, tech leads and the teams that take an agent into production, including people asked to review a design they did not make.
No. The book treats the model as a component you call and works the same way when you replace it. Real products and open protocols appear only as illustrations; the pattern is the point.
No. Prompts appear because they lower the rate of bad proposals, but a prompt is a request, and no property in the book rests on a request alone. Wherever a chapter relies on an instruction, it names the deterministic control that holds when the instruction does not.
You are expected to be a competent software engineer. The book does not explain what a language model is and uses machine-learning vocabulary only where it changes a control decision. You do not need to have used any particular framework, and the book names none as a recommendation.
Yes. The license line reads "© 2026 Muhammet Şafak — free to download and read". PDF and EPUB files are offered in the download panel on this page. This edition is 487 pages.
Seven languages: English, Turkish, Spanish, Simplified Chinese, Portuguese, German and French. Each is offered as a PDF and an EPUB.
It contains pseudocode. All code is language-independent, written in plain text blocks, and diagrams use Mermaid. The book never shows a provider API or an SDK; the model call is always one abstract function, model.propose(context), that returns a proposal.
It is the third of three books in The Unreliable Systems Trilogy: I Access (The Production Database Access Guide), II Events (Designing Reliable Event-Driven Systems) and III Agents (this book). The preface asks for general engineering skill, not for another book, so you can start here if an agent is the problem in front of you.
Blog posts that touch on this book's subject.
MCP was the right answer for giving an agent a project's documentation. As the count grew, the servers themselves became the thing needing maintenance.
RAG or fine-tuning gets answered everywhere. The three questions left after it — the key, the model choice, the budget — get answered nowhere.
Work an agent finishes in days takes a week in a system running for years: there the cost isn't producing code, it's finding and proving the rules.
Not the 'why' but the 'how much': which workflow layers the tool plugs into, the bug patterns it keeps catching, and where it hits its limits.