AI · Intermediate

Building AI Agents from Scratch

Learn what makes software agentic, then write your own think-act-observe loop, tools, memory, and MCP adapters in Python — not another agent SDK wrapper.

Who it is for

Developers who want to own the agent loop, not wrap another framework.

You should already know

Comfortable with a terminal, Python 3, HTTP, and JSON. An API key for any OpenAI-compatible chat endpoint. No prior agent-framework experience. Lessons on MCP tools assume the MCP course or equivalent.

You will be able to

  • Explain an agent versus a chatbot, a workflow, and a raw LLM call
  • Run an OpenAI-compatible chat completion with system and user messages
  • Implement think → act → observe → repeat and stop it cleanly
  • Define tool schemas, execute calls, and return results the model can use
  • Add short-term and long-term memory, planning, and failure recovery
  • Ship structured outputs, approval gates, MCP tools, logs, evals, and cost limits

Lessons

20 lessons

  1. What Is an AI Agent? LLM vs chatbot vs workflow vs agent — and what actually makes software agentic.
  2. Build Your First LLM Application Call an OpenAI-compatible chat API with system and user messages and print a real response.
  3. The Agent Loop Build the think → act → observe → repeat loop from scratch and decide when it stops.
  4. Giving Your Agent Tools Define the first tools and let the model decide when to call them.
  5. Tool Calling from Scratch Parse tool schemas and arguments, execute your code, and return results to the model.
  6. Multiple Tools and Tool Selection Give the agent several tools and see how names and descriptions drive which one it picks.
  7. Building a Useful Agent Combine the loop, tools, and results into a practical project assistant — not a toy calculator.
  8. Conversation Context and Memory Keep message history, respect the context window, and summarize when short-term memory gets too long.
  9. Long-Term Memory Store and retrieve useful facts across sessions — and know when memory makes the agent worse.
  10. Planning Multi-Step Tasks Handle tasks that need several actions, dependencies, and a replan after new observations.
  11. Handling Tool Failures Timeouts, bad parameters, API errors, retries, and letting the agent recover inside the loop.
  12. Structured Outputs Force a JSON object your application can consume instead of parsing prose.
  13. Human Approval and Guardrails Require confirmation before the agent sends, deletes, purchases, or modifies data.
  14. Giving Your Agent MCP Tools Connect the agent to an MCP server and turn that server’s tools into calls your loop can run.
  15. Working with Multiple MCP Servers Let one agent use several MCP servers without hard-coding every integration.
  16. Agent Security Prompt injection, untrusted tool output, permissions, secrets, and dangerous actions.
  17. Agent Observability and Debugging Log model calls and tool calls, inspect decisions, trace failures, and measure token and cost usage.
  18. Evaluating Your Agent Build small repeatable tests so a prompt or tool change is a measured win, not a vibe.
  19. Production Architecture Queues, persistence, background jobs, concurrency, rate limits, and cost controls for a real agent service.
  20. Capstone: Build a Real AI Agent Assemble the loop, tools, memory, approval, traces, and evals into a deployable agent that finishes real multi-step tasks.