A Complete Guide from Fundamentals to Production-Ready Systems
Introduction: The Agent Paradigm
- What Is an AI Agent?
- Why the OpenAI Agents SDK?
- Core Primitives at a Glance
- How to Use This Book
Chapter 1: Getting Started with the Agents SDK
- Installation and Environment Setup
- Your First Agent
- Understanding the Runner
- The RunResult Object
Chapter 2: Agent Configuration and Prompt Engineering
- Defining an Agent
- Dynamic Instructions
- Model Selection and Configuration
- Structured Outputs with Pydantic
- Prompt Templates and Platform Prompts
Chapter 3: Building Tools for Your Agents
- Function Tools with @function_tool
- Advanced Function Tool Patterns
- Hosted OpenAI Tools
- Tool Namespaces and Deferred Loading
- Local Runtime Tools
Chapter 4: Running Agents and Managing State
- The Agent Loop Explained
- Manual Conversation Management
- Session Memory
- Server-Managed Conversations
- Streaming Events and Cancellation
- Error Handling and Recovery
Chapter 5: Context Management and Dependency Injection
- The Context Pattern
- Passing Context Through Tools
- Dynamic Instructions from Context
- Lifecycle Hooks
- Usage Tracking and Token Accounting
- Cloning and Copying Agents
- Tool Input for Nested Agent Runs
Chapter 6: Multi-Agent Systems with Handoffs
- The Handoff Pattern Explained
- Configuring Handoffs
- Structured Handoff Data
- Input Filters and History Management
- Manager Pattern (Agents as Tools)
- Handoff Prompt Engineering
- Multi-Level Delegation
Chapter 7: Guardrails and Safety Controls
- Input Guardrails
- Output Guardrails
- Tool Guardrails
- Building Practical Guardrails
- Guardrails in Multi-Agent Workflows
Chapter 8: Observability and Tracing
- Automatic Tracing
- The Trace Dashboard
- Custom Spans and Manual Traces
- Sensitive Data Controls
- Third-Party Integrations
- Flushing Traces
- Non-OpenAI Tracing
Chapter 9: Human-in-the-Loop and Approval Workflows
- The Approval Flow
- Approving and Rejecting Tool Calls
- Streaming with Approvals
- Durable State Serialization
- Building Interactive Approval Interfaces
Chapter 10: Advanced Multi-Agent Orchestration
- Agents as Tools Deep Dive
- Structured Input for Tool Agents
- Custom Output Extraction
- Streaming Nested Agent Runs
- Conditional Tool Enabling
- Complex Orchestration Topologies
Chapter 11: Model Context Protocol (MCP) Integration
- What Is MCP?
- Local MCP Servers
- Hosted MCP Tools
- MCP and Tool Search
- Practical MCP Integration Patterns
- Agent-Level MCP Configuration
Chapter 12: Production Deployment and Best Practices
- Performance Optimization
- Cost Management
- Security Best Practices
- Testing Strategies
- Deployment Architectures
- Real-World Case Study: Customer Service Bot
Conclusion: The Future of Agentic AI
- Key Takeaways
- Emerging Capabilities
- Your Next Steps