AI Agents Tutorial
Learn AI Agents step by step: 39 lessons in 9 chapters with examples, quizzes, diagrams and projects.
Start learning →
of lessons completed
Getting Started
- What Is an AI Agent? Learn what an AI agent is, how it differs from a chatbot or a plain script, and the perceive, decide, act loop behind every agent, with runnable Python.
- LLMs as the Agent's Brain How a language model fits inside an agent: stateless calls, roles and messages, tokens, context windows, temperature and the limits you must design around.
- Your First Agent Loop Write a complete agent loop in plain Python: a model stand-in that picks actions, a tool dispatcher, a message history, a step limit and a readable trace.
- Agent Use Cases, Limits and When Not to Use One Decide when an AI agent is the right tool: strong use cases, honest limits, cost and reliability math, and a scoring checklist you can run in Python.
Agent Concepts and Loops
- The Perceive, Think, Act Loop (ReAct Style) Understand the core agent loop in depth: observations, thoughts, actions, the ReAct pattern, and how to build a loop that logs thoughts and recovers from bad steps.
- Agent State and Message History Manage what an agent knows: the message transcript, structured state outside the prompt, scratchpads, trimming and summarizing history, and checkpoints.
- Stop Conditions, Budgets and Loop Guards Keep agents from running away: step, token, time and cost budgets, repeated-action detection, success checks and graceful fallbacks, with runnable Python.
- Workflows versus Agents: Chaining, Routing, Parallel Compare fixed LLM workflows with free-running agents and learn the building blocks: prompt chaining, routing, parallelization and evaluator loops, in Python.
- Structured Outputs and Parsing Model Responses Make model output safe to use in code: ask for JSON, extract it from messy text, validate fields and types, and send validation errors back for repair.
Tools and Function Calling
- What Are Tools? Function Calling Basics Learn how tools give a language model hands: the function-calling flow, tool definitions, tool-use messages and results, and a runnable calling loop in Python.
- Tool Schemas with JSON Schema Describe tools so models call them correctly: names, descriptions, JSON Schema types, enums and required fields, plus a Python validator and a schema generator.
- Executing Tool Calls Safely Run model-requested tools without regret: allowlists, argument validation, permission levels, human approval, timeouts, output limits and dry runs in Python.
- Tool Errors, Retries and Fallbacks Make agents resilient when tools fail: classify errors, return readable error observations, retry with backoff, add fallbacks and circuit breakers, with Python examples.
- Designing Good Tools for Agents Learn how to design tools a model uses correctly: clear names and descriptions, narrow scope, compact outputs, helpful errors and a tool count that stays manageable.
Planning and Reasoning
- Chain-of-Thought and Reasoning Models Understand why step-by-step reasoning improves LLM answers, how reasoning models differ, when to ask for thinking, and how agents use and verify intermediate steps.
- The ReAct Pattern: Reason, Act, Observe Learn the ReAct agent pattern that interleaves reasoning with tool calls, with a runnable Python stand-in, a parser, a trace view and the common ways ReAct loops fail.
- Planning and Task Decomposition Break big goals into small, checkable steps: plans as data, dependencies and ordering, topological sorting, hierarchical plans and when planning is worth its cost.
- The Plan-and-Execute Pattern Separate planning from doing: a planner writes the steps, an executor runs them with tools, and a checker decides whether to continue. Includes a runnable Python stand-in.
- Reflection and Self-Critique Let agents review and improve their own work: generate, critique, revise loops, external verifiers, reflection memory, and the limits of self-checking, with Python demos.
- Replanning and Recovering from Failure Keep agents on track when reality changes: detect stuck loops, checkpoint progress, replan with a budget, choose alternatives and escalate to a human, with Python demos.
Memory and Retrieval
- Short-Term Memory and Context Windows Learn how an AI agent keeps its working memory inside the context window, how to count tokens, and how to trim or summarize history without losing the plot.
- Long-Term Agent Memory Give an AI agent memory that survives between sessions: episodic, semantic and procedural memory, when to write and read them, and a runnable memory store.
- Embeddings and Vector Search Understand embeddings, cosine similarity and nearest-neighbor search, then build a tiny vector index in Python to retrieve the most relevant text for an agent.
- Retrieval-Augmented Generation for Agents Learn the RAG pipeline for AI agents: chunk, embed, retrieve, rerank and answer with citations, plus agentic RAG where the agent decides when and what to search.
Multi-agent Systems
- Multi-Agent Patterns Learn when to use several AI agents instead of one, and the main patterns: pipeline, router, supervisor, debate and swarm, with runnable Python stand-ins.
- The Orchestrator-Worker Pattern Build an orchestrator agent that plans a goal, delegates tasks to specialist workers, runs them in parallel and merges the results, with runnable Python.
- Agent Handoffs and Shared State Learn how AI agents pass a conversation to each other with handoffs, share state safely through a blackboard, and avoid loops, lost context and conflicts.
Evaluation and Safety
- Evaluating Agents Learn to measure AI agents: build a test set, score outcomes and trajectories, use LLM judges carefully, run repeated trials and catch regressions with a runnable harness.
- Agent Guardrails and Prompt Injection Understand prompt injection and how to defend AI agents with layered guardrails: input and output checks, least privilege, data and instruction separation, with runnable examples.
- Human-in-the-Loop and Permissions Design approval gates for AI agents: classify actions by risk, pause for human confirmation, support edit and reject, log decisions and set autonomy levels, with runnable Python.
- Agent Observability and Tracing Make AI agents debuggable: record traces and spans for every model and tool call, track tokens, cost and latency, spot loops and replay failures with runnable Python.
Frameworks and Deployment
- The Agent Framework Landscape Compare the kinds of AI agent frameworks, what they give you, what they cost, and how to decide between building your own loop and adopting a library.
- Model Context Protocol (MCP) Learn what the Model Context Protocol is, how hosts, clients and servers exchange tools, resources and prompts over JSON-RPC, and run a tiny MCP-style server in Python.
- Structured Agent Workflows and Graphs Model an AI agent as a graph of steps with shared state, conditional edges, loops and checkpoints, and build a tiny runnable graph engine in Python.
- Deploying Agents to Production Take an AI agent from notebook to production: architecture, queues for long runs, timeouts, retries, rate limits, cost control, secrets, versioning and a launch checklist.
Projects and Practice
- Project: Research Assistant Agent Build a research assistant agent end to end: plan sub-questions, search a document set, take notes, cite sources and write a report, with runnable Python stand-ins.
- Project: Customer Support Agent Build a support agent that routes requests, answers from a knowledge base, calls order tools with approval for refunds, escalates to humans and passes an eval set.
- Project: Code Review Agent Build a code review agent: parse a diff, run static checks as tools, collect findings with severity and line numbers, filter noise and format a review comment.
- Agent Practice Challenges Practice building AI agents with hands-on challenges: fix a runaway loop, validate tool arguments, design memory, route requests and write evals, each with a solution to run.