Build an AI Agent From Scratch in Python

Stephen Gruppetta 13 Lessons 1h 4m Updated intermediate ai

You know how LLMs work, and you may already use AI agents to help you write code. However, an agent isn’t an LLM, and an LLM isn’t an agent. What sits between them is the agentic loop. In this video course, you’ll build an AI agent from scratch in Python by writing the harness that turns a language model into an agent. You’ll do this in about 90 lines of code, with no frameworks.

By the end of this video course, you’ll understand that:

  • An AI agent is a language model wrapped in a harness, which is a loop that passes information between you, the model, and a set of tools.
  • The Chat Completions API doesn’t remember earlier messages between calls, so the harness resends the whole conversation context with every request.
  • A tool is any action the harness can perform for the model, such as running a Python function. The model learns about the tool only through its description, which includes a JSON schema for its arguments.
  • The model never runs a tool itself. It returns a tool call, and the harness decides whether to run the tool and send back the result.
  • Running the model in a loop lets it chain tool calls, using each result to decide its next step until it has an answer.

What’s Included:

  • 13 Lessons
  • Video Subtitles and Full Transcripts
  • 2 Downloadable Resources
  • Accompanying Text-Based Tutorial
  • Interactive Quiz to Check Your Progress
  • 2 Hands-On Coding Exercises
  • Q&A With Python Experts: Ask a Question
  • Certificate of Completion

Downloadable Resources:

About Stephen Gruppetta

Stephen obtained a PhD in physics and worked as a physicist in academia for over a decade before becoming a Python educator. He's constantly looking for simple ways to explain complex things in Python.

» More about Stephen

Each tutorial at Real Python is created by a team of developers so that it meets our high quality standards. The team members who worked on this tutorial are:

← Browse All Courses