Skip to content

About

Building Reliable AI Assisted Software, published by Packt

Resources

Stars

1 star

Watchers

0 watching

Forks

Latest commit

 

History

11 Commits

Folders and files

NameName
Last commit message
Last commit date
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Building Reliable AI-Assisted Software Systems

Design, test, and govern production-grade AI software by wrapping probabilistic models inside a deterministic engineering shell

From the author of 30 Agents Every AI Engineer Must Build and 50 Algorithms Every Programmer Should Know

Author: Imran Ahmad, PhD
Publisher: Packt Publishing, 2026


About This Repository

Software engineering has crossed from deterministic execution to sampled probability, opening a Reliability Gap between an ~80% prototype demo and a 99.9% production system. You cannot force a frontier language model to become deterministic, nor should you strip away the generative reasoning that makes it useful. Instead, you build a Deterministic Shell around a Probabilistic Core.

Chapter 1 Figure 1.2: The probabilistic poet on the left, the philosopher demanding shown work in the middle, and the deterministic accountant on the right.

Figure 1.2 – The poet, the philosopher, and the accountant: generative range on one side, transparent reasoning in the middle, and reproducible, auditable rigor on the other.

This repository is the complete, self-contained executable companion to all 17 chapters of Building Reliable AI-Assisted Software Systems. Every chapter folder (chapter-01-* through chapter-17-*) ships with two pre-executed, richly annotated Jupyter notebooks, chapter-aligned Python modules, book diagrams, simulated policy documents, golden datasets, progressive Cloudanum Inc. case-study dossiers (USECASE.md), troubleshooting guides (TROUBLESHOOTING.md), and automated pytest verification suites.


Two Notebook Editions in Every Chapter

Following the dual-execution standard established in 30 Agents Every AI Engineer Must Build, every chapter provides two ready-to-run Jupyter notebook editions:

Edition Filename Pattern API Key Required? How It Works
1. OpenAI Live Edition chNN_<topic>__RUN_OPENAI_GPT4o.ipynb OPENAI_API_KEY (via .env or environment) Connects to OpenAI (gpt-4o) via the official openai SDK for live prompts, judging, query rewriting, routing, and bounded agent loops. Every live call is wrapped in @graceful_fallback so rate limits, network blips, or missing keys fall back cleanly without unhandled exceptions.
2. Simulation Mode Edition chNN_<topic>__RUN_NO_KEY_SIMULATION.ipynb None (works with or without a key) Locks SIMULATION_MODE = True so every cell executes deterministically offline against chapter-calibrated MockLLM engines and committed Cloudanum fixtures, reproducing 100% of the book's canonical metrics identically across runs.

Each notebook includes:

  • Learning Objectives & Artifact Map right at the top, linking every cell to book sections, numbered listings, and canonical metrics
  • Embedded Book Figures (assets/fig_N_M_*.png) introduced and interpreted at each architectural boundary
  • Structured Bullet Walkthroughs & Packt Callout Boxes highlighting reliability trade-offs, failure modes, and governance invariants
  • Resilience Demonstration proving the zero-exception guarantee under 100% simulated provider failure (failure_rate=1.0)
  • Case File: Cloudanum status ledger tracking the 98-week engineering transformation from an offline prototype (INC-207 & INC-183) to a 99.6% safe-outcome production shell

Progressive Running Case Study: Cloudanum Inc. (Week 0 to Week 98)

Across all 17 chapters, you build the production reliability stack for Cloudanum Inc., a mid-sized 3D design and cloud-rendering software company headquartered in Ottawa, Canada (serving 90,000 studios and ~850 weekday support tickets across $350/month refundable trials, $4,200/year non-refundable Studio seats, and $30/hour GPU render nodes).

Chapter 17 Figure 17.7: Cloudanum Week 0 unguarded prototype vs Week 98 Four-Pillar Deterministic Shell.

Figure 17.7 – Cloudanum from Week 0 (INC-207 $4,200 refund fabrication & INC-183 $23,400 GPU loop) to Week 98 (Four-Pillar Deterministic Shell, 1,240 golden cases, 1-day model swap, 99.6% safe-outcome SLO).


Chapter-by-Chapter Guide

Part I: The New Paradigm

Ch Chapter & Folder Notebooks (OpenAI & Simulation) Cloudanum Case File (USECASE.md)
01 The Reliability Gap __RUN_OPENAI_GPT4o · __RUN_NO_KEY_SIMULATION Week 0 · 12/12 demo vs INC-207 ($4,200 refund) & INC-183 ($23,400 GPU loop); 0.90^5 = 59% chain compounding
02 The Engineering Mindset for AI __RUN_OPENAI_GPT4o · __RUN_NO_KEY_SIMULATION Week 3 · Backlog +38% while offline; Four-Pillar DeterministicShell blueprint & @graceful_fallback

Part II: Pillar 1 — Eval-Driven Development

Ch Chapter & Folder Notebooks (OpenAI & Simulation) Cloudanum Case File (USECASE.md)
03 Defining Correctness and Golden Datasets __RUN_OPENAI_GPT4o · __RUN_NO_KEY_SIMULATION Week 6 · golden_v1.0.jsonl (150 cases across 6 intents), golden_0047, starting pass rate 72.0% (108/150)
04 Evaluation Strategies and Automated Judging __RUN_OPENAI_GPT4o · __RUN_NO_KEY_SIMULATION Week 9 · faithfulness_judge v1.1 calibrated on Omar's 250-transcript pool (78% -> 91% agreement, kappa = 0.77)
05 CI for LLM Apps __RUN_OPENAI_GPT4o · __RUN_NO_KEY_SIMULATION Week 12 · baseline_v1 = 92.0% (138/150); empathy prompt tweak (88.0%) & JSON parse regression (6.1%) blocked at CI gate
06 Debugging with Evals __RUN_OPENAI_GPT4o · __RUN_NO_KEY_SIMULATION Week 16 · trace_schema_v1 (17 fields) + Blame Ladder isolating recall@5 drop (0.83 -> 0.61) to Markdown parser

Part III: Pillar 2 — Context Engineering

Ch Chapter & Folder Notebooks (OpenAI & Simulation) Cloudanum Case File (USECASE.md)
07 Context Window as Application State __RUN_OPENAI_GPT4o · __RUN_NO_KEY_SIMULATION Week 18 · 16,000-token ContextWindow + compact_history; 20-turn studio adherence 71% -> 89% (40 multi-turn cases)
08 Advanced RAG Architectures __RUN_OPENAI_GPT4o · __RUN_NO_KEY_SIMULATION Week 20 · 6-stage hybrid BM25 + dense RRF + cross-encoder reranking (recall@5: 0.61 -> 0.89, faithfulness 89% -> 95%)
09 Memory and State Across Sessions __RUN_OPENAI_GPT4o · __RUN_NO_KEY_SIMULATION Week 23 · Scoped MemoryFact, TTL session store & authority reconciler; cross-session consistency 68% -> 90% (310 cases)

Part IV: Pillar 3 — Agentic Patterns

Ch Chapter & Folder Notebooks (OpenAI & Simulation) Cloudanum Case File (USECASE.md)
10 When You Need an Agent __RUN_OPENAI_GPT4o · __RUN_NO_KEY_SIMULATION Week 26 · Autonomy adoption rubric routing 850 weekday tickets into an 80/15/4/1 tier mix (~3.5x token savings)
11 Deterministic Patterns: Chains, Routers, Gateways __RUN_OPENAI_GPT4o · __RUN_NO_KEY_SIMULATION Week 30 · Constrained intent router, circuit breaker & fallback ladder (95% deterministic, 97.4% accuracy, $0.05/ticket, p95 2.1s)
12 Agentic Patterns: Orchestration, ReAct, and Self-Improvement __RUN_OPENAI_GPT4o · __RUN_NO_KEY_SIMULATION Week 33 · Plan-gated orchestrator, 12-call / $0.50 / 60s bounded ReAct loop & stuck detector (71% resolved in bounds, 0 violations)
13 Human-in-the-Loop Patterns __RUN_OPENAI_GPT4o · __RUN_NO_KEY_SIMULATION Week 35 · Ingrid's <$400 deterministic ceiling + Omar's async review queue ($460 case D-3141 resolved in 4m; 450 golden cases)

Part V: Pillar 4 — Governance

Ch Chapter & Folder Notebooks (OpenAI & Simulation) Cloudanum Case File (USECASE.md)
14 The Determinism Sandwich __RUN_OPENAI_GPT4o · __RUN_NO_KEY_SIMULATION Week 38 · Input schema/tripwire, PII vault, constrained decoding & egress validator (40/40 adversarial attempts blocked incl. $10,000)
15 Safety and Compliance by Design __RUN_OPENAI_GPT4o · __RUN_NO_KEY_SIMULATION Week 41 · 23-rule refund_constitution_v1 (Python + Rego), EU AI Act / GDPR audit_record_v1 (100% reconstructible, 0 findings)
16 Operating Guardrails in Production __RUN_OPENAI_GPT4o · __RUN_NO_KEY_SIMULATION Week 44 / GA Wk 46 · Worst-case cost limiter, Prometheus exporter & kill switch (INC-241 rolled back in 3m40s; 99.2% SLO; 530 cases)

Part VI: Bringing It All Together

Ch Chapter & Folder Notebooks (OpenAI & Simulation) Cloudanum Case File (USECASE.md)
17 The Path Forward __RUN_OPENAI_GPT4o · __RUN_NO_KEY_SIMULATION Week 98 · Swappable ModelProvider promotion gate, 1,240-case flywheel, 1-day flagship model upgrade, 99.6% safe-outcome SLO

Quickstart

Option A: Run Immediately in Simulation Mode (Zero API Key)

git clone https://github.com/PacktPublishing/Building-Reliable-AI-Assisted-Software.git
cd Building-Reliable-AI-Assisted-Software/chapter-02-the-engineering-mindset-for-ai

python3 -m venv .venv
source .venv/bin/activate          # Windows: .venv\Scripts\activate
pip install -r requirements.txt

jupyter lab ch02_the_engineering_mindset__RUN_NO_KEY_SIMULATION.ipynb

Option B: Run Against Live OpenAI (gpt-4o)

cd chapter-02-the-engineering-mindset-for-ai
pip install -r requirements.txt -r requirements-openai.txt

cp .env.template .env
# Edit .env and set OPENAI_API_KEY=sk-...

jupyter lab ch02_the_engineering_mindset__RUN_OPENAI_GPT4o.ipynb

Option C: Batch-Execute or Test Across All 17 Chapters

# Execute all 17 Simulation Mode notebooks + chapter pytest suites
python3 scripts/run_all_notebooks.py --mode simulation --run-tests

# Execute all 17 OpenAI notebooks (loads OPENAI_API_KEY from .env, env, or ../key.txt)
python3 scripts/run_all_notebooks.py --mode openai

See EXECUTION_AND_MODES.md for full details on API key resolution, simulation determinism, and troubleshooting.


How to Navigate This Repository

Goal Start Here Next Steps
Master the full Four-Pillar architecture Chapters 01 → 02 Follow Pillars 1–4 sequentially (03–06 → 07–09 → 10–13 → 14–16 → 17)
Stop prompt regressions in CI/CD Chapter 03 (Golden Datasets) Chapter 04 (Calibrated Judges) → Chapter 05 (3-Lane CI Gate) → Chapter 06 (Blame Ladder)
Fix RAG collisions & multi-turn context rot Chapter 07 (Context Budget) Chapter 08 (Hybrid RRF + Cross-Encoder Rerank) → Chapter 09 (Cross-Session Memory)
Bound autonomous agents & tool spend Chapter 10 (Autonomy Rubric) Chapter 11 (Routers & Circuit Breakers) → Chapter 12 (Bounded ReAct) → Chapter 13 (HITL Queue)
Enforce PII, EU AI Act / GDPR & kill switches Chapter 14 (Determinism Sandwich) Chapter 15 (Policy-as-Code & Audit Log) → Chapter 16 (Production Guardrails & Rollback)

License

Released under the MIT License. All company names, characters, incidents, and datasets in the Cloudanum Inc. case study are fictional engineering composites created for educational purposes.

About

Building Reliable AI Assisted Software, published by Packt

Resources

Stars

1 star

Watchers

0 watching

Forks

Releases

Packages

Used by

Contributors

Languages