Building AI Applications with PHP
- A Practical Guide Using PapiAI, Laravel, and Symfony
Part I: Foundations
Chapter 1: The AI-Native PHP Application
- What You’ll Build
- Who This Book Is For
- What You Need
- The Anatomy of an AI Application
- Installing PapiAI
Chapter 2: Your First Agent
- The Provider
- The Agent
- The Response
- Streaming
- Swapping Providers
- Failover
Chapter 3: Tools — Giving the AI Hands
- How Tool Calling Works
- Creating Tools with Closures
- Creating Tools with PHP Attributes
- Tool Design Principles
- The Agentic Loop and maxTurns
Chapter 4: Conversations and Memory
- The Conversation Object
- Messages
- Why Context Management Matters
- Context Window Strategies
- Persisting Conversations
Chapter 5: Structured Output
- The Schema System
- Schema Types
- Constraints and Modifiers
- Validation
Chapter 6: Retrieval-Augmented Generation (RAG)
- How RAG Works
- Embeddings with PapiAI
- The Vector Store
- Building a RAG Pipeline
- RAG as a Tool
- Tuning RAG Quality
- Production Considerations
Chapter 7: Middleware
- The Middleware Interface
- Built-in Middleware
- Stacking Middleware
- Custom Middleware
Part II: Building the Laravel Project
Chapter 8: Project Setup — The Support Agent
- Scaffolding
- Configuration
- Database Setup
- The System Prompt
Chapter 9: Building the Tools
- OrderLookup
- KnowledgeBase
- InventoryCheck
- Registering Tools in the Service Provider
Chapter 10: The Chat Controller and Streaming
- The Controller
- Routes
- The Frontend
- Testing the Flow
Chapter 11: Security
- Prompt Injection
- Tool Security
- API Key Management
- Rate Limiting
- Cost Controls
Part III: Building the Symfony Project
Chapter 12: Project Setup — The Content Pipeline
- Scaffolding
- Bundle Configuration
- Database Schema
- The Article Schema
Chapter 13: The Content Generation Pipeline
- The Pipeline Orchestrator
- Async Processing with Messenger
- The Controller
- Running the Worker
Chapter 14: Performance
- Streaming
- Caching
- Model Selection
- Async Processing
- Token Optimization
- Connection Reuse
Chapter 15: Architecture Patterns
- The Agent as a Service
- Separate Concerns
- Prompt Management
- The Router Pattern
- Observability
Chapter 16: Testing AI Applications
- Testing Tools
- Testing with Mock Providers
- Testing Schemas
- Integration Tests
Chapter 17: Deployment and Production Concerns
- Environment Configuration
- Health Checks
- Monitoring
- Timeouts
- Scaling
Appendix A: Provider Reference
- Provider Capabilities Matrix
- Provider Constructor Parameters
Appendix B: Schema Reference
- Types
- Constraints
- Validation Methods
Appendix C: Middleware Reference
- RetryMiddleware
- RateLimitMiddleware
- CacheMiddleware
- LoggingMiddleware
- Custom Middleware