Leanpub Header

Skip to main content

Building AI Agents with the Claude Agent SDK

From Fundamentals to Production Deployments

This book is 100% completeLast updated on 2026-07-08

Build AI agents that do more than generate text. This book shows you how to use the Claude Agent SDK to create autonomous systems that use tools, manage context, coordinate multiple agents, and solve complex tasks. With practical examples in Python and TypeScript, you will learn how to build secure, scalable agents ready for production.

Minimum price

$19.00

$29.00

You pay

Author earns

$

Also available for 1 book credit with a Reader Membership

PDF
EPUB
WEB
APP
About

About

About the Book

The Claude Agent SDK transforms Anthropic's Claude Code agent harness into a programmable library, giving developers access to the same autonomous tool execution, context management, and multi-agent orchestration that powers one of the most capable AI coding tools in existence. This book takes you from the fundamentals of AI agent architecture through advanced production patterns, with complete code examples in both Python and TypeScript. Whether you are building internal developer tools, customer-facing automation, or enterprise-grade multi-agent systems, you will learn the design patterns, security practices, and operational strategies that separate prototypes from production.

Share this book

Author

About the Author

Steve T. Publications

Steve T. is a cybersecurity leader, researcher, and engineer with more than 20 years of experience across application security, infrastructure security, vulnerability management, software development, and secure engineering practices. Having built his career alongside the growth of the modern internet, he has worked through multiple generations of technology, evolving security threats, and changing development methodologies.

He is currently part of the advanced research organization at a leading cybersecurity company, where he focuses on emerging threats, security innovation, and the practical application of research. His work involves investigating new attack techniques, evaluating emerging technologies, conducting deep technical analysis, and helping organizations better understand and manage complex security risks.

In addition to his research responsibilities, Steve leads a team of senior engineers and subject matter experts who create technical books, training programs, and educational resources for security professionals. Through this work, he helps engineers, developers, architects, and security practitioners strengthen their skills and build more secure systems.

Steve's technical expertise spans software development, reverse engineering, web application security, penetration testing, security architecture, incident response, vulnerability research, operating system internals, and secure software development. His ability to analyze systems at both the source code and binary levels enables him to bridge the worlds of software engineering, security research, and practical defense.

Over the course of his career, Steve has worked with organizations across a wide range of industries, helping them identify, assess, and remediate security weaknesses in critical applications and infrastructure. He is recognized for combining deep technical expertise with a pragmatic approach to security, focusing on solutions that are effective, sustainable, and aligned with business goals.

Through his work in research, engineering, leadership, and education, Steve continues to contribute to the advancement of cybersecurity and the development of secure, resilient technology systems.

Contents

Table of Contents

From Fundamentals to Production Deployments

Introduction: The Agent Revolution

  1. What Are AI Agents and Why They Matter
  2. From Claude Code CLI to Agent SDK
  3. What You Will Build
  4. How to Read This Book

Chapter 1: AI Agent Fundamentals

  1. The Anatomy of an AI Agent
  2. Tool Use and Function Calling
  3. The Agent Loop
  4. Memory Architectures for Agents
  5. Planning and Reasoning Patterns
  6. Agent vs. Workflow: When to Use Each
  7. Chapter Summary
  8. Exercises
  9. Interview Questions

Chapter 2: SDK Architecture and Environment Setup

  1. The SDK Stack: Client SDK vs. Agent SDK
  2. Installation and Authentication
  3. Project Configuration and CLAUDE.md
  4. The Subprocess Model
  5. Multi-Language Support: Python and TypeScript
  6. Chapter Summary
  7. Exercises
  8. Interview Questions

Chapter 3: Core APIs and the Agent Loop

  1. The query() Function
  2. ClaudeSDKClient for Multi-Turn Conversations
  3. Message Types and Lifecycle
  4. Turn Management and Budget Controls
  5. Session Persistence and Resumption
  6. The Agent Loop in Action: First Complete Example
  7. Chapter Summary
  8. Exercises
  9. Interview Questions

Chapter 4: Built-In Tools and Tool Use

  1. File Operations: Read, Write, Edit
  2. Search and Discovery: Glob, Grep
  3. Command Execution: Bash and Monitor
  4. Web Tools: WebSearch and WebFetch
  5. User Interaction: AskUserQuestion
  6. Permission Modes and Tool Access Control
  7. Parallel vs. Sequential Tool Execution
  8. Chapter Summary
  9. Exercises
  10. Interview Questions

Chapter 5: Custom Tools and MCP Integration

  1. Defining Custom Tools in-Process
  2. Tool Result Formats
  3. MCP Server Integration
  4. Tool Search and Context Optimization
  5. Building a Complete Custom Tool: Weather Service Example
  6. Chapter Summary
  7. Exercises
  8. Interview Questions

Chapter 6: Memory Systems and Context Management

  1. The Context Window: Sizes, Limits, and Budgets
  2. Automatic Context Compaction
  3. CLAUDE.md: Project-Level Memory
  4. The Memory Tool
  5. Retrieval-Augmented Generation with Agents
  6. Context Optimization Strategies
  7. Chapter Summary
  8. Exercises
  9. Interview Questions

Chapter 7: Prompt Engineering for Agents

  1. System Prompts vs. User Prompts in Agent Context
  2. Writing Effective Agent System Prompts
  3. CLAUDE.md Mastery
  4. XML Structuring and Few-Shot Examples
  5. Extended Thinking and Effort Levels
  6. Prompt Caching Across Sessions
  7. Chapter Summary
  8. Exercises
  9. Interview Questions

Chapter 8: Subagents and Multi-Agent Systems

  1. Why Subagents: Context Isolation and Parallelism
  2. Programmatic AgentDefinition
  3. Automatic vs. Explicit Invocation
  4. Subagent Inheritance and Isolation
  5. Detecting and Resuming Subagents
  6. Dynamic Workflows for Large-Scale Orchestration
  7. Common Multi-Agent Patterns
  8. Chapter Summary
  9. Exercises
  10. Interview Questions

Chapter 9: Hooks and Human-in-the-Loop Patterns

  1. Hook Architecture and Execution Pipeline
  2. Lifecycle Events Reference
  3. Matcher Patterns and Filtering
  4. Blocking and Transforming Tool Calls
  5. Human Approval Workflows
  6. Async Hooks for Observability
  7. Anti-Patterns: Hook Pitfalls
  8. Chapter Summary
  9. Exercises
  10. Interview Questions

Chapter 10: Structured Outputs and Data Extraction

  1. Why Structured Outputs Matter
  2. Defining Output Schemas
  3. Multi-Tool Structured Extraction
  4. Error Handling for Schema Validation
  5. Best Practices and Anti-Patterns
  6. Chapter Summary
  7. Exercises
  8. Interview Questions

Chapter 11: Testing, Debugging, and Evaluation

  1. The Challenge of Testing Agents
  2. Unit Testing Tools and Hooks
  3. Promptfoo Integration
  4. MLflow Tracing and Evaluation
  5. Debugging Strategies
  6. Building Evaluation Datasets
  7. Continuous Evaluation in CI/CD
  8. Chapter Summary
  9. Exercises
  10. Interview Questions

Chapter 12: Observability and Performance Optimization

  1. The Three Signals: Metrics, Traces, Logs
  2. OpenTelemetry Integration
  3. Cost Tracking and Budget Management
  4. Performance Optimization Strategies
  5. Prompt Caching for Cost Reduction
  6. Observability Tooling Comparison
  7. Redacting PII and Secrets from Telemetry
  8. Chapter Summary
  9. Exercises
  10. Interview Questions

Chapter 13: Security and Sandboxing

  1. The Agent Threat Model
  2. Built-In Security Features
  3. Sandbox Runtime: bubblewrap and sandbox-exec
  4. Container Isolation Strategies
  5. Credential Management
  6. Filesystem Security
  7. Network Security
  8. Defense in Depth Checklist
  9. Chapter Summary
  10. Exercises
  11. Interview Questions

Chapter 14: Deployment, Scaling, and Production Operations

  1. Hosting Patterns
  2. Container Providers
  3. Session Persistence in Production
  4. Scaling Strategies
  5. Multi-Tenant Isolation
  6. Monitoring and Alerting in Production
  7. Known Limitations and Workarounds
  8. Chapter Summary
  9. Exercises
  10. Interview Questions

Chapter 15: Real-World Case Studies and Enterprise Architecture

  1. Case Study: Automated Code Review Pipeline
  2. Case Study: RAG-Powered Customer Support Agent
  3. Case Study: Research Assistant with Parallel Subagents
  4. Enterprise Integration Patterns
  5. Managed Agents vs. Self-Hosted SDK
  6. Comparison with Alternative Frameworks
  7. The Future of Agent Development
  8. Chapter Summary
  9. Exercises
  10. Interview Questions

Conclusion: Your Agent Journey Ahead

  1. Key Takeaways
  2. Building Your First Production Agent
  3. The Evolving Landscape
  4. Resources and Community

References

Get the free sample chapters

Click the buttons to get the free sample in PDF or EPUB, or read the sample online here

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

In fact, authors have earned over $15 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