Skip to content
Agent Engineering Lab

Agentic AI for Serious Engineers

A field guide to building reliable, evaluable, production-grade agent systems. It teaches you when to build an agent, when not to, and how to make the ones you build hold up in production.

19 chapters. 7 are free to read here, in full. The other 12 are in the book, each with a preview below.

Read before you buy

The six Foundations and Chapter 1 are on this site in full. Read them first, and buy only if they earn it.

Run the code

The companion repository holds working Python, evaluation harnesses and end-to-end projects for the book, under the MIT licence.

Check the evidence

The lab reports on this site test the book's ideas, and publish the repo, the data and the seed.

Contents

Read free the whole chapter is on this site. In the book open the row to see what it covers.

Start hereFoundations

Six hands-on sections that take you from zero to your first agent, connect it to tools through MCP, and draw the line around what it can safely do.

  1. 00a How LLMs Actually Work The engineer's mental model for LLMs. Not transformers math. The five things you need to know to build real systems. Read free 18 min
  2. 00b From API Calls to Tool Use How to go from sending text to having the model take actions. Function calling demystified, schema validation, and the bridge from text generator to system component. Read free 22 min
  3. 00c Your First Agent, No Framework Build a complete agent in 100 lines of Python. No framework. No magic. Every line explained, including the ones where it breaks. Read free 21 min
  4. 00d The Same Agent, With a Framework The same agent rebuilt with Google ADK and LangChain. Side-by-side comparison with eval scores. What frameworks give you, what they hide, and how to choose. Read free 15 min
  5. 00e Connecting Your Agent to MCP Build an MCP server from scratch and connect your agent to it. The standard protocol for giving AI agents access to tools, data, and services. Read free 14 min
  6. 00f The Production Boundary An LLM gets dangerous not when it speaks but when it acts. What every tool call really asks for, and the boundary that turns an agent into a system component you can trust. Read free 20 min

Part IBuild

From components to multi-agent systems.

  1. 01 What "Agentic" Actually Means What makes a system agentic? Precise definitions of LLM apps, workflows, tool-using systems, agents, and multi-agent systems for engineers. Read free 12 min
  2. 02 Tools, Context, and the Agent Loop How tool-using agents work: function calling, context window management, the agent loop, and writing a working agent without a framework. In the book

    What the chapter covers

    • An LLM primer for systems engineers. What matters for production, not theory.
    • Tools as contracts. Function calling with validation, permissions, and error handling.
    • Context engineering. System prompts, retrieval context, grounding, injection boundaries.
    • The agent loop. The observe-think-act cycle and what makes it work or fail.
    • Failure modes in this chapter's code. What breaks and why.
    • Building a working agent. A complete implementation without reaching for a framework.

    Working code: src/ch02/ on GitHub

    Get the book on Amazon Open the preview page

  3. 03 Workflow First, Agent Second Why you should reach for deterministic workflows before agents. Decision criteria, architecture comparison, and the engineering instinct that saves production systems. In the book

    What the chapter covers

    • The deterministic workflow. Building a reliable pipeline for document question answering.
    • The bounded agent. The same task with LLM-driven decision-making.
    • Same task, two ways: the comparison. Accuracy, latency, cost, and debuggability metrics.
    • Design guidance: when to choose which. Decision criteria for workflows vs agents.
    • Planning and single-agent design. State management and bounded autonomy.
    • Failure modes specific to this chapter. What breaks when you choose wrong.

    Working code: src/ch03/ on GitHub

    Get the book on Amazon Open the preview page

  4. 04 Multi-Agent Systems Without Theater When multi-agent systems are justified and when they are complexity theater. Patterns, coordination overhead, and honest cost analysis. In the book

    What the chapter covers

    • When multi-agent is justified. The specific conditions where a single agent cannot hold the task.
    • When multi-agent is theater. Recognizing unnecessary decomposition.
    • Core patterns. Orchestrator, message contracts, and agent specialization.
    • The working example. Retriever, reasoner, and verifier on the document intelligence task.
    • The comparison. Single-agent vs multi-agent on accuracy, cost, and latency.
    • Coordination overhead and cost explosion. The real price of multi-agent.
    • Failure modes. What goes wrong when agents coordinate.

    Working code: src/ch04_multiagent/ on GitHub

    Get the book on Amazon Open the preview page

Part IIJudge

Oversight, evaluation, and knowing when to stop.

  1. 05 Human-in-the-Loop as Architecture Human-in-the-loop as a first-class architectural decision. Approval gates, escalation policies, audit logging, and the Incident Runbook Agent. In the book

    What the chapter covers

    • The three primitives. Approval gates, escalation policies, audit trails.
    • Design guidance. Structuring when and how humans intervene.
    • The working example: Incident Runbook Agent. Multi-agent with human approval before remediation.
    • When HITL is security theater. Rubber-stamping vs real oversight.
    • Cost of HITL vs value of HITL. The tradeoff analysis most teams skip.
    • Building for auditability. Decision trails useful for debugging, compliance, and improvement.
    • Failure modes. What breaks in human-agent interaction.

    Working code: src/ch05_hitl/ on GitHub

    Get the book on Amazon Open the preview page

  2. 06 Evaluating and Hardening Agents How to evaluate and harden production agent systems. Metrics, adversarial testing, regression suites, and the difference between opinions and evidence. In the book

    What the chapter covers

    • Evaluation. Gold datasets, rubric scoring, failure bucketing, and regression suites.
    • Observability. Structured traces, token accounting, latency decomposition.
    • Reliability. Retries, checkpointing, crash recovery, graceful degradation.
    • Cost management. Token profiling, budget controls, architecture-level cost optimization.
    • Security. Prompt injection, tool abuse, data exfiltration, least privilege enforcement.
    • Before and after hardening. Concrete metrics showing the difference.
    • Failure modes in this chapter's code. What breaks during hardening.

    Working code: src/ch06/ on GitHub

    Get the book on Amazon Open the preview page

  3. 07 When Not to Use Agents The most important chapter: when not to use agents. Decision framework, anti-patterns, and honest retrospective on simpler alternatives. In the book

    What the chapter covers

    • The agent tax. The real cost of autonomy in latency, money, complexity, and debugging time.
    • Alternatives that are usually sufficient. When workflows, rules, retrieval, or static pipelines win.
    • A decision framework. A structured approach to the build-or-not decision.
    • Systems that should not have been agents. Real examples of over-engineering.
    • Three case studies you should memorize. Patterns that repeat across teams and industries.
    • Multi-agent anti-patterns. The most common ways teams add unnecessary coordination.
    • An honest retrospective on the Document Intelligence Agent. What actually needed agent autonomy.
    • Principles for the decision. Six principles that hold across use cases.

    Get the book on Amazon Open the preview page

Part IIIOperate

Production reality.

  1. 08 Metacognition and Self-Reflection Production patterns for agent metacognition: loop detection, quality assessment, cost-aware planning, and sycophancy defense. In the book
  2. 09 Deploying and Scaling Deploying and scaling agent systems: durable execution, observability, autoscaling, and real production failures. In the book
  3. 10 Governance and Auditability Agent governance and auditability: decision traces, compliance boundaries, risk tiers, and policy engines. In the book
  4. 11 Security Deep Dive Security deep dive for agent systems: the Lethal Trifecta, defense in depth, MCP security, and red teaming. In the book

Part IVAdvanced

Memory and protocols at scale.

  1. 12 Memory Management Memory management for production agents: session memory, long-term learning, multi-agent coordination, and memory security. In the book

    What the chapter covers

    • Session memory. Surviving the context window with importance-weighted truncation and compaction.
    • Long-term memory. Learning from corrections, avoiding repeated mistakes, two-pass retrieval.
    • Shared memory. Multi-agent coordination with scoped state stores and optimistic concurrency.
    • Production frameworks. Mem0, Zep, and Letta compared with current benchmarks.
    • Memory security. Poisoning attacks, validation, and the GDPR compliance tension.
    • Learned forgetting. When and how to retire memories that no longer serve.

    Working code: src/ch12_memory/ on GitHub

    Get the book on Amazon Open the preview page

  2. 13 Agent Protocols in Production MCP, A2A, and AIP in production: building enterprise MCP servers, cross-boundary agent collaboration, identity and delegation chains, and production pitfalls. In the book

    What the chapter covers

    • Building production MCP servers. Thin wrappers, gateways, catalogs, enterprise auth.
    • A2A across team boundaries. Agent Cards, task lifecycle, multi-turn negotiation.
    • The identity gap. Why MCP and A2A solve connectivity but not accountability.
    • AIP deep dive. Delegation chains, scope attenuation, the MCP auth proxy.
    • Complex use cases. Financial services, healthcare, supply chain.
    • Production pitfalls. Server sprawl, shadow connections, delegation debugging.
    • The adoption sequence. When to add each protocol layer.

    Get the book on Amazon Open the preview page

About the author

Sunil Prakash is an engineering leader and researcher working on enterprise AI systems, agent identity and production agent architecture. He writes the Agent Engineering Lab, where the book's ideas are argued about and tested.