Lessons · Coding · beginner · Tech With Tim

Building AI Agents in Pure Python - Beginner Course

The video “Building AI Agents in Pure Python - Beginner Course” by Tech With Tim as 8 lessons, with the idea explained, the code from the screen, steps to try in the practice terminal, practice problems with solutions and a quiz that leads back to the moment.

8lessons
13pieces of code
15exercises
27questions
37min of video
Open the lessons →Lesson 1 is free · Beyond Pass opens all
Building AI Agents in Pure Python - Beginner Course, video by Tech With Tim▶ 37:24 · Tech With Tim
12345678
0:008 lessons across the whole video37:24

You will be able to

  • Explain the three parts of an AI agent (model, tools, loop) and why an LLM only generates text
  • Make an API call to an LLM from Python and read the response
  • Maintain conversation history by passing the messages list back to the model each turn
  • Write a Python tool with a JSON schema and execute the model's tool calls in a loop until it finishes
  • Build a small coding agent with file and shell tools that can create and edit files in a project

Good to know first

  • Basic Python: functions, lists, dictionaries, and loops
  • Comfort using a terminal and editing files in a code editor
  • A package manager such as uv or pip, and an OpenAI API key with billing enabled

Syllabus

8 lessons and a final project

  1. 1

    What an agent is: model, tools, and loop Free

    0:00–3:003 min of video

    An AI agent is built from three parts: a model that reasons by turning text into text, tools that let it act, and a loop that keeps it working until the task is done. This lesson shows how those three pieces fit together, and why a single model call is only a chatbot.

    2 exercises4 questions
  2. 2

    Setting up a project and making your first LLM call Beyond Pass

    3:00–12:159 min of video

    You will set up a Python project with uv, install the OpenAI package, and send your first request to a language model. You will also learn what messages and roles (system, user, assistant) are and why the model needs them.

    2 code5 build steps2 exercises3 questions
  3. 3

    Adding conversation memory with the messages list Beyond Pass

    12:15–17:005 min of video

    You will learn why a language model forgets everything between calls and how a messages list gives your agent memory by being passed back in on every turn. You will see the step-two script that appends each user question and each assistant reply, and test it with and without that list.

    1 code5 build steps2 exercises3 questions
  4. 4

    How tool calling works: schemas and the harness Beyond Pass

    17:00–19:002 min of video

    Tool calling lets an agent ask for actions by sending a menu of tool schemas to the model and getting back a structured request. The model only asks; your Python harness does the actual work and sends the result back.

    2 code3 exercises3 questions
  5. 5

    Building a read_file tool and the tool-call loop Beyond Pass

    19:00–27:309 min of video

    You will write a real Python function that an AI model can ask to run, describe it with a schema the model can read, and write the loop that runs each requested tool call and feeds the result back. By the end you will know why the model never runs code itself and how the message list carries the whole conversation.

    2 code2 build steps1 exercise3 questions
  6. 6

    Building a mini Claude Code: four tools and the agent loop Beyond Pass

    27:30–33:306 min of video

    You will see how a coding agent is assembled from four tools (list files, read file, write file, run command), JSON-style tool schemas that describe them to the model, and an agent loop that keeps calling tools until the model answers in plain text. You will also see how a main loop keeps the whole conversation in one messages list.

    3 code6 build steps4 questions
  7. 7

    Running the agent: building a snake game in Pygame Beyond Pass

    33:30–36:083 min of video

    You will watch an AI agent turn a plain-English request into real files: it creates a folder, writes a Pygame snake game, and then splits it into several modules. You will also see how the agent's tool calls, your approval, and the final game fit together.

    2 code5 build steps3 exercises4 questions
  8. 8

    Recap: an agent is just an LLM in a loop with tools Beyond Pass

    36:08–37:241 min of video

    This recap shows that an AI agent is not magic: it is ordinary software that repeatedly asks an LLM what to do, runs the tools the LLM requests, and feeds the results back. Once you see the loop, you can build a working agent in pure Python without frameworks.

    1 code3 build steps2 exercises3 questions

Final project

Build Your Own Mini Coding Agent (and Prove the Loop Works)

Build a small coding agent in pure Python with four tools (list files, read file, write file, run command) and a loop that runs until the model answers in plain text. You will also write a fake model so you can test the loop without calling an API. This shows that an agent is an LLM, tools and a loop.

Its 7 tasks open with Beyond Pass.

Free preview · Lesson 1 in full

What an agent is: model, tools, and loop

An AI agent is built from three parts: a model that reasons by turning text into text, tools that let it act, and a loop that keeps it working until the task is done. This lesson shows how those three pieces fit together, and why a single model call is only a chatbot.

0:00 to 3:00 in the video

Scratchpad

Draw and write next to the video.

The idea

An AI agent is, in the video's words, really just three things: a model, tools, and a loop. You can also add context or memory, but the video suggests that memory can be folded into the tools, so the core is the three parts.

The model is the brain. In practice it is just an API: you send it text and it sends text back. It might be a local model you run yourself (through Ollama, Docker Model Runner or LM Studio) or a closed-source model from a provider such as Anthropic or OpenAI. Its job is to reason, and what it produces is text that is meaningful enough for our program to read and act on.

Tools are the hands of the agent. A tool can be almost anything: an MCP server, a third-party service, a web search, or a Python function you write yourself. In this course the tools are plain Python functions, but a function can do anything inside it, and later you can connect other tools too.

The loop is the important part. One request and one response is just a chatbot. An agent keeps going: the model asks for a tool, the tool runs, the result is sent back, and the model decides the next step. This can repeat 20, 30 or 40 times, and the loop only stops when the agent says it is finished. Big tools like Claude Code, Cursor and Codex are, under the hood, the same three things built very cleverly, with extra features on top.

So the plan for the course is three steps. First you call an LLM through an API. Then you add tools. Then you wrap it all in a loop. Each step builds on the one before.

Key points

  • An agent = model + tools + loop. Remove the loop and you have a chatbot. 0:46
  • The model is the brain: it takes text in and gives text out, and it does the reasoning. 0:58
  • Tools can be anything; in this course, they are Python functions. 1:44
  • The loop lets the agent keep working over many requests until it reports it is finished. 1:55
  • Products like Claude Code, Cursor and Codex share these same three core parts. 2:23

Words to know

Agent
A program that uses a model, tools and a loop to work towards a task over many steps.
Model (LLM)
The reasoning brain, accessed through an API, that turns text input into text output.
Tool
An action the agent can take, such as a Python function, a web search or an MCP server.
Loop
The repeated cycle of asking the model, running a tool, and sending the result back until the task is done.
API
A way for one program to send a request to another service and get a reply back.

Watch out

  • A single model call is not an agent. One question and one answer is a chatbot; the loop is what makes it an agent. 1:15
  • A local model and a cloud model are both 'the model' here. The model is defined by its role (reasoning via text), not by where it runs. 1:00
  • Memory and context are optional extras; the video says they can be wrapped into the tools. 0:52

Practice

Explain Solution checked

In your own words, explain why a program that sends one question to a model and prints the answer is a chatbot, not an agent.

Hint

Think about what the loop adds and how many requests happen.

Solution
  1. One request goes out and one response comes back, then the program stops.
  2. An agent needs a loop so it can call tools, get results, and keep going for many steps until it reports it is finished.

A chatbot makes one request and gets one reply. An agent loops: it asks the model, runs a tool, sends back the result, and repeats until the task is done.

Do it Solution checked

On paper or in your scratchpad, draw a box for the model, a box for tools, and a circle arrow for the loop. Draw arrows showing what goes from the model to a tool and back again.

Hint

The loop should connect the model and the tools in a cycle.

Solution
  1. Draw the model box and the tools box side by side.
  2. Draw an arrow from the model to the tools (a tool call) and an arrow back (the tool result).
  3. Draw a circular arrow around both to show the loop repeats until the task is finished.

A diagram with model and tools connected by arrows in a repeating circle, labelled as the loop.

On your scratchpad

Draw three boxes labelled Model, Tools and Loop. Then draw arrows: model sends a request to tools, tools send a result back to model, and a circular arrow around them shows the loop repeating until the task is finished.

Quiz

  1. Which three things make up an AI agent according to the chapter?

    1. A model, tools, and a loop
    2. A database, a browser, and a server
    3. A prompt, a font, and a colour theme
    4. Only a large model with memory
    Show the answer

    A. A model, tools, and a loop · The video says an agent is really just three things: a model, tools, and a loop.

    0:46 watch the moment
  2. Why is a loop the important part?

    1. It makes the model faster
    2. It lets the agent keep calling tools and working across many requests until it finishes a task
    3. It stores the API key
    4. It replaces the model
    Show the answer

    B. It lets the agent keep calling tools and working across many requests until it finishes a task · Without the loop, one request gives one response, like a chatbot. The loop lets the agent work through many steps.

    1:55 watch the moment
  3. What is the model's main job in an agent?

    1. To run the tools directly on the computer
    2. To reason, taking text in and giving text out
    3. To store files
    4. To draw the user interface
    Show the answer

    B. To reason, taking text in and giving text out · The model is the brain. It reasons and generates text, which the program then reads and uses.

    1:12 watch the moment
  4. What form do the tools take in this course?

    1. MCP servers only
    2. Python functions that we write ourselves
    3. Closed-source models
    4. Browser extensions
    Show the answer

    B. Python functions that we write ourselves · The video says the tools in this video will be Python functions, though they could connect to other tools later.

    1:50 watch the moment

Open lesson 1, with the video →

Lessons 2–8 and the final project

They open with Beyond Pass: every lesson of every course, in full. One payment: $14.99 for 90 days or $29 for a year. No subscription.

Made by Beyond from the video “Building AI Agents in Pure Python - Beginner Course” by Tech With Tim. The video plays in YouTube's own player. Watch it on YouTube · All lessons