Skip to main content
Machine Learning & AI

AI Agents Tutorial with Examples.

AI agents tutorial: autonomous agent systems with ReAct, tool-calling, memory, multi-agent orchestration and production agent patterns.

Architecture at a glance

Click any box to open the lesson that teaches it

AI agent architecture at a glance

goal → plan → act (tool call) → observe → repeat → answer

AI agent architecture at a glance An agent loops from a goal through a validated plan, a tool call, and an observation of the result, repeating until it answers. The loop draws on memory, a RAG agent's search and rerank, a token-budgeted context, and tools exposed over MCP. It scales out to several subagents in parallel and to long crash-safe runs with checkpoints. Before shipping, replies are schema-validated, evaluated on outcome and trajectory, checked for security risks, gated on human approval for destructive calls, and tried out in real projects. Goal the task Plan validatereplan Act tool_usetool_result Observe result Answer task complete repeats until done What the agent draws on Memory sliding windowlong-term store Retrieval (RAG) search againcitations Context token budgettrim results Tools (MCP) schemaserrors Multi-agent Orchestrator + subagents parallel fan-out Autonomous workflows Crash-safe runs checkpoints · idempotent reruns Build and trust Structured outputs Evaluation LLM security Human approval Projects
How it fits together (8 steps)
  1. An agent starts from a goal and a plan. The plan is parsed as data and validated before anything runs, and the agent replans when a step fails.
  2. Each step acts through a tool call — the tool_use / tool_result loop — then reads the result back as an observation, the ReAct pattern of thought, action and observation.
  3. That loop repeats until the model gives a final answer, or a step cap and a repeat check stop it, as intro.md's runaway-loop example shows.
  4. What the agent draws on: memory that survives a session, a RAG agent that rephrases and searches again until the evidence clears a relevance bar, a token-budgeted context, and tools exposed over MCP with their schemas and errors.
  5. Scaling out: an orchestrator fans work out to several subagents in parallel, and a long-running agent survives a crash through checkpoints and idempotency keys.
  6. Before it ships: replies are schema-validated, graded on outcome and trajectory over many runs, and checked against prompt injection and excessive agency.
  7. Destructive tool calls wait on a human: an agent loop over MCP tools gates deletes on approval, checked by the agent or enforced by the server through elicitation.
  8. Then build something real: the projects page runs from a calculator agent to a multi-agent debate system.

Beginner

Start here — no prior experience needed

2 lessons

Intermediate

For developers with core concepts down

3 lessons

Advanced

Production-grade patterns for experienced engineers

5 lessons

Also part of AI Agents

Taught in other topics. Each link opens the lesson in its home topic.

7 lessons
llm intermediate
5 min read

Tool schemas, argument validation, the tool_use/tool_result loop, error recovery, parallel calls and approval gates, all run against a scripted model.

llm intermediate
5 min read

Why 'return JSON only' isn't enough, and how schema validation plus a retry loop turns a flaky text model into a reliable data source.

llm intermediate
5 min read

Fit system prompt, history, documents and tool results into a token budget, cite sources, chunk by heading and trim tool output, all as runnable Python.

llm advanced
5 min read

Indirect prompt injection, excessive agency, and insecure output handling — the OWASP-style risks that survive input/output guardrails.

mcp beginner
5 min read

Build a Model Context Protocol server with one tool in Python, call it from a scripted client over stdio and in memory, and see why stdout is off limits.

mcp beginner
5 min read

See the inputSchema MCP builds from Python type hints, return structured output, and tell tool errors from protocol errors, all with real printed results.

mcp advanced
5 min read

Let an MCP server ask the client for input mid-call: elicitation, sampling and roots via multi round-trip requests, with scripted callbacks.