- Preface
- Prologue: LLM Foundations for Agent Engineers
- P.1 What Is a Large Language Model?
- P.2 LLM Capabilities and Limitations
- P.3 The Context Window as a Managed Resource
- P.4 How LLMs Are Served
- P.5 From Chatbot to Agent: The Conceptual Bridge
- Part I: Foundations of Agentic AI
- Chapter 1: The Evolution from LLMs to Agent Ecosystems
- 1.1 The Limits That Forced the Leap
- 1.2 A Brief History: From Rule-Based Systems to Neural Agents
- 1.3 What Makes a System “Agentic”? A Precise Definition
- 1.4 The Agent Capability Stack: Perception, Reasoning, Memory, Action
- 1.5 Taxonomy of Agent Types
- 1.6 The 2026 Agent Landscape
- 1.7 What This Book Will Teach You: A Roadmap
- Chapter 2: The Core Agentic Loop
- 2.1 The OODA Model Applied to Agents
- 2.2 The Perceive–Reason–Act–Reflect Cycle in Detail
- 2.3 Single-Step vs. Multi-Step vs. Long-Horizon Tasks
- 2.4 The Role of the LLM Inside the Loop
- 2.5 Termination Conditions: When Does the Loop Stop?
- 2.6 Loop Failures: Infinite Loops, Stuck States, and Divergence
- 2.7 Tracing a Full Loop Execution End to End
- Chapter 3: Prompt Engineering for Agentic Systems
- 3.1 Why Prompt Engineering Is a Systems Engineering Discipline
- 3.2 System Prompts vs. User Prompts vs. Tool Results
- 3.3 Instruction Design: Clarity, Constraints, and Output Formatting
- 3.4 Chain-of-Thought, ReAct, and Scratchpad Patterns
- 3.5 Dynamic Prompt Construction: Templates, Slots, and Context Injection
- 3.6 Prompt Versioning, Testing, and Regression
- 3.7 Prompt Security: Injection Attacks and Defensive Patterns
- 3.8 Prompt Optimization at Scale: Token Budgets and Cost Control
- Chapter 1: The Evolution from LLMs to Agent Ecosystems
- Part II: Anatomy of an AI Agent
- Chapter 4: The Agent Runtime: Orchestrating the Core Loop
- 4.1 What Is the Agent Runtime?
- 4.2 The Execution Lifecycle
- 4.3 The Orchestrator Pattern
- 4.4 Synchronous vs. Asynchronous Execution Models
- 4.5 Error Handling, Retry Logic, and Graceful Degradation
- 4.6 Runtime Configuration
- 4.7 The Runtime as a Platform: Extensibility Points
- Chapter 5: Perception and Input Processing
- 5.1 What Agents Perceive
- 5.2 Input Normalization and Preprocessing Pipelines
- 5.3 Multimodal Perception
- 5.4 Signal vs. Noise: Relevance Filtering at Ingestion
- 5.5 Streaming Inputs and Real-Time Perception
- 5.6 Grounding: Connecting Perceived Input to Agent Knowledge
- Chapter 6: Reasoning and Planning
- 6.1 Types of Reasoning in Agents
- 6.2 Planning Strategies: Task Decomposition and Subgoal Generation
- 6.3 ReAct: Reasoning + Acting as an Interleaved Pattern
- 6.4 Tree-of-Thought and Graph-of-Thought Planning
- 6.5 Plan Validation and Self-Correction
- 6.6 Uncertainty and Confidence Estimation in Plans
- 6.7 Long-Horizon Planning
- Chapter 7: The Action Layer: Tools and Delegation
- 7.1 What Is an Action? A Taxonomy of Agent Actions
- 7.2 Tool Calling: The Mechanism, the Protocol, the Contract
- 7.3 Delegation to Subagents
- 7.4 Side Effects, Reversibility, and Action Safety
- 7.5 Action Validation
- 7.6 Composing Actions: Sequential, Parallel, and Conditional
- 7.7 Action Logging for Observability and Replay
- Chapter 8: The State Manager: The Heart of the Agent
- 8.1 What Is Agent State?
- 8.2 Working Memory: The In-Session Scratchpad
- 8.3 Context Window Management: Filling, Pruning, Summarizing
- 8.4 Goal Stack and Subgoal Tracking
- 8.5 Belief State
- 8.6 State Serialization and Checkpointing
- 8.7 State Transitions and the State Machine Model
- Chapter 9: Cognitive Architectures: The Brain of the Agent
- 9.1 What Is a Cognitive Architecture?
- 9.2 Classical Cognitive Architectures: SOAR, ACT-R
- 9.3 The BDI Model: Beliefs, Desires, Intentions
- 9.4 The ReAct Architecture and Its Descendants
- 9.5 The Reflexion Architecture
- 9.6 The LATS Architecture: Language Agent Tree Search
- 9.7 Cognitive Architecture Selection: Trade-offs and Decision Criteria
- Chapter 4: The Agent Runtime: Orchestrating the Core Loop
- Part III: Memory Architecture
- Chapter 10: The Taxonomy of Agent Memory
- 10.1 Why Memory Is the Defining Feature of Intelligent Agents
- 10.2 The Memory Taxonomy: Five Types
- 10.3 In-Context Memory vs. External Memory
- 10.4 Procedural Memory: Knowing How to Do Things
- 10.5 Memory as a First-Class Architectural Component
- 10.6 The Memory Lifecycle: Write, Store, Retrieve, Expire
- Chapter 11: Vector Memory, Knowledge Graphs, and Hybrid Retrieval
- 11.1 Embeddings: Turning Meaning into Numbers
- 11.2 Similarity Search: Cosine, Dot Product, and Euclidean Distance
- 11.3 Vector Databases: Architecture, Indexing, and Query Patterns
- 11.4 Knowledge Graphs: Nodes, Edges, and Relational Memory
- 11.5 Hybrid Retrieval: Combining Vector Search, Keyword, and Graph
- 11.6 Retrieval Quality: Precision, Recall, and Relevance Ranking
- 11.7 Production Vector Databases: Pinecone, Weaviate, Qdrant, and pgvector
- Chapter 12: Architecting Memory: Consolidation, Pruning, and Long-Term Persistence
- 12.1 The Memory Consolidation Problem
- 12.2 Summarisation-Based Consolidation Strategies
- 12.3 Importance Scoring: What Deserves to Be Kept
- 12.4 Forgetting by Design: Pruning Strategies and TTL Policies
- 12.5 Long-Term Persistence: Tiered Storage Architecture
- 12.6 Memory Consistency: Avoiding Conflicting Beliefs Across Stores
- 12.7 Memory Audit and Inspection
- Chapter 13: Memory as the Foundation for Statefulness
- 13.1 Stateless vs. Stateful Agents: The Architectural Divide
- 13.2 Session State vs. Cross-Session Persistence
- 13.3 User Modelling: Building a Persistent Model of the User
- 13.4 Task Continuity: Resuming Long-Running Tasks Across Interruptions
- 13.5 Shared Memory in Multi-Agent Systems
- 13.6 Memory Synchronisation and Conflict Resolution
- Chapter 14: Advanced Memory Dynamics
- 14.1 Associative Memory and Spreading Activation
- 14.2 Memory Compression: Hierarchical Summarisation Trees
- 14.3 Prospective Memory: Scheduling Future Recalls
- 14.4 Memory-Augmented Reasoning
- 14.5 Memory as an Attack Surface: Security and Poisoning Risks
- 14.6 Evaluating Memory System Quality
- Chapter 10: The Taxonomy of Agent Memory
- Part IV: Agent Architecture Patterns
- Chapter 15: Single-Agent Patterns
- 15.1 Why Single-Agent Should Be the Default
- 15.2 A Taxonomy of Single-Agent Patterns
- 15.3 The Direct Tool-Using Agent
- 15.4 The ReAct Single Agent
- 15.5 The Planner–Executor Single Agent
- 15.6 The Reflective Single Agent
- 15.7 The Control Envelope for Single Agents
- 15.8 Graduation Signals: When One Agent Stops Being Enough
- 15.9 Chapter Summary
- Chapter 16: Multi-Agent Orchestration
- 16.1 Why Multi-Agent Orchestration Exists
- 16.2 A Taxonomy of Orchestration Patterns
- 16.3 The Supervisor–Worker Pattern
- 16.4 The Manager–Specialist Pattern
- 16.5 The Pipeline and Handoff Patterns
- 16.6 Shared State and the Blackboard Pattern
- 16.7 Hierarchical Orchestration
- 16.8 Coordination Contracts, Observability, and Failure Handling
- 16.9 When Orchestration Is the Wrong Choice
- 16.10 Chapter Summary
- Chapter 17: Human-in-the-Loop as a First-Class Pattern
- 17.1 Why Human Participation Is an Architectural Choice
- 17.2 A Taxonomy of Human-in-the-Loop Patterns
- 17.3 Pre-Action Approval and Gated Autonomy
- 17.4 Post-Generation Review and Release Control
- 17.5 Exception-Only Escalation
- 17.6 Mixed-Initiative Systems
- 17.7 Designing the Human Control Surface
- 17.8 Failure Modes of Human-in-the-Loop Systems
- 17.9 From Human-in-the-Loop to Human-on-the-Loop
- 17.10 Chapter Summary
- Chapter 18: Emergent Behaviors in Decentralized Networks
- 18.1 Why Decentralized Patterns Exist
- 18.2 A Taxonomy of Decentralized Coordination
- 18.3 Peer-to-Peer Delegation Networks
- 18.4 Stigmergic Coordination and Shared Environmental Signals
- 18.5 Market-Based and Incentive-Driven Coordination
- 18.6 Swarm Systems and Local Rules
- 18.7 Federation of Autonomous Agents
- 18.8 Emergence, Failure Modes, and Control Limits
- 18.9 When Decentralization Is the Right Pattern
- 18.10 The Protocol Imperative
- 18.11 Chapter Summary
- Chapter 15: Single-Agent Patterns
- Part V: Agent Communication Protocols
- Chapter 19: The Protocol Imperative
- 19.1 The Integration Problem at Scale
- 19.2 What a Protocol Actually Is
- 19.3 The Three-Layer Communication Model
- 19.4 Protocol Design Dimensions
- 19.5 Security, Trust, and Authorization at the Protocol Layer
- 19.6 From Protocols to Interoperability: The Architectural Payoff
- Chapter 20: Layer 1 — Tool Access: The Model Context Protocol
- 20.1 Why a Dedicated Tool Protocol
- 20.2 Architecture: Hosts, Clients, and Servers
- 20.3 The Transport Layer
- 20.4 The Connection Lifecycle
- 20.5 Server Primitives: Tools, Resources, and Prompts
- 20.6 Client Primitives: Sampling, Roots, and Elicitation
- 20.7 Security and Authorization
- 20.8 Production Considerations
- Chapter 21: Layer 2 — Agent Collaboration: A2A and ANP
- 21.1 What Layer 2 Collaboration Actually Requires
- 21.2 A2A: The Agent2Agent Protocol
- 21.3 ACP: Historical Context and Contribution to A2A
- 21.4 ANP: The Agent Network Protocol
- 21.5 Protocol Positioning: A Decision Framework
- 21.6 Security Across Layer 2
- Chapter 22: Layer 3 — The Agent Web
- 22.1 From Closed Ecosystems to an Open Agent Web
- 22.2 Agent Discovery at Scale
- 22.3 Trust Infrastructure for Open Networks
- 22.4 Agent Gateways: The Policy Enforcement Point
- 22.5 Governance: The Gap Between Deployment and Control
- 22.6 Assembling the Full Protocol Stack
- Chapter 19: The Protocol Imperative
- Part VI: The Framework Landscape (2026)
- Chapter 23: A Taxonomy of Modern Frameworks
- 23.1 Why Framework Selection Is an Engineering Decision
- 23.2 Five Framework Categories
- 23.3 The Evaluation Rubric
- 23.4 The 2026 Framework Landscape: A Structured Map
- Chapter 24: Deep Dive — LangGraph and Graph-Based Execution
- 24.1 Architecture Overview
- 24.2 State Management
- 24.3 Multi-Agent Coordination
- 24.4 Human-in-the-Loop
- 24.5 Tool and Protocol Integration
- 24.6 Developer Ergonomics
- 24.7 Production Suitability
- 24.8 Failure Modes and Limitations
- 24.9 Annotated Walkthrough: A Durable Research Agent
- Chapter 25: Deep Dive: Microsoft Agent Framework
- 25.1 The Two-Layer Architecture and Why It Exists
- 25.2 The Capability Layer: Agents and the Kernel
- 25.3 The Execution Layer: Workflows and Orchestration Patterns
- 25.4 State Management and Human-in-the-Loop
- 25.5 Azure AI Foundry and Production Deployment
- 25.6 Rubric Evaluation
- 25.7 When MAF Is Not the Right Choice
- Chapter 26: Deep Dive: Google Agent Development Kit
- 26.1 The Three-Category Model: Engineering Consequences
- 26.2 LlmAgent: The Intelligence Layer
- 26.3 Workflow Agents: The Topology Layer
- 26.4 State Management and Session Services
- 26.5 Protocol Integration and Polyglot Support
- 26.6 Deployment: Vertex AI Agent Engine and Self-Hosted
- 26.7 Rubric Evaluation
- 26.8 When ADK Is Not the Right Choice
- Chapter 27: Deep Dive: OpenAI Agents SDK
- 27.1 The Design Philosophy: Intentional Minimalism
- 27.2 The Three Primitives
- 27.3 Guardrails: First-Class Safety Primitives
- 27.4 Sessions, State, and Memory
- 27.5 MCP, Protocol Integration, and Tracing
- 27.6 The SDK vs. Graph-Based Frameworks: An Honest Comparison
- 27.7 Rubric Evaluation
- 27.8 When the OpenAI Agents SDK Is Not the Right Choice
- Chapter 28: Deep Dive: Protocol-Native Frameworks
- 28.1 The Protocol Boundary Category: What It Means
- 28.2 FastMCP: Architecture and Production Model
- 28.3 FastMCP: Production Features
- 28.4 FastMCP: Rubric Evaluation
- 28.5 FastMCP: When It Is and Is Not the Right Choice
- 28.6 The A2A SDK: Architecture and Task Lifecycle
- 28.7 A2A SDK: Rubric Evaluation
- 28.8 A2A SDK: When It Is and Is Not the Right Choice
- Chapter 29: Additional Frameworks: CrewAI, Pydantic AI, and Mastra
- 29.1 CrewAI: Architectural Identity
- 29.2 CrewAI: Flows, Crews, and Production Primitives
- 29.3 CrewAI: Rubric Evaluation and Fit
- 29.4 Pydantic AI: Architectural Identity
- 29.5 Pydantic AI: Core Primitives and Production Features
- 29.6 Pydantic AI: Rubric Evaluation and Fit
- 29.7 Mastra: Architectural Identity
- 29.8 Mastra: Core Primitives and Production Architecture
- 29.9 Mastra: Rubric Evaluation and Fit
- Chapter 30: Cross-Framework Orchestration via MCP and A2A
- 30.1 The Protocol Layering Model
- 30.2 Integration Pattern 1: Any Agent Consuming MCP Tools
- 30.3 Integration Pattern 2: Exposing Any Agent as an A2A Service
- 30.4 Integration Pattern 3: A2A Client — Agent Discovery and Delegation
- 30.5 A Complete Cross-Framework Architecture
- 30.6 When to Add a Protocol Boundary—and When Not To
- Chapter 31: Framework Comparison Matrix
- 31.1 How to Read This Matrix
- 31.2 The Master Rubric Matrix
- 31.3 Selection Scenarios
- 31.4 Composition: When One Framework Is Not Enough
- 31.5 Chapter Summary
- Chapter 23: A Taxonomy of Modern Frameworks
- Part VII: Tooling and Integration
- Chapter 32: The Tool Abstraction Layer and MCP Integration
- 32.1 Why Tools Need an Abstraction Layer
- 32.2 Anatomy of a Tool Contract
- 32.3 Tool Registration and Discovery
- 32.4 MCP as the Wiring Standard: From Protocol to Implementation
- 32.5 The Tool Execution Lifecycle
- 32.6 Error Handling and Fallback Strategies
- 32.7 Security Boundaries at the Tool Layer
- 32.8 Testing and Mocking Tool Integrations
- Chapter 33: Integrating with Enterprise Systems
- 33.1 The Enterprise Integration Landscape
- 33.2 Authentication and Secrets Management
- 33.3 Connecting to REST and GraphQL APIs
- 33.4 Database Access as a Tool
- 33.5 Message Queues and Event Buses
- 33.6 SaaS Platform Integration
- 33.7 Data Governance, Residency, and Compliance
- 33.8 Connection Management and Operational Reliability
- Chapter 34: Advanced Tool Patterns
- 34.1 Parallel Tool Execution: Fan-Out and Fan-In
- 34.2 Dynamic Tool Selection at Scale
- 34.3 Tool Chaining and Data Flow Safety
- 34.4 Long-Running and Asynchronous Tools
- 34.5 Tool Middleware: Cross-Cutting Concerns
- 34.6 Tool Versioning and Schema Evolution
- Chapter 35: RAG Pipelines and Multi-Agent Retrieval
- 35.1 RAG as a Tool Pipeline
- 35.2 Query Transformation
- 35.3 Chunking and Indexing Strategy
- 35.4 Retrieval Strategies: Dense, Sparse, and Hybrid
- 35.5 Reranking
- 35.6 Context Assembly and Prompt Injection
- 35.7 Agentic RAG and Adaptive Retrieval
- 35.8 Embedding Model Selection
- 35.9 Multi-Agent Retrieval Patterns
- 35.10 RAG Quality Measurement
- 35.11 Part 7 Synthesis: The Complete Integration Stack
- Chapter 32: The Tool Abstraction Layer and MCP Integration
- Appendices
- Protocol Specification Cheat Sheet
- Three-Protocol Overview
- MCP — Model Context Protocol
- A2A — Agent-to-Agent Protocol
- ANP — Agent Network Protocol
- Framework Comparison Matrix (2026 Edition)
- Framework Legend
- Core Capabilities (Part 1 — Orchestration Frameworks)
- Core Capabilities (Part 2 — Specialised & Protocol Frameworks)
- Protocol Integration
- Deployment Characteristics (Part 1 — Orchestration Frameworks)
- Deployment Characteristics (Part 2 — Specialised & Protocol Frameworks)
- Developer Experience
- Trade-offs Summary
- Protocol Specification Cheat Sheet
- Glossary of Agentic AI Terms
- Index
Architecting AI Agent Systems
Foundations, Memory, Patterns, Protocols and Frameworks
Move beyond AI agent tutorials and understand how autonomous AI systems are actually engineered.
Architecting AI Agent Systems, Volume 1 delivers a rigorous, production-oriented architectural reference covering agent design, reasoning, memory, multi-agent orchestration, communication protocols, and the evolving framework landscape. Discover not just how agent systems work, but why they are designed that way, where they fail, and what it takes to build them right.
Minimum price
$39.99
$54.49
You pay
Author earns
Buying multiple copies for your team? See below for a discount!
About
About the Book
The engineering reference the AI agent field has been missing.
In 2024 and 2025, the community produced a flood of AI agent tutorials. Almost none of it answered the questions that matter in production: Why is the system designed this way? What fails — and why? What does this architectural decision cost at scale?
Architecting AI Agent Systems, Volume 1 closes that gap. Written for software engineers and architects, this is a precision-engineered, production-oriented reference—not a tutorial collection.
It builds the complete architectural foundation of autonomous AI systems: from LLM fundamentals to agent anatomy, multi-agent orchestration, the MCP/A2A/ANP protocol stack, the 2026 framework landscape, and the integration stack.
By the final chapter, you hold a battle-tested mental model of how agent systems are designed.
Volume 2 takes every pattern specified here and implements it in production Java.
What this book covers — 815 pages, 35 chapters, 7 parts: Prologue — LLM Foundations: LLMs as stateless functions, token economics, context window management as a resource, and the conceptual bridge to autonomous agency.
Part I — Foundations of Agentic AI: Agentic systems defined, the OODA-inspired loop, loop failure modes (infinite loops, divergence), and prompt engineering as a systems discipline with injection defense and regression testing.
Part II — Anatomy of an AI Agent: The agent runtime, perception pipelines, reasoning architectures (ReAct, Tree-of-Thought, LATS, Reflexion, BDI), tool calling contracts, and cognitive architecture trade-offs.
Part III — Memory Architecture: The five-type memory taxonomy, vector databases (Pinecone, Qdrant, pgvector), knowledge graphs, hybrid retrieval, memory consolidation, and security attack surfaces.
Part IV — Multi-Agent Orchestration: Supervisor–Worker, Manager–Specialist, Pipeline, Blackboard, Hierarchical patterns, peer-to-peer delegation, and human-in-the-loop (HITL) as an architectural decision.
Part V — Communication Protocols: The three-layer stack: MCP (Model Context Protocol) for tool access; A2A (Agent-to-Agent) for collaboration; and ANP (Agent Network Protocol) for the open agent web via W3C DIDs and DIDComm v2.
Part VI — The 2026 Framework Landscape: Evaluations of LangGraph, Microsoft Agent Framework, Google ADK, OpenAI Agents SDK, FastMCP, CrewAI, PydanticAI, and Mastra—assessed against production rubrics.
Part VII — Tooling & Integration: Tool abstraction, enterprise integration (REST, GraphQL, queues), advanced patterns (parallel fan-out, async tools), and agentic RAG pipelines with hybrid search and reranking.
Who this book is for:
Software engineers building production AI systems who need depth beyond API documentation.
Architects making framework and protocol decisions.
Technical leads evaluating MCP, A2A, and ANP for enterprise adoption. Senior engineers moving from RAG to autonomous architectures.
What sets this apart:
Structured Reference: Every chapter opens with precise learning objectives and closes with hard engineering takeaways.
Honest Evaluations: Framework reviews cover failure modes and "when not to use" rather than "Hello World" marketing.
Specification-Grade: Protocol coverage (MCP, A2A, ANP) is treated with the rigor of engineering contracts, including security and lifecycle detail.
For every engineer who asked why it works before asking how to use it.
Team Discounts
Team Discounts
Get a team discount on this book!
Up to 3 members
- Minimum price
- $99.00
- Suggested price
- $136
Up to 5 members
- Minimum price
- $159
- Suggested price
- $217
Up to 10 members
- Minimum price
- $279
- Suggested price
- $381
Up to 15 members
- Minimum price
- $399
- Suggested price
- $544
Up to 25 members
- Minimum price
- $599
- Suggested price
- $817
Author
About the Author
Haythem is a software engineering practitioner interested in the architecture and engineering of intelligent, reliable AI systems. His interests span cognitive architectures, agentic AI, software design, and practical Java development. He is particularly interested in understanding how ideas from cognitive science and AI research can be translated into explicit software components, decision processes, memory systems, and dependable execution workflows. His approach emphasizes conceptual clarity, careful analysis of research, sound architectural boundaries, and implementation that can be examined and tested. He is motivated by the challenge of moving beyond simple AI demonstrations toward a deeper understanding of how capable, stateful, and reliable intelligent systems can be designed.
Contents
Table of Contents
Get the free sample chapters
Click the buttons to get the free sample in PDF or EPUB, or read the sample online here
Also by the Author
Also by the Author
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.)
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.