Leanpub Header

Skip to main content

Survive Production: The AI Engineering Bundle

LLM features, long-running agents and the MCP tools they call: three practical books on building AI that survives production, with tested Go code for every pattern.

Bought separately

$63.00

$45.00

You pay

Author earns

$

Also available for 2 book credits with a Reader Membership

The following 3 books are included in this bundle...

These books have a total suggested price of $63.00. Get them now for only $45.00!
About

About

About the Bundle

Three books for backend engineers who have been asked to put AI into real products, and keep it running.

Each book treats AI as what it is in production: a dependency that is slow, costs money, sometimes goes down and is sometimes wrong. Each one applies engineering you already know (timeouts, idempotency, state machines, rate limits, audit) to it. Each comes with an open-source Go companion repository where every snippet in the book is tested in CI.

  • Models Make Things Up: single LLM features. Retries and fallbacks, validated structured output, versioned prompts, cost budgets, safe caching, evals, guardrails for actions that move money.
  • Agents Never Sleep: agents that run unattended. Durable runs with a journal and fencing tokens, one side effect per intention, human approval as a state, budgets and kill switches, trajectory evals and tracing.
  • The Tool Layer: the MCP servers and tools agents call. OAuth audience checks, tenant isolation, cost-weighted rate limits, idempotent refunds, versioning, tool poisoning, audit. Includes an example on mcp-go.

Read them in any order. Each book stands alone, and together they cover the whole path: one model call, a long-running agent, and the tools it touches.

What you get: 39 chapters, PDF and EPUB, with an Interview Corner, a production checklist and a TL;DR in every chapter, plus free updates. The bundle costs less than buying the three books separately.

All incidents are composites. Drafted with AI assistance; reviewed, tested and edited by the author.

Books

About the Books

Agents Never Sleep

Agents Never Sleep

Building AI Agents That Survive Production: Durable Runs, Safe Tools, Budgets and Evals in Go

Your agent runs at 3 a.m. with nobody watching. Build it like it knows.

The demo was flawless. Then the agent ran overnight. It looped for six hours on a listing it could never fix. A pod restart made it refund the same order twice. An approval request scrolled out of a chat channel, and the run waited all weekend. Text hidden in a seller's listing told it to send order data somewhere it shouldn't.

None of these are model problems. They are distributed-systems problems with a model in the loop, and backend engineers already know how to solve most of them.

Agents Never Sleep treats an agent as what it is in production: a long-running state machine whose next step is chosen by a model, calling real tools, touching real money and data. Then it applies proven engineering from payment systems and workflow engines to that loop.

What you'll be able to do

  • Survive crashes and deploys. Use an append-only journal, replay on resume, and leases with fencing tokens so a late worker can't write.
  • Make every side effect happen once. Use idempotency keys per intention, a status check after a timeout instead of a blind retry, and an outbox that holds messages until the run succeeds.
  • Keep humans in the loop properly. Treat approval as a state with deadlines, escalation and maker-checker. The agent can't approve its own refund.
  • Stop runaway agents. Set step, cost and time budgets, detect no progress, and add kill switches per tenant, per agent and globally.
  • Limit excessive agency. Give tools least privilege and identity from the session, not the model, and switch off egress once untrusted text is in context.
  • Coordinate many agents. Give each resource one writer, using leases and versioned writes.
  • Give agents memory that doesn't rot. Scope it to tenant and user, let it expire, and make it deletable.
  • Know whether a change made things worse. Run trajectory evals, replay production runs against new code, and trace every run step by step.
  • Pass the interview. Design an agent platform in 45 minutes.

Code you can run today

Every Go snippet in the book comes from the open-source companion repository, github.com/AlwyAbdullah/agents-never-sleep. It has 17 packages, uses only the standard library, and every package is tested in CI. One command, go run ./cmd/night-shift, runs three production stories offline, with no API key.

In that demo a stuck agent is stopped after 4 steps. A kill switch pauses refunds for one tenant. In a refund run, one worker dies mid-run and another resumes from the journal without repeating the approval or the refund.

Read the code for free. Buy the book for the why: the failure stories, the trade-offs, and when each pattern is overkill.

What's inside

  • 14 chapters, 5 appendices, 10 diagrams, 162 pages (PDF + EPUB)
  • An Interview Corner, a production checklist and a TL;DR in every chapter
  • A production-readiness checklist, a tool spec template, and an agent incident runbook template
  • No framework tutorial, no model rankings, no hype. Provider- and framework-agnostic, so it stays useful when the tools change.

Who it's for

Backend engineers and tech leads who build, run or review AI agents, and engineers preparing for "design an agent platform" interviews. If you've built services, queues and state machines, you're ready. No ML background is needed.

Not for you if you want ML theory, prompt collections, or a step-by-step guide to one agent framework.

Part of a series: Models Make Things Up (single LLM features) and The Tool Layer (MCP servers and agent tools). Each book stands alone.

Facts that can change were checked in November 2026. All incidents are composites. Drafted with AI assistance; reviewed, tested and edited by the author.Table of contents

  • Introduction: The Agent Worked. Then It Kept Working.
  • Part I: What an Agent Really Is. 1. The Demo Agent and the 3 a.m. Agent · 2. Workflows First, Agents Second · 3. State Lives Outside the Model
  • Part II: Surviving Failure. 4. Crashes Are Normal: Durable Execution · 5. Every Tool Call Is a Side Effect · 6. Tools Are APIs for a Creative Caller · 7. Humans Are a State, Not an Exception
  • Part III: Control. 8. Budgets, Brakes and Kill Switches · 9. Many Agents, One Source of Truth · 10. Memory That Doesn't Rot · 11. Excessive Agency Is the Real Risk
  • Part IV: Knowing What Happened. 12. Evaluating Trajectories, Not Answers · 13. Observability for Runs · 14. Design an Agent Platform in 45 Minutes
  • Appendices: Glossary · Production Readiness Checklist · Tool Spec Template · Agent Incident Runbook Template · Sources and Further Reading

The Tool Layer

The Tool Layer

Building MCP Servers and Agent Tools That Survive Production: Auth, Tenants, Rate Limits and Idempotency in Go

Every agent is a new client. Build the server side like it.

You published a tool. Now strangers' agents call it thousands of times, with arguments chosen by a model that read your description once and believed every word. One loops all night. One sends the same refund twice. One arrives with a token that was never meant for you. And one read a product listing that told it to do something else.

An MCP server is a public API whose caller is creative, retries a lot, and acts on text it found somewhere. Most MCP material stops at "here is how to register a tool". The Tool Layer starts where real users, real tenants and real money begin.

What you'll be able to do

  • Design tools models call correctly. Use server-owned amounts, closed enums, strict decoding, and errors written for the model's next step.
  • Lock down auth. Apply OAuth 2.1 for tool servers: protected resource metadata, resource indicators, and the audience check that stops tokens meant for other APIs.
  • Isolate tenants. Take the principal from the token, never from arguments, so another tenant's order looks exactly like a missing one.
  • Control load and cost. Set rate limits, quotas and cost attribution per tenant, agent and tool, with expensive tools costing more.
  • Make refunds happen once. Combine idempotency keys with tools that are idempotent by design.
  • Change tools without breaking agents. Version and deprecate tools with sunset dates, even for agents that cached your tool list.
  • Contain tool poisoning. Handle rug pulls, shadowing and injection through results, with containment that holds when detection fails.
  • Answer "which agent did this, for whom?" in minutes, with one audit record per call and W3C trace IDs.
  • Pass the interview. Design a production MCP gateway in 45 minutes.

Code you can run today

Every Go snippet in the book comes from the open-source companion repository, github.com/AlwyAbdullah/the-tool-layer: a small MCP server (revision 2026-07-28, Streamable HTTP), standard library only, with every package tested in CI. Start it with go run ./cmd/kiosk-mcp, then run go run ./cmd/kiosk-client in a second terminal. No API key is needed.

The client walks through the failure cases against the real server: no token, a cross-tenant lookup, an invalid enum, the same refund sent twice, a 429 with Retry-After, and finally "nothing left to refund".

Read the code for free. Buy the book for the why: the incidents behind each check, the trade-offs, and when a check is overkill.

What's inside

  • 11 chapters, 5 appendices, 9 diagrams, 144 pages (PDF + EPUB)
  • An Interview Corner, a production checklist and a TL;DR in every chapter
  • A tool server production checklist, a tool design template, and dated MCP spec notes
  • Patterns first, spec second. MCP changes several times a year; the engineering doesn't. Spec details live in one dated chapter and one appendix.

Who it's for

Backend engineers building MCP servers or exposing their product to agents, tech leads and security reviewers deciding what agents may touch, and engineers preparing for "design a tool platform for agents" interviews.

Not for you if you want an agent-framework tutorial, prompt tricks, or a complete MCP reference.

Part of a series: Agents Never Sleep (running agents in production) and Models Make Things Up (single LLM features). Each book stands alone.

Facts that can change were checked in November 2026. All incidents are composites. Drafted with AI assistance; reviewed, tested and edited by the author.Table of contents

  • Introduction: Every Agent Is a New Client
  • Part I: The Surface. 1. Tools Are Your New Public API · 2. MCP in One Chapter · 3. Designing Tools Models Use Correctly
  • Part II: Who Is Calling. 4. AuthN and AuthZ: OAuth 2.1, Scopes, Per-User Tokens · 5. Multi-Tenant Servers and Data Isolation · 6. Rate Limits, Quotas and Cost Attribution
  • Part III: Calls That Change Things. 7. Idempotency and Side Effects Behind Tools · 8. Versioning and Deprecation Without Breaking Agents
  • Part IV: Defence and Operations. 9. Tool Poisoning, Injection and the Supply Chain · 10. Observability and Incident Response for Tool Servers · 11. A Production MCP Gateway in 45 Minutes
  • Appendices: Glossary · Tool Server Production Checklist · Tool Design Template · MCP Specification Notes (checked Nov 2026) · Sources and Further Reading

Models Make Things Up

Models Make Things Up

Building LLM Features That Survive Production

Your LLM demo worked. Then production happened: a provider outage turned into a minute-long spinner, the model invented a refund policy, a retry loop quadrupled the bill, and a user talked the assistant into a discount code.

Models Make Things Up is for backend engineers who have been asked to "add AI" to a real product. It treats the language model as what it is in production: a slow, billed, sometimes-down, occasionally wrong dependency, and shows the engineering that makes features built on it reliable.

What you will learn

  • Treat model calls like any fallible dependency: latency budgets, deadlines, typed errors
  • Turn model text into validated, typed data, and repair once instead of looping
  • Version prompts like code, with the version on every request
  • Retry the right errors with jitter and Retry-After; add circuit breakers and tested fallbacks
  • Let models trigger actions without double refunds: idempotent tool calls
  • Know the cost of every request, cache safely, and stop runaway spend with budgets
  • Stream, queue or batch depending on who is waiting
  • Build evals that catch regressions before users do
  • Log enough to debug without leaking personal data
  • Measure RAG retrieval separately from answers
  • Contain prompt injection by limiting what the model can do, see and trigger
  • Use AI near money safely: the model is an analyst, not a cashier
  • Put agents on a leash: step, cost and time limits, escalation
  • Roll out with shadow mode, flags and a kill switch, and design an LLM system in 45 minutes

What is inside: 14 chapters, 5 appendices (glossary, production-readiness checklist, LLM API error taxonomy, eval set template, sources), 9 diagrams, and an Interview Corner, Production checklist and TL;DR in every chapter. Every Go snippet comes from a companion repository (standard library only, every package tested). PDF (146 pages) and EPUB.

No model rankings, no hype. Provider-agnostic engineering that stays useful when models change.

Who it is for: backend engineers and tech leads building or reviewing LLM features, and engineers preparing for "design a system with an LLM" interviews.

Who it is not for: people looking for ML theory, fine-tuning, or a prompt-tricks collection.

Facts that can change were checked October 2026. All incidents are composites.Code you can run today

Every Go snippet in the book comes from the open-source companion repository, github.com/AlwyAbdullah/models-make-things-up: 20 packages covering all 14 chapters, standard library only, every package tested in CI. go run ./cmd/kiko runs the whole book in one request flow, offline and with no API key: a provider outage answered by the fallback chain, a cached repeat, a refund that runs once, and a prompt-injection attempt whose made-up discount code is blocked before it reaches the customer.

Read the code for free. Buy the book for the why: the incidents behind each pattern, the trade-offs, and when a pattern is overkill.

Table of contents

  • Introduction: The Demo Worked. Production Didn't.
  • Part I: When the Model Is a Dependency. 1. The Least Reliable Dependency You Have · 2. Contracts for a Probabilistic API · 3. Prompts Are Code
  • Part II: Calls That Survive. 4. Timeouts, Retries and Fallbacks · 5. When the Model Can Do Things · 6. The Bill Is a Feature · 7. Streaming, Queues and Background Work
  • Part III: Knowing It Works. 8. Evals Before Vibes · 9. Observability Without Leaking Secrets · 10. Retrieval Without the Hype
  • Part IV: Safety, Money and Agents. 11. Prompt Injection Is an Architecture Problem · 12. When AI Touches Money · 13. Agents on a Leash · 14. Shipping It, and Designing One in 45 Minutes
  • Appendices: Glossary · Production-Readiness Checklist · LLM API Error Taxonomy · Eval Set Template · Further Reading and Sources

Part of a series: Agents Never Sleep (running agents in production) and The Tool Layer (MCP servers and agent tools). Each book stands alone.

The Leanpub 60 Day 100% Happiness Guarantee

Within 60 days of purchase you can get a 100% refund on any Leanpub purchase, in two clicks.

See full terms...

Earn $8 on a $10 Purchase, and $16 on a $20 Purchase

We pay 80% royalties on purchases of $7.99 or more, and 80% royalties minus a 50 cent flat fee on purchases between $0.99 and $7.98. You earn $8 on a $10 sale, and $16 on a $20 sale. So, if we sell 5000 non-refunded copies of your book for $20, you'll earn $80,000.

(Yes, some authors have already earned much more than that on Leanpub.)

Learn more about writing on Leanpub

Free Updates. DRM Free.

If you buy a Leanpub book, you get free updates for as long as the author updates the book! Many authors use Leanpub to publish their books in-progress, while they are writing them. All readers get free updates, regardless of when they bought the book or how much they paid (including free).

Most Leanpub books are available in PDF (for computers) and EPUB (for phones, tablets and Kindle). The formats that a book includes are shown at the top right corner of this page.

Finally, Leanpub books don't have any DRM copy-protection nonsense, so you can easily read them on any supported device.

Learn more about Leanpub's ebook formats and where to read them

Write and Publish on Leanpub

You can use Leanpub to easily write, publish and sell in-progress and completed ebooks and online courses!

Leanpub is a powerful platform for serious authors, combining a simple, elegant writing and publishing workflow with a store focused on selling in-progress ebooks.

Leanpub is a magical typewriter for authors: just write in plain text, and to publish your ebook, just click a button. (Or, if you are producing your ebook your own way, you can even upload your own PDF and/or EPUB files and then publish with one click!) It really is that easy.

Learn more about writing on Leanpub