From Fundamentals to Production Deployments
Introduction: The Agent Revolution
- What Are AI Agents and Why They Matter
- From Claude Code CLI to Agent SDK
- What You Will Build
- How to Read This Book
Chapter 1: AI Agent Fundamentals
- The Anatomy of an AI Agent
- Tool Use and Function Calling
- The Agent Loop
- Memory Architectures for Agents
- Planning and Reasoning Patterns
- Agent vs. Workflow: When to Use Each
- Chapter Summary
- Exercises
- Interview Questions
Chapter 2: SDK Architecture and Environment Setup
- The SDK Stack: Client SDK vs. Agent SDK
- Installation and Authentication
- Project Configuration and CLAUDE.md
- The Subprocess Model
- Multi-Language Support: Python and TypeScript
- Chapter Summary
- Exercises
- Interview Questions
Chapter 3: Core APIs and the Agent Loop
- The query() Function
- ClaudeSDKClient for Multi-Turn Conversations
- Message Types and Lifecycle
- Turn Management and Budget Controls
- Session Persistence and Resumption
- The Agent Loop in Action: First Complete Example
- Chapter Summary
- Exercises
- Interview Questions
Chapter 4: Built-In Tools and Tool Use
- File Operations: Read, Write, Edit
- Search and Discovery: Glob, Grep
- Command Execution: Bash and Monitor
- Web Tools: WebSearch and WebFetch
- User Interaction: AskUserQuestion
- Permission Modes and Tool Access Control
- Parallel vs. Sequential Tool Execution
- Chapter Summary
- Exercises
- Interview Questions
Chapter 5: Custom Tools and MCP Integration
- Defining Custom Tools in-Process
- Tool Result Formats
- MCP Server Integration
- Tool Search and Context Optimization
- Building a Complete Custom Tool: Weather Service Example
- Chapter Summary
- Exercises
- Interview Questions
Chapter 6: Memory Systems and Context Management
- The Context Window: Sizes, Limits, and Budgets
- Automatic Context Compaction
- CLAUDE.md: Project-Level Memory
- The Memory Tool
- Retrieval-Augmented Generation with Agents
- Context Optimization Strategies
- Chapter Summary
- Exercises
- Interview Questions
Chapter 7: Prompt Engineering for Agents
- System Prompts vs. User Prompts in Agent Context
- Writing Effective Agent System Prompts
- CLAUDE.md Mastery
- XML Structuring and Few-Shot Examples
- Extended Thinking and Effort Levels
- Prompt Caching Across Sessions
- Chapter Summary
- Exercises
- Interview Questions
Chapter 8: Subagents and Multi-Agent Systems
- Why Subagents: Context Isolation and Parallelism
- Programmatic AgentDefinition
- Automatic vs. Explicit Invocation
- Subagent Inheritance and Isolation
- Detecting and Resuming Subagents
- Dynamic Workflows for Large-Scale Orchestration
- Common Multi-Agent Patterns
- Chapter Summary
- Exercises
- Interview Questions
Chapter 9: Hooks and Human-in-the-Loop Patterns
- Hook Architecture and Execution Pipeline
- Lifecycle Events Reference
- Matcher Patterns and Filtering
- Blocking and Transforming Tool Calls
- Human Approval Workflows
- Async Hooks for Observability
- Anti-Patterns: Hook Pitfalls
- Chapter Summary
- Exercises
- Interview Questions
Chapter 10: Structured Outputs and Data Extraction
- Why Structured Outputs Matter
- Defining Output Schemas
- Multi-Tool Structured Extraction
- Error Handling for Schema Validation
- Best Practices and Anti-Patterns
- Chapter Summary
- Exercises
- Interview Questions
Chapter 11: Testing, Debugging, and Evaluation
- The Challenge of Testing Agents
- Unit Testing Tools and Hooks
- Promptfoo Integration
- MLflow Tracing and Evaluation
- Debugging Strategies
- Building Evaluation Datasets
- Continuous Evaluation in CI/CD
- Chapter Summary
- Exercises
- Interview Questions
Chapter 12: Observability and Performance Optimization
- The Three Signals: Metrics, Traces, Logs
- OpenTelemetry Integration
- Cost Tracking and Budget Management
- Performance Optimization Strategies
- Prompt Caching for Cost Reduction
- Observability Tooling Comparison
- Redacting PII and Secrets from Telemetry
- Chapter Summary
- Exercises
- Interview Questions
Chapter 13: Security and Sandboxing
- The Agent Threat Model
- Built-In Security Features
- Sandbox Runtime: bubblewrap and sandbox-exec
- Container Isolation Strategies
- Credential Management
- Filesystem Security
- Network Security
- Defense in Depth Checklist
- Chapter Summary
- Exercises
- Interview Questions
Chapter 14: Deployment, Scaling, and Production Operations
- Hosting Patterns
- Container Providers
- Session Persistence in Production
- Scaling Strategies
- Multi-Tenant Isolation
- Monitoring and Alerting in Production
- Known Limitations and Workarounds
- Chapter Summary
- Exercises
- Interview Questions
Chapter 15: Real-World Case Studies and Enterprise Architecture
- Case Study: Automated Code Review Pipeline
- Case Study: RAG-Powered Customer Support Agent
- Case Study: Research Assistant with Parallel Subagents
- Enterprise Integration Patterns
- Managed Agents vs. Self-Hosted SDK
- Comparison with Alternative Frameworks
- The Future of Agent Development
- Chapter Summary
- Exercises
- Interview Questions
Conclusion: Your Agent Journey Ahead
- Key Takeaways
- Building Your First Production Agent
- The Evolving Landscape
- Resources and Community