Module 1: Anatomy of an AI Agent

1. Introduction: the world of AI agents

Overview

This is the first capsule of Module 1 of the Building AI Agents Guide. Here you'll understand what AI agents are, why they're dominating the AI Engineering landscape in 2025-2026, and what you'll build over the next 10 modules. Agents are not glorified chatbots: they're systems that perceive their environment, reason about what to do, and act using external tools to reach goals autonomously.

Why it matters: Most resources teach "how to use create_agent" or "how to build your first agent with LangChain". That leaves you at tutorial level. This guide teaches you to build agents — from understanding the ReAct loop at the code level to designing multi-agent systems with persistent memory, MCP, testing, and production deployment. It's the difference between knowing how to use a hammer and knowing how to build a house.

Without this introductory module, the rest of the guide would be a collection of disconnected techniques. With it, every module fits into a coherent framework: what an agent is, how its cognitive architecture is designed, what types exist, and when (and when not) you should build one.


Where are we in the guide?

Context

This guide has 10 modules organized into 3 phases:

Phase 1: Agent Foundations (Modules 1-3)
├── Module 01: Anatomy of an AI Agent            ← YOU ARE HERE
├── Module 02: Tool Use Fundamentals
└── Module 03: Function Calling Patterns

Phase 2: Agent Architecture (Modules 4-7)
├── Module 04: State Machines for Agents
├── Module 05: Multi-Step Reasoning and Planning
├── Module 06: Memory Systems for Agents
└── Module 07: MCP and Advanced Tool Integration

Phase 3: Multi-Agent & Production (Modules 8-10)
├── Module 08: Multi-Agent Orchestration
├── Module 09: Testing and Evaluating Agents
└── Module 10: Agents in Production and Alternatives

Estimated total duration: 13-16 hours (self-paced).

Where are we headed?

This module gives you the full conceptual base: what an agent is, how it thinks (perceive-reason-act), what types exist, when to use them, and what the framework landscape looks like. With that base, Module 2 goes deep on tool use (the foundational capability of every agent) and Module 3 on advanced function calling patterns.

The progression is deliberate:

  1. First you understand what an agent is (this module) — without this, you build disguised chatbots
  2. Then you give it tools (module 2) — tool use is what turns an LLM into an agent
  3. You master advanced patterns (module 3) — parallel calls, routing, extraction, retry
  4. You design the architecture (module 4) — state machines with LangGraph for flow control
  5. You add reasoning (module 5) — planning, reflection, self-correction
  6. You implement memory (module 6) — persistence, checkpointing, long-term memory
  7. You connect tools at scale (module 7) — MCP (Model Context Protocol)
  8. You orchestrate multiple agents (module 8) — supervisor, handoffs, subagents
  9. You test and evaluate (module 9) — unit tests, trajectory evaluation, golden datasets
  10. You ship to production (module 10) — deployment, scaling, monitoring, cost control

Each step builds on the one before it. No jumps.


What sets apart an AI Engineer who masters agents

There are three levels in agent adoption:

Level 1: "I can create a basic agent"

agent = create_react_agent(model, tools)
result = agent.invoke({"messages": [("user", "...")]})

You copy an example from the documentation, it works, you show it in a demo. But you don't know why the agent sometimes falls into an infinite loop, why the cost explodes, or how to test it.

Level 2: "I understand how agents work"

You know what happens internally: the perceive-reason-act loop, how the model decides to call tools, what a ToolMessage is, why stop conditions matter. You can debug agents and design the right type for each problem.

Level 3: "I build agent systems for production"

You design custom state machines, implement planning and reflection, add persistent memory, connect tools via MCP, orchestrate multiple specialized agents, test with golden datasets, and deploy with monitoring and cost control.

This guide takes you from Level 1 to Level 3. Module 1 focuses on moving you from Level 1 to Level 2: from "I know how to use the API" to "I understand what's behind it and I decide with judgment". Modules 2-10 take you to Level 3.


Prerequisites

Before starting this guide you need to be comfortable with:

Technical knowledge

  • LangChain & LangGraph Guide (#9): You're comfortable with create_react_agent, @tool, StateGraph, bind_tools, messages (HumanMessage, AIMessage, ToolMessage). This guide does not re-teach the framework APIs — you already know those.
  • Advanced Prompt Engineering (#10): You're comfortable with advanced system prompts, structured outputs, chain-of-thought. Agents depend on well-designed prompts to reason and act correctly.
  • Advanced Python: async/await, decorators, type hints, Pydantic models. The code in this guide uses these features extensively.

Tools

  • Python 3.11+
  • langchain v1.2+ and langgraph v1.0+
  • OpenAI API key (or Anthropic)
  • Editor with Python support (VS Code, Cursor, PyCharm)

Quick setup

python -m venv agents-venv
source agents-venv/bin/activate  # Mac/Linux
# agents-venv\Scripts\activate   # Windows

pip install langchain langchain-openai langgraph tavily-python python-dotenv

echo "OPENAI_API_KEY=sk-..." > .env

What you'll build in this guide

Modules 1-3: standalone mini-projects

Each Phase 1 module has its own focused project:

ModuleProjectWhat it demonstrates
1ReAct agent from scratchThe fundamental loop without a framework
2Agent with 5 real toolsTool use with external APIs
3Extraction + routing systemAdvanced function calling patterns

Modules 4-10: evolving project — AI Research Agent

From Module 4 onward, you build a single project that evolves in every module:

Module 4:  Research Agent with a custom state machine
     ↓
Module 5:  + Planning and reflection
     ↓
Module 6:  + Persistent memory (cross-session)
     ↓
Module 7:  + MCP servers (filesystem, web search, papers DB)
     ↓
Module 8:  + Multi-agent system (researcher, analyst, writer, supervisor)
     ↓
Module 9:  + Complete testing and evaluation suite
     ↓
Module 10: + Production deployment with FastAPI

Final result: A production-ready multi-agent system that takes a research question and produces a structured research report, with planning, reflection, persistent memory, external tools via MCP, testing, and deployment.


Professional goal of Module 1

By the end of this module you'll be able to:

  • Formally define what an AI agent is and articulate its components: perception, reasoning, action, memory
  • Explain the cognitive architecture perceive-reason-act and how it's implemented in the ReAct loop
  • Classify agents by taxonomy: reactive, deliberative, hybrid, simple reflex vs goal-based
  • Decide with judgment when to use an agent vs a chain vs a workflow, with a decision framework you can apply at your company
  • Position the main frameworks (LangChain/LangGraph, Pydantic AI, CrewAI, AutoGen) without evangelizing any of them
  • Identify anti-patterns — when NOT to use an agent and why
  • Implement a ReAct agent manually (no framework) and compare it with create_react_agent

Module map

#CapsuleWhat you'll learn
02What an AI agent is (formal definition)Components: perception, reasoning, action, memory. Agent vs chatbot vs pipeline
03Cognitive architecture: perceive-reason-actThe fundamental loop, its relationship to the ReAct paper, step-by-step implementation
04A taxonomy of agentsReactive, deliberative, hybrid. Simple reflex vs model-based vs goal-based vs utility-based
05Agents vs chains vs workflowsDecision framework: when to use each one. Concrete trade-offs
06Framework landscape 2025-2026LangChain/LangGraph, Pydantic AI, CrewAI, AutoGen, Semantic Kernel. Philosophies and trade-offs
07When to use (and when NOT to use) agentsAnti-patterns, cost-benefit analysis, signals that you need an agent
08Project: basic ReAct agent from scratchManual implementation with the OpenAI API → reimplementation with create_react_agent

Learning flow

First you'll understand what an agent is at a formal level — not as a buzzword but as an architecture with defined components (capsule 02). Then you'll go deeper into how it thinks: the perceive-reason-act loop that underpins everything that follows (capsule 03).

With that base, you'll explore the taxonomy: not all agents are the same, and classifying them lets you design the right type for each problem (capsule 04). Next you'll learn to decide when to use an agent vs simpler alternatives — one of the most valuable skills in this module (capsule 05).

Capsules 06 and 07 give you industry context: what frameworks exist, what their philosophies are, and when an agent is the right solution (and when it's expensive over-engineering).

Finally, in the project (capsule 08) you'll implement a ReAct agent manually — just the OpenAI API, no framework — to understand exactly what happens under the hood. Then you'll reimplement it with create_react_agent and compare: what the framework abstracts away, what you gain, and what you lose.


Connection with the project

This module's project: basic ReAct agent from scratch

You'll implement the ReAct loop two ways:

  1. Manual (OpenAI API): Prompt → parse tool_calls → execute tool → append result → repeat. No framework. Just you, the API, and the loop. This forces you to understand every step.
  2. With LangChain: create_react_agent + tools. Same result, ~80% less code. But now you understand what it's doing internally.

Estimated duration: 30-45 minutes.

Connection with the evolving project

Although the evolving project (AI Research Agent) doesn't start until Module 4, the concepts in this module are foundational:

  • The cognitive architecture (perceive-reason-act) defines how the Research Agent makes decisions
  • The taxonomy helps you classify what type of agent you need for each component of the system
  • The decision framework (agent vs chain vs workflow) guides you on which parts of the Research Agent are agents and which are deterministic pipelines
  • The manual ReAct loop prepares you to design custom state machines in Module 4

What this module does NOT cover

  • LangChain APIs in detail — You already covered that in guide #9. Here we don't re-teach bind_tools, StateGraph, or framework APIs
  • Deep tool use — That's all of Module 2. Here you only use basic tools for the project
  • Function calling patterns — That's Module 3. Here you understand the concept, not the advanced patterns
  • Detailed implementation of alternative frameworks — Capsule 06 positions frameworks but isn't a tutorial on each one
  • The full history of AI agents — This isn't an academic paper. Only the theory you need to build real agents
  • RL agents (Reinforcement Learning) — This guide covers LLM-based agents, not classic RL agents

Difference from the LangChain & LangGraph Guide (#9)

It's important that you understand the difference from the start:

Guide #9 (LangChain & LangGraph):
  → "How to use the framework"
  → APIs, tools, syntax, framework patterns
  → create_react_agent, StateGraph, bind_tools, etc.

Guide #11 (Building AI Agents — this guide):
  → "How to build agents with the framework"
  → Cognitive architecture, taxonomy, agent design
  → Custom state machines, planning, reflection, multi-agent
  → MCP, testing, production deployment

The analogy: guide #9 taught you to use a hammer, a saw, and nails. This guide teaches you to build a house. Knowing how to use the tools is a prerequisite, but it isn't enough — you need to understand architecture, design, and construction patterns.


Industry context: why agents now

The shift toward agents (2024-2026)

The AI Engineering ecosystem evolved fast:

YearDominant paradigmExample
2022-2023Chatbots and promptsChatGPT, GPT-3.5
2023-2024RAG and pipelinesLangChain chains, vector DBs
2024-2025Simple agentscreate_react_agent, function calling
2025-2026Agent systemsMulti-agent, MCP, production agents

Three market signals

  1. OpenAI, Anthropic, and Google expose function calling as a core feature of their APIs. It isn't experimental — it's the main mechanism for models to interact with the world
  2. MCP (Model Context Protocol), backed by Anthropic and Microsoft, standardizes how agents connect to external tools. It's the "USB for agents"
  3. LangGraph became the reference framework for stateful agents, with production adoption at companies like Replit, Elastic, and Uber

What companies are building

Agents aren't an academic exercise. Real companies are using them in production:

  • Replit uses LangGraph agents for its code assistant, which can create, edit, and run complete projects
  • Elastic integrates agents into its Security AI Assistant, which investigates threats by querying multiple sources
  • Customer support: Companies like Klarna replaced support teams with agents that resolve tickets by querying databases, policies, and internal tools
  • Research automation: Agents that read papers, extract data, and generate reports — exactly what you'll build in this guide

The gap this guide fills

Most existing resources stop at:

  • "Your first agent with LangChain" (tutorial level)
  • "What an AI agent is" (conceptual level, no code)
  • Framework documentation (reference, not a pedagogical guide)

No resource in Spanish covers the full path: fundamentals → architecture → multi-agent → production. This guide does.


How to use this module

If you're coming from guide #9 (LangChain & LangGraph)

You already know the framework. This module gives you the "why" behind the "how". Why create_react_agent has a loop, why agents need stop conditions, why sometimes a chain is the better option.

If you have agent experience

If you've already built agents in production, capsules 02-04 can go fast. Focus on:

  • Capsule 05 (Agents vs chains vs workflows) — the decision framework
  • Capsule 07 (When NOT to use agents) — anti-patterns
  • Capsule 08 (Project) — manual implementation of the ReAct loop

If you're new to agents

Read each capsule in order. The progression is designed to build understanding gradually. Don't jump to the project without understanding the cognitive architecture (capsule 03).

Estimated time

  • Reading: ~45 minutes (capsules 02-07)
  • Project: ~30-45 minutes (capsule 08)
  • Total: ~1.3-1.6 hours

The real costs of agents

Before diving in, you should understand that agents carry costs a simple pipeline doesn't:

AspectPipeline/ChainAgent
LatencyPredictable (1-2 calls)Variable (2-15+ calls per iteration)
TokensFixed per requestCumulative (every iteration adds up)
PredictabilityHigh (deterministic flow)Low (the model chooses the path)
DebuggingSimple (A→B→C)Complex (loops, model decisions)
Cost ($)Low and predictableMedium-high and variable

This isn't meant to scare you — it's so you make informed decisions. Throughout the guide, each module helps you control these costs: stop conditions (M1), error handling (M2), retry patterns (M3), state machines (M4), and explicit cost control (M10).

The question isn't "are agents good?" but "for this problem, does an agent justify its costs?". That decision-making skill is the most valuable thing you'll take from this module.


Evidence of success

By the end of this module, you'll know you succeeded if:

  • ✅ You can explain in 30 seconds what an agent is, its components, and how it differs from a chatbot
  • ✅ You can draw the perceive-reason-act loop and explain each step precisely
  • ✅ Faced with a new problem, you decide with judgment whether it needs an agent, a chain, or a workflow — and you can justify your decision
  • ✅ You know the framework landscape and can argue pros/cons of each one without evangelizing
  • ✅ Your manual ReAct agent works with at least 2 tools and stop conditions, and you can explain what create_react_agent abstracts away
  • ✅ You can identify at least 3 agent anti-patterns and explain why they're problematic

Quick self-assessment

Ask yourself these questions after completing the module:

  1. "Can I implement a ReAct agent with no framework in under 50 lines of Python?" → If yes, you understand the fundamental loop
  2. "Can I explain why Notion chose not to use an agent for its AI writing feature?" → If yes, you understand the trade-offs
  3. "If someone asks me to compare LangChain vs Pydantic AI, can I give an honest 2-minute answer?" → If yes, you have industry context

If you answered yes to all three → you're ready for Module 2. If you answered no to any → review the corresponding capsule before moving on.


The guide's tech stack

Across the 10 modules you'll use:

Core

TechnologyVersionWhat for
Python3.11+Base language
LangChainv1.2+Agent and tool framework
LangGraphv1.0+State machines, agent loops

Agent tools

TechnologyWhat for
langchain-openaiOpenAI provider (GPT-4.1, GPT-4.1-mini)
langchain-anthropicAnthropic provider (Claude)
tavily-pythonWeb search for agents
mcp SDK v1.0+Model Context Protocol

Production

TechnologyWhat for
fastapiAPI deployment
langsmithTracing and evaluation
psycopgPostgreSQL for persistence
pydantic-aiFramework comparison

You don't need to install everything now. Each module tells you which dependencies you need.


Summary

  • This guide covers agents from conceptual fundamentals to production deployment (10 modules, 13-16 hrs)
  • Agents are the dominant paradigm in AI Engineering 2025-2026: function calling, MCP, multi-agent
  • This module establishes the conceptual base: what an agent is, how it thinks, what types exist, when to use them
  • You'll build an evolving Research Agent from Module 4 up to a production-ready multi-agent system
  • Agents have real costs (latency, tokens, complexity) — the key skill is deciding when to use them
  • Prerequisites: LangChain & LangGraph Guide (#9), Advanced Prompt Engineering (#10), advanced Python

Resources

  1. LangGraph Documentation — Official documentation for this guide's main framework
  2. LangChain Agents — Agent reference in LangChain
  3. ReAct: Synergizing Reasoning and Acting in Language Models (Paper) — The foundational paper of the ReAct loop
  4. MCP Specification — Official specification of the Model Context Protocol
  5. Building Effective Agents (Anthropic) — Anthropic's guide on agent design
  6. Pydantic AI Documentation — Alternative framework you'll compare in Module 10