Preface
- Why This Book?
- Who Is This For?
- How to Use This Book
- The Philosophy
- What’s Not in This Book
- A Note on the Moving Target
- Acknowledgments
- About the Author
- A Note for Instructors
- A Note for Self-Learners
- Conventions Used in This Book
- Feedback and Errata
- Resources
Chapter 1: The AI Revolution in Context
- 1.1 Why This Book, Why Now?
- 1.2 A Brief History: How We Got Here
- 1.3 What Is “Agentic AI,” Exactly?
- 1.4 What Everyone Else Gets Wrong
- 1.5 The Market Context
- 1.6 Who This Book Is For
- 1.7 How This Book Is Organized
- 1.8 The Book’s Philosophy
- 1.9 Before We Begin
- 1.10 Let’s Get Started
- Chapter Summary
- Up Next
- References
Chapter 2: Machine Learning Essentials
- Chapter Overview
- 2.1 What Is Machine Learning?
- 2.2 The ML Pipeline: How Learning Happens
- 2.3 The Algorithm That Matters: Gradient Descent
- 2.4 Linear Models: The Foundation
- 2.5 Classification: Predicting Categories
- 2.6 Decision Trees and Ensembles
- 2.7 Feature Engineering: The Dirty Secret
- 2.8 The Bridge to Neural Networks: Perceptrons
- 2.9 Evaluation: How Do We Know It Works?
- 2.10 Cross-Validation: Better Evaluation
- 2.11 The Bias-Variance Tradeoff
- 2.12 Regularization: Preventing Overfitting
- 2.13 Embeddings: The Bridge to Transformers
- 2.14 Hands-On: Train a Simple Model
- Chapter Summary
- What to Skip If You Know ML
- Up Next
- References
Chapter 3: Neural Networks and Deep Learning
- Chapter Overview
- 3.1 The Single Neuron: Perceptron Redux
- 3.2 Multi-Layer Perceptrons (MLPs)
- 3.3 Backpropagation: How Networks Learn
- 3.4 Training Loop: Putting It Together
- 3.5 The Pre-Transformer Era: CNNs and RNNs
- 3.6 LSTMs and GRUs: The RNN Evolution
- 3.7 Attention Before Transformers
- 3.8 From CNNs/RNNs to Transformers
- 3.9 Hands-On: Implement a Neural Network
- 3.10 The Limitation: Why We Needed Transformers
- Chapter Summary
- Up Next
- References
Chapter 4: The Transformer Architecture Deep Dive
- Chapter Overview
- 4.1 The Problem: Why We Needed Transformers
- 4.2 Self-Attention: The Heart of Transformers
- 4.3 Multi-Head Attention: Why One Head Isn’t Enough
- 4.4 Positional Encoding: Remembering Order
- 4.5 The Complete Transformer Layer
- 4.6 Encoder vs. Decoder: Three Variants
- 4.7 Building a Mini-Transformer
- 4.8 The Scaling Laws: Why Bigger Is Better
- 4.9 Hands-On: Implement Attention from Scratch
- Chapter Summary
- Up Next
- References
Chapter 5: Tokenization: The Hidden Foundation
- Chapter Overview
- 5.1 Why Tokenization Matters
- 5.2 Approaches to Tokenization
- 5.3 Byte-Pair Encoding (BPE)
- 5.4 WordPiece: Google’s Approach
- 5.5 SentencePiece: Language-Agnostic Tokenization
- 5.6 Modern Tokenizers: TikToken and Beyond
- 5.7 Tokenization Artifacts and Edge Cases
- 5.8 Counting Tokens: Practical Considerations
- 5.9 Hands-On: Build a BPE Tokenizer
- Chapter Summary
- Up Next
- References
Chapter 6: Training and Fine-Tuning LLMs
- Chapter Overview
- 6.1 Pre-Training vs. Fine-Tuning
- 6.2 Pre-Training: How Foundation Models Are Built
- 6.3 Scaling Laws: The Chinchilla Finding
- 6.4 Fine-Tuning: Adapting Pre-Trained Models
- 6.5 Instruction Tuning
- 6.6 RLHF: Reinforcement Learning from Human Feedback
- 6.7 Hands-On: Fine-Tune a Model
- 6.8 When to Use What
- 6.9 Fine-Tuning for Agent Workloads
- Chapter Summary
- Up Next
- References
Chapter 7: Modern LLMs
- Chapter Overview
- 7.1 The LLM Landscape (2025-2026)
- 7.2 Closed vs. Open Source: The Trade-offs
- 7.3 Model Capabilities: What’s Possible Today
- 7.4 Model Selection: A Framework
- 7.5 Model Selection for Agent Workloads
- 7.6 The Hidden Factors
- 7.7 Model Benchmarks
- 7.8 Hands-On: Comparing Models
- 7.9 The Future: What’s Coming Next
- Chapter Summary
- Up Next
- References
Chapter 8: Working with LLM APIs
- Chapter Overview
- 8.1 The API Landscape
- 8.2 The Chat API: Modern Standard
- 8.3 Anthropic Claude API
- 8.4 Streaming Responses
- 8.5 Prompt Management
- 8.6 Error Handling and Retries
- 8.7 Cost Optimization
- 8.8 Production Considerations
- 8.9 Hands-On: Build a Production LLM Client
- Chapter Summary
- Up Next
- References
Chapter 9: What Makes AI “Agentic”?
- Chapter Overview
- 9.1 Defining Agency: What It Is and Isn’t
- 9.2 The Six Components of Agentic Systems
- 9.3 Real-World Examples
- 9.4 The Agentic Architecture
- 9.5 From Chatbot to Agent: A Transformation
- 9.6 When to Use Agents vs. Simpler Approaches
- 9.7 Types of Agents
- Production Principles
- Chapter Summary
- DO / DON’T
- Practitioner Checklist
- Patterns
- Up Next
- References
Chapter 10: Agentic Architecture Patterns
- Chapter Overview
- 10.1 What Makes Architecture “Agentic”?
- 10.2 The ReAct Pattern: Reasoning + Acting
- 10.3 Implementing ReAct from Scratch
- 10.4 The Planning Pattern
- 10.5 The Sequential Workflow Pattern
- 10.6 The Human-in-the-Loop Pattern
- 10.7 Complementary Patterns
- 10.8 Pattern Selection Guide
- 10.9 Hands-On Exercise: Build a ReAct Agent
- 10.10 Common Pitfalls and Solutions
- 10.11 Evaluating Agentic Systems
- Production Principles
- Chapter Summary
- Up Next
- References
Chapter 11: Agent Frameworks and Tooling
- Chapter Overview
- 11.1 The Framework Problem
- 11.2 The Agentic Framework Landscape (January 2026)
- 11.3 Framework Deep Dive: LangGraph
- 11.4 Framework Deep Dive: CrewAI
- 11.5 Framework Deep Dive: AutoGen
- 11.6 Framework Comparison: The Same Agent, Three Ways
- 11.7 When to Build From Scratch
- 11.8 LlamaIndex and Emerging Frameworks
- 11.9 Protocol Standards: MCP and A2A
- 11.10 Hands-On: Build It Three Ways
- 11.11 Observability Platforms
- Production Principles
- Chapter Summary
- Up Next
- References
Chapter 12: Tool Use and Function Calling
- Chapter Overview
- 12.1 What Are Tools?
- 12.2 Function Calling: The Foundation
- 12.3 Designing Effective Tools
- 12.4 Tool Reliability Engineering
- 12.5 Tool Composition and Chaining
- 12.5 Tool Security
- 12.6 Hands-On: Build a Tool Library
- 12.7 Quantization and Tool Reliability
- 12.8 Browser Agents: When APIs Don’t Exist
- Production Principles
- Chapter Summary
- Up Next
- References
Chapter 13: Building a First Agent
- Chapter Overview
- Bridge: Why LLM-Only Systems Break
- 13.1 Agent Anatomy: What We’re Building
- 13.2 The ReAct Loop: Foundation of Our Agent
- 13.3 Adding Web Search
- 13.4 Adding Memory
- 13.5 Error Handling and Logging
- 13.6 Complete Research Agent
- 13.7 Testing Our Agent
- 13.8 Common Issues and Debugging
- 13.9 Hands-On: Build an Agent
- Production Principles
- Chapter Summary
- Up Next
- References
Chapter 14: Memory and Knowledge Systems
- Chapter Overview
- 14.1 The Memory Problem
- 14.2 Three Types of Agent Memory (Cognitive Science Framework)
- 14.3 Vector Databases for Semantic Memory
- 14.4 RAG: Retrieval Augmented Generation
- 14.5 Building RAG from Scratch
- 14.6 Advanced RAG Patterns
- 14.7 Chunking Strategies
- 14.8 Evaluating RAG Systems
- 14.9 Hands-On Exercise: Build a Memory-Enhanced Agent
- Production Principles
- Chapter Summary
- Up Next
- References
Chapter 15: Advanced RAG Patterns
- Chapter Overview
- 15.1 The Problem with Naive RAG
- 15.2 Pre-Retrieval: Fixing the Query
- 15.3 Advanced Retrieval: Better Search
- 15.4 Post-Retrieval: Better Context
- 15.5 GraphRAG: When Graphs Beat Vectors
- 15.6 Evaluating RAG Systems
- 15.7 Hands-On: Build an Advanced RAG System
- Production Principles
- Chapter Summary
- Up Next
- References
Chapter 16: Multi-Agent Systems
- Chapter Overview
- 16.1 The Multi-Agent Decision
- 16.2 Orchestration Patterns
- 16.3 Arbitration and Conflict Resolution
- 16.4 Coordination Failure Modes
- 16.5 Framework Selection
- 16.4 Production Realities
- 16.5 Long-Horizon Failures
- 16.6 Communication Protocols
- Production Principles
- Chapter Summary
- Up Next
- References
Chapter 17: Agentic Workflows for Enterprise
- Chapter Overview
- 17.1 Customer Service Agents
- 17.2 Research and Analysis Agents
- 17.3 Software Development Agents
- 17.4 Why Agentic AI Projects Fail
- 17.5 Measuring Success
- 17.6 Production Realities (2026)
- DO / DON’T
- Practitioner Checklist
- Anti-Patterns
- Patterns
- Production Principles
- Chapter Summary
- Up Next
- References
Chapter 18: Deploying Agentic Systems
- Chapter Overview
- 18.1 Deployment Architectures
- 18.2 Infrastructure Considerations
- 18.3 Scaling Strategies
- 18.4 Enterprise Infrastructure (2026)
- 18.5 Monitoring and Observability
- 18.5 Cost Management
- 18.6 Hands-On: Deploy with Docker
- 18.7 Production Realities: What Actually Happens
- 18.8 Computer Use: When GUIs Have No APIs
- Chapter Summary
- Up Next
- References
Chapter 19: Safety, Ethics, and Governance
- Chapter Overview
- 19.1 The Agent Safety Problem
- 19.2 Guardrails: The Three-Layer Architecture
- 19.3 Prompt Injection in Agentic Systems
- 19.4 Human-in-the-Loop: Control, Not Feature
- 19.5 Privacy: Data Minimization in Practice
- 19.6 Governance: The Missing Layer in Most Deployments
- Chapter Summary
- Up Next
- References
Chapter 20: Evaluation and Testing
- Why Testing Agents is Different
- Evaluation Framework Components
- Building an Evaluation Harness
- Multi-Agent System Evaluation
- 20.1 Agent Benchmarks (2026)
- 20.2 Benchmark Best Practices
- 20.3 Benchmark Reference Table
- 20.4 Patterns
- A/B Testing Agent Configurations
- Evaluation Best Practices
- Red Teaming and Failure Analysis
- Continuous Evaluation
- Summary
- Next Steps
Chapter 21: Observability and Debugging
- Why Observability Matters for Agents
- Distributed Tracing for Agents
- Metrics and Monitoring
- Cost Tracking
- Debugging Agent Failures
- Production Monitoring
- 21.1 Enterprise Compliance Observability (2026)
- Integration with External Tools
- Best Practices
- Summary
- Conclusion
Chapter 22: Failure Modes and Recovery
- Chapter Overview
- 22.1 The Failure Spectrum
- 22.2 LLM-Level Failures
- 22.3 Reasoning-Level Failures
- 22.4 Tool-Level Failures
- 22.5 Interaction-Level Failures
- 22.6 Detection Patterns
- 22.7 Recovery Strategies
- 22.8 Recovery Architectures
- 22.9 Chaos Engineering
- 22.10 Practitioner Checklist
- DO / DON’T
- Patterns
- Anti-Patterns
- Chapter Summary
- Up Next
- Key Takeaways
- References
Chapter 23: Human-in-the-Loop & Enterprise Workflows
- The HITL Spectrum
- Risk-Based Approval Gates
- Escalation Paths
- Event-Driven Triggers
- Manual Override
- Multi-Agent Oversight
- Correction Workflows
- UI for Human Review
- Enterprise Integration
- Production Realities
- Summary
- Key Takeaways
Chapter 24: When NOT to Use Agents
- Chapter Overview
- 24.1 The Cost Hierarchy
- 24.2 Decision Framework
- 24.3 Cost Analysis at Scale
- 24.4 Reliability Considerations
- 24.5 Red Flags: When NOT to Use Agents
- 24.6 The Kill List: Do NOT Use Agents When
- 24.7 When Agents Are the Right Choice
- 24.8 Migration Path: Start Simple, Scale Up
- Chapter Summary
- Up Next
- Key Takeaways
- References
Chapter 25: Agent Design Patterns
- Why Patterns Matter
- Pattern 1: Orchestrator
- Pattern 2: Tool-First Design
- Pattern 3: Planner-Executor
- Pattern 4: ReAct (Reason + Act)
- Pattern 5: Stateless vs Stateful
- Pattern 6: Adapter Pattern
- Choosing the Right Pattern
- Anti-Patterns
- Production Realities
- Summary
- Key Takeaways
Chapter 26: Planner Engineering
- Chapter Overview
- 26.1 Why Most Planning Fails
- 26.2 Planning Architecture Comparison
- 26.3 Plan Verification
- 26.4 Replanning Triggers
- 26.5 Planner vs Executor Separation
- 26.6 Planning Templates
- 26.7 Practitioner Checklist
- DO / DON’T
- Patterns
- Anti-Patterns
- Summary
- Next Steps
- References
Chapter 27: Model Selection for Agents
- Chapter Overview
- 27.1 The Model Selection Decision Tree
- 27.2 Model-by-Model Analysis
- 27.3 Workload-Specific Recommendations
- 27.4 Model Fallback Chains
- 27.5 Heterogeneous Multi-Agent Teams
- 27.6 Cost Comparison
- 27.7 Practitioner Checklist
- DO / DON’T
- Patterns
- Summary
- Next Steps
- References
Chapter 28: Multi-Tenant Agent Governance
- Chapter Overview
- 28.1 The Multi-Tenant Problem Space
- 28.2 Tenant Isolation
- 28.3 Tool Permissions
- 28.4 Tool Schema Versioning
- 28.5 Audit Trails
- 28.6 Tool-Call Tracing and Replay
- 28.7 Execution Sandboxes
- 28.8 Agent Commit Protocol
- 28.9 Architecture Overview
- DO / DON’T
- Practitioner Checklist
- Patterns
- Summary
- Next Steps
- References
Chapter 29: Enterprise Integration Patterns
- Chapter Overview
- 29.1 API Integration Patterns
- 29.2 Agent Integration Patterns
- 29.3 Event-Driven Agent Systems
- 29.4 Legacy System Integration
- 29.5 Enterprise Agent Architecture
- DO / DON’T
- Practitioner Checklist
- Patterns
- Summary
- Next Steps
- References
Appendix A: Quick Reference Index
- A
- B
- C
- D
- E
- F
- G
- H
- I
- K
- L
- M
- O
- P
- Q
- R
- S
- T
- V
- W
- Code Examples Index
- Framework Decision Matrix
- LLM Selection Guide
- Common Workflows
Appendix B: Enterprise Case Studies
- Case Study 1: Financial Document Analyzer Agent
- Case Study 2: DevOps Automation Agent
- Case Study 3: Enterprise Browser Agent
- Cross-Case Patterns
- Final Takeaway
Glossary
- A
- B
- C
- D
- E
- F
- G
- H
- I
- K
- L
- M
- N
- O
- P
- Q
- R
- S
- T
- U
- V
- W
- Z
- Acronyms
Resources and Further Reading
- Frameworks and Libraries
- Research Papers
- Books
- Online Courses
- Communities
- Tools and Utilities
- Datasets
- Blogs and Newsletters
- Code Examples and Templates
- Reference Cards and Cheat Sheets
- Standards and Best Practices
- Citation Information
- Keeping Updated
- Version History
Acknowledgments
- Research Community
- The Agentic AI Pioneers
- The Pragmatic Engineers
- Personal Thanks
- To the Reader
- Errors and Feedback