Leanpub Header

Skip to main content

From Machine Learning to Agentic AI

Master ML foundations, transformers, and LLMs—then build production agent systems that actually survive deployment.

Minimum price

$19.00

$29.00

You pay

$29.00

Author earns

$23.20
$

...Or Buy With Credits!

You can get credits with a paid monthly or annual Reader Membership, or you can buy them here.
PDF
EPUB
WEB
About

About

About the Book

From Machine Learning to Agentic AI is a complete guide to building production-ready agent systems—starting from first principles.

You'll progress through ML fundamentals, neural networks, and transformer architecture—the foundation of modern LLMs. Then you'll move beyond chatbots into true agency: tool use, multi-step reasoning, memory systems, and multi-agent orchestration.

But capability without reliability is dangerous. That's why this book goes deeper than tutorials. You'll learn the failure modes that most resources avoid: tool hallucination, context exhaustion, state drift, and when agents are the wrong tool entirely.

What you'll learn:

- Foundations: ML essentials, neural networks, transformers, tokenization, training

- LLMs: Modern architectures, APIs, prompt engineering, quantization

- Agency: Architecture patterns, tool use, planning, memory, multi-agent systems

- Production: Evaluation, observability, failure modes, deployment, governance

Most books show you how to build agents that work once. This book shows you how to build systems that survive production.

Share this book

Author

About the Author

Yusef Ulum

Yusef Ulum is a software engineer and systems thinker with 23 years of experience building applications across finance, telecommunications, embedded systems, and the web. Since 2023, he has focused on applied machine learning and AI. He writes about technology, history, and geopolitics, exploring how complex systems succeed, fail, and evolve.

Contents

Table of Contents

Preface

  1. Why This Book?
  2. Who Is This For?
  3. How to Use This Book
  4. The Philosophy
  5. What’s Not in This Book
  6. A Note on the Moving Target
  7. Acknowledgments
  8. About the Author
  9. A Note for Instructors
  10. A Note for Self-Learners
  11. Conventions Used in This Book
  12. Feedback and Errata
  13. Resources

Chapter 1: The AI Revolution in Context

  1. 1.1 Why This Book, Why Now?
  2. 1.2 A Brief History: How We Got Here
  3. 1.3 What Is “Agentic AI,” Exactly?
  4. 1.4 What Everyone Else Gets Wrong
  5. 1.5 The Market Context
  6. 1.6 Who This Book Is For
  7. 1.7 How This Book Is Organized
  8. 1.8 The Book’s Philosophy
  9. 1.9 Before We Begin
  10. 1.10 Let’s Get Started
  11. Chapter Summary
  12. Up Next
  13. References

Chapter 2: Machine Learning Essentials

  1. Chapter Overview
  2. 2.1 What Is Machine Learning?
  3. 2.2 The ML Pipeline: How Learning Happens
  4. 2.3 The Algorithm That Matters: Gradient Descent
  5. 2.4 Linear Models: The Foundation
  6. 2.5 Classification: Predicting Categories
  7. 2.6 Decision Trees and Ensembles
  8. 2.7 Feature Engineering: The Dirty Secret
  9. 2.8 The Bridge to Neural Networks: Perceptrons
  10. 2.9 Evaluation: How Do We Know It Works?
  11. 2.10 Cross-Validation: Better Evaluation
  12. 2.11 The Bias-Variance Tradeoff
  13. 2.12 Regularization: Preventing Overfitting
  14. 2.13 Embeddings: The Bridge to Transformers
  15. 2.14 Hands-On: Train a Simple Model
  16. Chapter Summary
  17. What to Skip If You Know ML
  18. Up Next
  19. References

Chapter 3: Neural Networks and Deep Learning

  1. Chapter Overview
  2. 3.1 The Single Neuron: Perceptron Redux
  3. 3.2 Multi-Layer Perceptrons (MLPs)
  4. 3.3 Backpropagation: How Networks Learn
  5. 3.4 Training Loop: Putting It Together
  6. 3.5 The Pre-Transformer Era: CNNs and RNNs
  7. 3.6 LSTMs and GRUs: The RNN Evolution
  8. 3.7 Attention Before Transformers
  9. 3.8 From CNNs/RNNs to Transformers
  10. 3.9 Hands-On: Implement a Neural Network
  11. 3.10 The Limitation: Why We Needed Transformers
  12. Chapter Summary
  13. Up Next
  14. References

Chapter 4: The Transformer Architecture Deep Dive

  1. Chapter Overview
  2. 4.1 The Problem: Why We Needed Transformers
  3. 4.2 Self-Attention: The Heart of Transformers
  4. 4.3 Multi-Head Attention: Why One Head Isn’t Enough
  5. 4.4 Positional Encoding: Remembering Order
  6. 4.5 The Complete Transformer Layer
  7. 4.6 Encoder vs. Decoder: Three Variants
  8. 4.7 Building a Mini-Transformer
  9. 4.8 The Scaling Laws: Why Bigger Is Better
  10. 4.9 Hands-On: Implement Attention from Scratch
  11. Chapter Summary
  12. Up Next
  13. References

Chapter 5: Tokenization: The Hidden Foundation

  1. Chapter Overview
  2. 5.1 Why Tokenization Matters
  3. 5.2 Approaches to Tokenization
  4. 5.3 Byte-Pair Encoding (BPE)
  5. 5.4 WordPiece: Google’s Approach
  6. 5.5 SentencePiece: Language-Agnostic Tokenization
  7. 5.6 Modern Tokenizers: TikToken and Beyond
  8. 5.7 Tokenization Artifacts and Edge Cases
  9. 5.8 Counting Tokens: Practical Considerations
  10. 5.9 Hands-On: Build a BPE Tokenizer
  11. Chapter Summary
  12. Up Next
  13. References

Chapter 6: Training and Fine-Tuning LLMs

  1. Chapter Overview
  2. 6.1 Pre-Training vs. Fine-Tuning
  3. 6.2 Pre-Training: How Foundation Models Are Built
  4. 6.3 Scaling Laws: The Chinchilla Finding
  5. 6.4 Fine-Tuning: Adapting Pre-Trained Models
  6. 6.5 Instruction Tuning
  7. 6.6 RLHF: Reinforcement Learning from Human Feedback
  8. 6.7 Hands-On: Fine-Tune a Model
  9. 6.8 When to Use What
  10. 6.9 Fine-Tuning for Agent Workloads
  11. Chapter Summary
  12. Up Next
  13. References

Chapter 7: Modern LLMs

  1. Chapter Overview
  2. 7.1 The LLM Landscape (2025-2026)
  3. 7.2 Closed vs. Open Source: The Trade-offs
  4. 7.3 Model Capabilities: What’s Possible Today
  5. 7.4 Model Selection: A Framework
  6. 7.5 Model Selection for Agent Workloads
  7. 7.6 The Hidden Factors
  8. 7.7 Model Benchmarks
  9. 7.8 Hands-On: Comparing Models
  10. 7.9 The Future: What’s Coming Next
  11. Chapter Summary
  12. Up Next
  13. References

Chapter 8: Working with LLM APIs

  1. Chapter Overview
  2. 8.1 The API Landscape
  3. 8.2 The Chat API: Modern Standard
  4. 8.3 Anthropic Claude API
  5. 8.4 Streaming Responses
  6. 8.5 Prompt Management
  7. 8.6 Error Handling and Retries
  8. 8.7 Cost Optimization
  9. 8.8 Production Considerations
  10. 8.9 Hands-On: Build a Production LLM Client
  11. Chapter Summary
  12. Up Next
  13. References

Chapter 9: What Makes AI “Agentic”?

  1. Chapter Overview
  2. 9.1 Defining Agency: What It Is and Isn’t
  3. 9.2 The Six Components of Agentic Systems
  4. 9.3 Real-World Examples
  5. 9.4 The Agentic Architecture
  6. 9.5 From Chatbot to Agent: A Transformation
  7. 9.6 When to Use Agents vs. Simpler Approaches
  8. 9.7 Types of Agents
  9. Production Principles
  10. Chapter Summary
  11. DO / DON’T
  12. Practitioner Checklist
  13. Patterns
  14. Up Next
  15. References

Chapter 10: Agentic Architecture Patterns

  1. Chapter Overview
  2. 10.1 What Makes Architecture “Agentic”?
  3. 10.2 The ReAct Pattern: Reasoning + Acting
  4. 10.3 Implementing ReAct from Scratch
  5. 10.4 The Planning Pattern
  6. 10.5 The Sequential Workflow Pattern
  7. 10.6 The Human-in-the-Loop Pattern
  8. 10.7 Complementary Patterns
  9. 10.8 Pattern Selection Guide
  10. 10.9 Hands-On Exercise: Build a ReAct Agent
  11. 10.10 Common Pitfalls and Solutions
  12. 10.11 Evaluating Agentic Systems
  13. Production Principles
  14. Chapter Summary
  15. Up Next
  16. References

Chapter 11: Agent Frameworks and Tooling

  1. Chapter Overview
  2. 11.1 The Framework Problem
  3. 11.2 The Agentic Framework Landscape (January 2026)
  4. 11.3 Framework Deep Dive: LangGraph
  5. 11.4 Framework Deep Dive: CrewAI
  6. 11.5 Framework Deep Dive: AutoGen
  7. 11.6 Framework Comparison: The Same Agent, Three Ways
  8. 11.7 When to Build From Scratch
  9. 11.8 LlamaIndex and Emerging Frameworks
  10. 11.9 Protocol Standards: MCP and A2A
  11. 11.10 Hands-On: Build It Three Ways
  12. 11.11 Observability Platforms
  13. Production Principles
  14. Chapter Summary
  15. Up Next
  16. References

Chapter 12: Tool Use and Function Calling

  1. Chapter Overview
  2. 12.1 What Are Tools?
  3. 12.2 Function Calling: The Foundation
  4. 12.3 Designing Effective Tools
  5. 12.4 Tool Reliability Engineering
  6. 12.5 Tool Composition and Chaining
  7. 12.5 Tool Security
  8. 12.6 Hands-On: Build a Tool Library
  9. 12.7 Quantization and Tool Reliability
  10. 12.8 Browser Agents: When APIs Don’t Exist
  11. Production Principles
  12. Chapter Summary
  13. Up Next
  14. References

Chapter 13: Building a First Agent

  1. Chapter Overview
  2. Bridge: Why LLM-Only Systems Break
  3. 13.1 Agent Anatomy: What We’re Building
  4. 13.2 The ReAct Loop: Foundation of Our Agent
  5. 13.3 Adding Web Search
  6. 13.4 Adding Memory
  7. 13.5 Error Handling and Logging
  8. 13.6 Complete Research Agent
  9. 13.7 Testing Our Agent
  10. 13.8 Common Issues and Debugging
  11. 13.9 Hands-On: Build an Agent
  12. Production Principles
  13. Chapter Summary
  14. Up Next
  15. References

Chapter 14: Memory and Knowledge Systems

  1. Chapter Overview
  2. 14.1 The Memory Problem
  3. 14.2 Three Types of Agent Memory (Cognitive Science Framework)
  4. 14.3 Vector Databases for Semantic Memory
  5. 14.4 RAG: Retrieval Augmented Generation
  6. 14.5 Building RAG from Scratch
  7. 14.6 Advanced RAG Patterns
  8. 14.7 Chunking Strategies
  9. 14.8 Evaluating RAG Systems
  10. 14.9 Hands-On Exercise: Build a Memory-Enhanced Agent
  11. Production Principles
  12. Chapter Summary
  13. Up Next
  14. References

Chapter 15: Advanced RAG Patterns

  1. Chapter Overview
  2. 15.1 The Problem with Naive RAG
  3. 15.2 Pre-Retrieval: Fixing the Query
  4. 15.3 Advanced Retrieval: Better Search
  5. 15.4 Post-Retrieval: Better Context
  6. 15.5 GraphRAG: When Graphs Beat Vectors
  7. 15.6 Evaluating RAG Systems
  8. 15.7 Hands-On: Build an Advanced RAG System
  9. Production Principles
  10. Chapter Summary
  11. Up Next
  12. References

Chapter 16: Multi-Agent Systems

  1. Chapter Overview
  2. 16.1 The Multi-Agent Decision
  3. 16.2 Orchestration Patterns
  4. 16.3 Arbitration and Conflict Resolution
  5. 16.4 Coordination Failure Modes
  6. 16.5 Framework Selection
  7. 16.4 Production Realities
  8. 16.5 Long-Horizon Failures
  9. 16.6 Communication Protocols
  10. Production Principles
  11. Chapter Summary
  12. Up Next
  13. References

Chapter 17: Agentic Workflows for Enterprise

  1. Chapter Overview
  2. 17.1 Customer Service Agents
  3. 17.2 Research and Analysis Agents
  4. 17.3 Software Development Agents
  5. 17.4 Why Agentic AI Projects Fail
  6. 17.5 Measuring Success
  7. 17.6 Production Realities (2026)
  8. DO / DON’T
  9. Practitioner Checklist
  10. Anti-Patterns
  11. Patterns
  12. Production Principles
  13. Chapter Summary
  14. Up Next
  15. References

Chapter 18: Deploying Agentic Systems

  1. Chapter Overview
  2. 18.1 Deployment Architectures
  3. 18.2 Infrastructure Considerations
  4. 18.3 Scaling Strategies
  5. 18.4 Enterprise Infrastructure (2026)
  6. 18.5 Monitoring and Observability
  7. 18.5 Cost Management
  8. 18.6 Hands-On: Deploy with Docker
  9. 18.7 Production Realities: What Actually Happens
  10. 18.8 Computer Use: When GUIs Have No APIs
  11. Chapter Summary
  12. Up Next
  13. References

Chapter 19: Safety, Ethics, and Governance

  1. Chapter Overview
  2. 19.1 The Agent Safety Problem
  3. 19.2 Guardrails: The Three-Layer Architecture
  4. 19.3 Prompt Injection in Agentic Systems
  5. 19.4 Human-in-the-Loop: Control, Not Feature
  6. 19.5 Privacy: Data Minimization in Practice
  7. 19.6 Governance: The Missing Layer in Most Deployments
  8. Chapter Summary
  9. Up Next
  10. References

Chapter 20: Evaluation and Testing

  1. Why Testing Agents is Different
  2. Evaluation Framework Components
  3. Building an Evaluation Harness
  4. Multi-Agent System Evaluation
  5. 20.1 Agent Benchmarks (2026)
  6. 20.2 Benchmark Best Practices
  7. 20.3 Benchmark Reference Table
  8. 20.4 Patterns
  9. A/B Testing Agent Configurations
  10. Evaluation Best Practices
  11. Red Teaming and Failure Analysis
  12. Continuous Evaluation
  13. Summary
  14. Next Steps

Chapter 21: Observability and Debugging

  1. Why Observability Matters for Agents
  2. Distributed Tracing for Agents
  3. Metrics and Monitoring
  4. Cost Tracking
  5. Debugging Agent Failures
  6. Production Monitoring
  7. 21.1 Enterprise Compliance Observability (2026)
  8. Integration with External Tools
  9. Best Practices
  10. Summary
  11. Conclusion

Chapter 22: Failure Modes and Recovery

  1. Chapter Overview
  2. 22.1 The Failure Spectrum
  3. 22.2 LLM-Level Failures
  4. 22.3 Reasoning-Level Failures
  5. 22.4 Tool-Level Failures
  6. 22.5 Interaction-Level Failures
  7. 22.6 Detection Patterns
  8. 22.7 Recovery Strategies
  9. 22.8 Recovery Architectures
  10. 22.9 Chaos Engineering
  11. 22.10 Practitioner Checklist
  12. DO / DON’T
  13. Patterns
  14. Anti-Patterns
  15. Chapter Summary
  16. Up Next
  17. Key Takeaways
  18. References

Chapter 23: Human-in-the-Loop & Enterprise Workflows

  1. The HITL Spectrum
  2. Risk-Based Approval Gates
  3. Escalation Paths
  4. Event-Driven Triggers
  5. Manual Override
  6. Multi-Agent Oversight
  7. Correction Workflows
  8. UI for Human Review
  9. Enterprise Integration
  10. Production Realities
  11. Summary
  12. Key Takeaways

Chapter 24: When NOT to Use Agents

  1. Chapter Overview
  2. 24.1 The Cost Hierarchy
  3. 24.2 Decision Framework
  4. 24.3 Cost Analysis at Scale
  5. 24.4 Reliability Considerations
  6. 24.5 Red Flags: When NOT to Use Agents
  7. 24.6 The Kill List: Do NOT Use Agents When
  8. 24.7 When Agents Are the Right Choice
  9. 24.8 Migration Path: Start Simple, Scale Up
  10. Chapter Summary
  11. Up Next
  12. Key Takeaways
  13. References

Chapter 25: Agent Design Patterns

  1. Why Patterns Matter
  2. Pattern 1: Orchestrator
  3. Pattern 2: Tool-First Design
  4. Pattern 3: Planner-Executor
  5. Pattern 4: ReAct (Reason + Act)
  6. Pattern 5: Stateless vs Stateful
  7. Pattern 6: Adapter Pattern
  8. Choosing the Right Pattern
  9. Anti-Patterns
  10. Production Realities
  11. Summary
  12. Key Takeaways

Chapter 26: Planner Engineering

  1. Chapter Overview
  2. 26.1 Why Most Planning Fails
  3. 26.2 Planning Architecture Comparison
  4. 26.3 Plan Verification
  5. 26.4 Replanning Triggers
  6. 26.5 Planner vs Executor Separation
  7. 26.6 Planning Templates
  8. 26.7 Practitioner Checklist
  9. DO / DON’T
  10. Patterns
  11. Anti-Patterns
  12. Summary
  13. Next Steps
  14. References

Chapter 27: Model Selection for Agents

  1. Chapter Overview
  2. 27.1 The Model Selection Decision Tree
  3. 27.2 Model-by-Model Analysis
  4. 27.3 Workload-Specific Recommendations
  5. 27.4 Model Fallback Chains
  6. 27.5 Heterogeneous Multi-Agent Teams
  7. 27.6 Cost Comparison
  8. 27.7 Practitioner Checklist
  9. DO / DON’T
  10. Patterns
  11. Summary
  12. Next Steps
  13. References

Chapter 28: Multi-Tenant Agent Governance

  1. Chapter Overview
  2. 28.1 The Multi-Tenant Problem Space
  3. 28.2 Tenant Isolation
  4. 28.3 Tool Permissions
  5. 28.4 Tool Schema Versioning
  6. 28.5 Audit Trails
  7. 28.6 Tool-Call Tracing and Replay
  8. 28.7 Execution Sandboxes
  9. 28.8 Agent Commit Protocol
  10. 28.9 Architecture Overview
  11. DO / DON’T
  12. Practitioner Checklist
  13. Patterns
  14. Summary
  15. Next Steps
  16. References

Chapter 29: Enterprise Integration Patterns

  1. Chapter Overview
  2. 29.1 API Integration Patterns
  3. 29.2 Agent Integration Patterns
  4. 29.3 Event-Driven Agent Systems
  5. 29.4 Legacy System Integration
  6. 29.5 Enterprise Agent Architecture
  7. DO / DON’T
  8. Practitioner Checklist
  9. Patterns
  10. Summary
  11. Next Steps
  12. References

Appendix A: Quick Reference Index

  1. A
  2. B
  3. C
  4. D
  5. E
  6. F
  7. G
  8. H
  9. I
  10. K
  11. L
  12. M
  13. O
  14. P
  15. Q
  16. R
  17. S
  18. T
  19. V
  20. W
  21. Code Examples Index
  22. Framework Decision Matrix
  23. LLM Selection Guide
  24. Common Workflows

Appendix B: Enterprise Case Studies

  1. Case Study 1: Financial Document Analyzer Agent
  2. Case Study 2: DevOps Automation Agent
  3. Case Study 3: Enterprise Browser Agent
  4. Cross-Case Patterns
  5. Final Takeaway

Glossary

  1. A
  2. B
  3. C
  4. D
  5. E
  6. F
  7. G
  8. H
  9. I
  10. K
  11. L
  12. M
  13. N
  14. O
  15. P
  16. Q
  17. R
  18. S
  19. T
  20. U
  21. V
  22. W
  23. Z
  24. Acronyms

Resources and Further Reading

  1. Frameworks and Libraries
  2. Research Papers
  3. Books
  4. Online Courses
  5. Communities
  6. Tools and Utilities
  7. Datasets
  8. Blogs and Newsletters
  9. Code Examples and Templates
  10. Reference Cards and Cheat Sheets
  11. Standards and Best Practices
  12. Citation Information
  13. Keeping Updated
  14. Version History

Acknowledgments

  1. Research Community
  2. The Agentic AI Pioneers
  3. The Pragmatic Engineers
  4. Personal Thanks
  5. To the Reader
  6. Errors and Feedback

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.

Now, this is technically risky for us, since you'll have the book or course files either way. But we're so confident in our products and services, and in our authors and readers, that we're happy to offer a full money back guarantee for everything we sell.

You can only find out how good something is by trying it, and because of our 100% money back guarantee there's literally no risk to do so!

So, there's no reason not to click the Add to Cart button, is there?

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.)

In fact, authors have earned over $14 million writing, publishing and selling 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