Keyboard shortcuts

Press ← or → to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

Part 05 — Agents

How it is used to do things.

An agent is not a model. It is a loop around a model: the model proposes an action, something executes it, the result goes back into the context, and the whole thing repeats until a stopping condition. Almost everything that makes an agent work — or fail — is in the parts that are not the model.

This part is ordered by dependency rather than fashion. The frameworks (LangChain, LangGraph) are covered last, after the primitives they wrap, so that you can evaluate them rather than memorise them.

  1. What an Agent Actually Is — the loop, the four components (policy, tools, memory, control), and the failure taxonomy.
  2. ReAct — interleaving reasoning traces with actions, the original prompt format, and why it beats chain-of-thought alone on tool tasks.
  3. Tool / Function Calling — how a chat model is constrained to emit valid JSON, the schemas, parallel calls, and the error handling that separates a demo from a product.
  4. LangChain — what the abstractions buy you, where the leaky parts are, and when a plain SDK call is the better engineering choice.
  5. LangGraph — why a directed loop with explicit state beats an implicit agent loop: checkpointing, human-in-the-loop, and deterministic control flow.
  6. Multi-Agent Patterns — supervisor, swarm, and debate; the coordination cost model; and the honest answer to “should you split this into multiple agents?” (usually no).
  7. Memory and Context Management — the context window is a budget, not a container: summarisation, retrieval-backed memory, compaction, and what to evict.
  8. MCP (Model Context Protocol) — the tool-integration standard: hosts, clients, servers, transports, and the security boundary it creates.
  9. Guardrails — why a model cannot reliably police itself, the three layers of defence (input, decision, output), and the constraint that actually holds — the lethal trifecta and Agents Rule of Two, which you check by auditing the tool list rather than the model’s behaviour.

After this part you can answer: how ReAct differs from plain prompting; what a tool schema actually constrains; when to use LangGraph instead of LangChain; and how you would stop an agent from deleting production data.

Depends on: Part 02 for the instruction-following model being looped, and Part 03 for the exploration/estimation vocabulary ReAct borrows.

Where this leads: Part 06 gives the agent knowledge it does not have to hold in its weights.