A Unified Guide to DSPy, OpenAI Agents SDK, Claude Agent SDK, Google ADK, and Beyond
- About This Book
- Copyright and Dedication
Chapter 1: Introduction: The Agent Revolution: Why Tools Change Everything
- A Tuesday Morning in September 2025
- What “Agentic AI” Actually Means (And What It Doesn’t)
- The Single Biggest Factor in Agent Success
- Why Tools Change Everything
- The Framework Landscape: Five Philosophies
- What This Book Will Do
- What This Book Won’t Do
- How to Read This Book
Chapter 2: The Anatomy of an AI Agent
- The Agent Loop: Observe, Reason, Act
- A Concrete Example: The Airline Agent
- Function Calling: The Foundational Primitive
- The Spectrum of Autonomy
- Deterministic vs. Probabilistic Control Flow
- Context Window Management: The Hidden Bottleneck
- A Composite Scenario: The Infinite Loop
- The MCP Layer: The Universal Language
- Chapter Summary
Chapter 3: Designing Tools That Agents Can Use Well
- The Anatomy of a Good Tool Definition
- Error Handling: Making Failures Informative
- Structured Outputs: When Tools Return Data, Not Just Text
- The Context Window Tax of Tool Descriptions
- Composite Scenario: The 50-Tool Agent (Context Window Overload Pattern)
- Tool Design Case Studies
- Anti-Patterns to Avoid
- Chapter Summary
Chapter 4: DSPy: Programming LLM Pipelines, Not Prompts
- The DSPy Philosophy: Signatures Over Prompts
- Building the Airline Agent: A Complete Walkthrough
- The ReAct Loop Internals: What DSPy Does Under the Hood
- Trajectory Inspection: Debugging the Agent’s Thinking
- Escalation: The File-Ticket Pattern
- Optimization: DSPy’s Secret Weapon
- Composite Scenario: Optimizing a Failing RAG Pipeline (DSPy Optimization Pattern)
- DSPy’s Design Philosophy: Why Signatures Over Prompts?
- Why DSPy’s Optimizers Work: The Mechanics of MIPROv2
- DSPy vs. Traditional Prompt Engineering: A Side-by-Side Comparison
- Debugging DSPy Agents: A Walkthrough
- DSPy in Production: Real-World Deployments
- DSPy’s Limitations: When to Avoid It
- DSPy vs. Pydantic AI: A Deeper Comparison
- When to Use DSPy (and When Not To)
- DSPy and MCP
- Inference-Time vs. Optimization-Time Trade-offs
- Chapter Summary
Chapter 5: Pydantic AI: Type-Safe Agents the Python Way
- Core Concepts: Agent as a Typed Container
- Five Execution Pathways
- Tools:
@agent.toolvs@agent.tool_plain - Dependency Injection via
RunContext - Structured Outputs with Pydantic Models
- Usage Limits and Cost Control
- Model Settings and Configuration
- Concurrency Limiting and Backpressure
- Streaming Modes: Three Levels of Visibility
- Self-Correction and Retry Budgets
- Observability: Logfire and OpenTelemetry
- Declarative Configuration: YAML Agent Specs
- Runs vs. Conversations: Message History
- Durable Execution: Surviving API Failures
- A Composite Scenario: Migrating from Flask to Pydantic AI
- Pydantic AI vs. OpenAI Agents SDK: A Deeper Comparison
- Pydantic AI vs. OpenAI Agents SDK: Guardrails Compared
- Pydantic AI’s Durable Execution: Production-Grade Reliability
- When to Use Pydantic AI (and When Not To)
- Chapter Summary
Chapter 6: Claude Agent SDK: In-Process Tools and Built-in Execution
- The
query()Function: Your Entry Point - Built-in Tools: The Complete Toolset
- Permission Modes: Controlling Autonomy
- Custom Tools: The
@toolDecorator and In-Process MCP Servers - Error Handling:
isErrorvs Exceptions - Tool Annotations: Behavioral Metadata
- Hooks: Intercepting Agent Behavior at Key Points
- Subagents: Spawning Specialized Agents from Within a Run
- Sessions and Multi-Turn Conversations
- MCP Server Integration
- Third-Party Provider Support
- SDK vs. Claude Code CLI vs. Managed Agents
- Claude Agent SDK’s In-Process MCP Servers: Why It Matters
- Claude Agent SDK’s Permission Modes: A Deep Dive
- Claude Agent SDK’s Hooks: Deterministic Control Over Probabilistic Behavior
- When to Use the Claude Agent SDK (and When Not To)
- Chapter Summary
Chapter 7: OpenAI Agents SDK: Lightweight Orchestration with Handoffs
- The Three Primitives: Agents, Handoffs, Guardrails
- Function Tools with Automatic Schema Generation
- Constraining Arguments with Pydantic Field
- Tool Timeouts and Error Handling
- Tool Context and Dependencies
- Hosted Tools: OpenAI’s Built-in Capabilities
- Tool Search for Deferred Loading
- Agents as Tools: A Second Multi-Agent Pattern
- Handoffs: The Primary Multi-Agent Pattern
- Guardrails: Input, Output, and Tool Validation
- Sandbox Agents: Isolated Execution
- Tracing and Observability
- Sessions: Persistent Memory
- MCP Server Integration
- Multi-Provider Support
- OpenAI Agents SDK’s Handoff Mechanism: How It Actually Works
- OpenAI Agents SDK vs. Pydantic AI: Runtime Overhead Comparison
- OpenAI Agents SDK’s Sandbox Agents: Security Through Isolation
- When to Use the OpenAI Agents SDK (and When Not To)
- Chapter Summary
Chapter 8: Google ADK: Graph-Based Workflows for Enterprise Scale
- Template Workflow Agents: The Foundation
- State Management: Shared State Namespace
- Custom Tools: FunctionTool and Beyond
- ADK 2.0: Graph-Based Workflows (Workflow Runtime)
- Dynamic Workflows: Code-Based Logic
- Collaborative Workflows: Coordinator Agents and Subagents
- Skills: Loading Domain Expertise on Demand
- Evaluation and Testing
- A2A Protocol: Cross-Framework Communication
- Deployment Options
- Multi-Language Support
- ADK for Android
- Google ADK’s Workflow Runtime vs. Template Agents: When to Use Which
- ADK’s Collaborative Workflows: Coordinator Agents and Subagents
- ADK’s Skills Toolset: On-Demand Domain Expertise
- Google ADK’s Multi-Language Support: Why It Matters
- When to Use Google ADK (and When Not To)
- Chapter Summary
Chapter 9: Cross-Framework Patterns: What Works Everywhere
- Pattern 1: Tool Design Principles That Are Framework-Agnostic
- Pattern 2: Error Handling Strategies: Three Levels
- Pattern 3: Observability and Tracing
- Pattern 4: Memory and Context Management
- Pattern 5: Security Considerations
- Pattern 6: Performance Optimization
- Pattern 7: The Human-in-the-Loop Spectrum
- Cross-Framework Migration: What Changes When You Switch
- Cost Comparison: Token Costs Per Framework/Model
- Community Health and Ecosystem Maturity
- Chapter Summary
Chapter 10: Productionizing Agent Systems
- Testing Strategies: A Multi-Layer Approach
- Cost Management: Seven Strategies
- Deployment Patterns
- Monitoring and Observability
- A/B Testing Agent Configurations
- Scaling Considerations
- Composite Scenario: From Prototype to 10k Daily Requests (Production Scaling Pattern)
- Security Hardening and Compliance
- CI/CD Integration for Agent Systems
- Cost/Latency Benchmarking Tables
- State Management Deep Dive
- Chapter Summary
Chapter 11: The Future of Agent Tool Use
- MCP Ecosystem Growth: What’s Certain
- Multi-Agent Collaboration Standards: What’s Emerging
- Fine-Tuning vs. Prompting for Tool Use: The Convergence
- Hardware Acceleration and Low-Latency Agents
- Speculation: What’s Next?
- The Economic Argument: When Do Agents Pay for Themselves?
- What’s Genuinely Uncertain
- Chapter Summary
Conclusion: Choosing Your Path
- The Decision Matrix: A Refined Guide
- The Pragmatic Approach: Seven Principles
- A Decision Framework: When to Use What
- The Economics of Agents
- The Framework Landscape: A Snapshot
- The Big Picture: Agents as Software Engineering
Glossary of Key Terms
Index
References
- Framework Documentation
- MCP Ecosystem
- MCP Security
- Academic Papers
- Industry Analysis and Additional Resources
