Uploaded October 2026 | Updated December 2026, 2 days ago
Build an AI Agent From Scratch in Python (live course) β realpython.com/workshops/agentic-loops/?utm_source=youtube&utm_medium=description&utm_campaign=agentic-loops&utm_content=oBbwZjcunDE
You use AI agents every day, but an agent isn't an LLM. It's an LLM wrapped in a harness of plain code. In this video, Stephen Gruppetta builds that harness from scratch in Python with the OpenAI API and shows the single change that turns a chatbot into an agent.
You'll start with one chat-completion call that can't see your files, then add a loop, a growing message history so the model remembers the conversation, and tool definitions so it can ask the harness to list and read files. The last step swaps an "if" for a "while", and the model starts chaining tool calls on its own until it has an answer.
By the end, agents like Claude Code and Codex stop being a mystery: you'll know what they send to the model, why long conversations get expensive, and where permissions and memory fit in.
Create Your Personal Python & AI Coding Learning Plan β realpython.com/plan?utm_source=youtube&utm_medium=description&utm_campaign=learning-plan&utm_content=oBbwZjcunDE
π Links from the video:
Sample code for this video: realpython.com/bonus/agentic-loop-code/?utm_source=youtube&utm_medium=description&utm_campaign=agentic-loop-code&utm_content=oBbwZjcunDE
OpenAI Python library: github.com/openai/openai-python
OpenAI function calling guide: platform.openai.com/docs/guides/function-calling
00:00 Chatbot vs. agent: same model, different code
00:45 What a harness is
00:52 Talking to an LLM with the OpenAI API
02:40 Wrapping the model in a while loop
04:57 Why the model forgets: sending the whole conversation
06:37 Giving the model a tool
08:31 The model asks for a tool call
09:04 Running tools from the harness
11:50 Adding a read_file tool
13:02 Mapping tool names to functions
14:10 From if to while: the agent loop
15:49 What real agents add
16:18 Recap: how an agent works
17:05 Go further with the live course
π Become a Python expert with real-world tutorials, on-demand courses, interactive quizzes, and 24/7 access to a community of experts at https://realpython.com?utm_source=youtube&utm_medium=description&utm_campaign=home&utm_content=oBbwZjcunDE
β°β°β°β°β°β°β°β°β°β°β°β°β°β°β°β°β°β°β°β°
π Start Here β realpython.com/start?utm_source=youtube&utm_medium=description&utm_campaign=start&utm_content=oBbwZjcunDE
πΊοΈ Guided Learning Paths β realpython.com/learning-paths/?utm_source=youtube&utm_medium=description&utm_campaign=learning-paths&utm_content=oBbwZjcunDE
π§ Real Python Podcast β realpython.com/podcast?utm_source=youtube&utm_medium=description&utm_campaign=podcast&utm_content=oBbwZjcunDE
π Python Books β realpython.com/books?utm_source=youtube&utm_medium=description&utm_campaign=books&utm_content=oBbwZjcunDE
π Python Reference β realpython.com/ref?utm_source=youtube&utm_medium=description&utm_campaign=ref&utm_content=oBbwZjcunDE
π§βπ» Quizzes & Exercises β realpython.com/quizzes/?utm_source=youtube&utm_medium=description&utm_campaign=quizzes&utm_content=oBbwZjcunDE
π Live Courses: realpython.com/live/?utm_source=youtube&utm_medium=description&utm_campaign=live&utm_content=oBbwZjcunDE
βοΈ Reviews & Learner Stories: realpython.com/learner-stories/?utm_source=youtube&utm_medium=description&utm_campaign=learner-stories&utm_content=oBbwZjcunDE
β°β°β°β°β°β°β°β°β°β°β°β°β°β°β°β°β°β°β°β°
Build an AI Agent From Scratch in Python (live course) β realpython.com/workshops/agentic-loops/?utm_source=youtube&utm_medium=description&utm_campaign=agentic-loops&utm_content=oBbwZjcunDE
You use AI agents every day, but an agent isn't an LLM. It's an LLM wrapped in a harness of plain code. In this video, Stephen Gruppetta builds that harness from scratch in Python with the OpenAI API and shows the single change that turns a chatbot into an agent.
You'll start with one chat-completion call that can't see your files, then add a loop, a growing message history so the model remembers the conversation, and tool definitions so it can ask the harness to list and read files. The last step swaps an "if" for a "while", and the model starts chaining tool calls on its own until it has an answer.
By the end, agents like Claude Code and Codex stop being a mystery: you'll know what they send to the model, why long conversations get expensive, and where permissions and memory fit in.
Create Your Personal Python & AI Coding Learning Plan β realpython.com/plan?utm_source=youtube&utm_medium=description&utm_campaign=learning-plan&utm_content=oBbwZjcunDE
π Links from the video:
Sample code for this video: realpython.com/bonus/agentic-loop-code/?utm_source=youtube&utm_medium=description&utm_campaign=agentic-loop-code&utm_content=oBbwZjcunDE
OpenAI Python library: github.com/openai/openai-python
OpenAI function calling guide: platform.openai.com/docs/guides/function-calling
00:00 Chatbot vs. agent: same model, different code
00:45 What a harness is
00:52 Talking to an LLM with the OpenAI API
02:40 Wrapping the model in a while loop
04:57 Why the model forgets: sending the whole conversation
06:37 Giving the model a tool
08:31 The model asks for a tool call
09:04 Running tools from the harness
11:50 Adding a read_file tool
13:02 Mapping tool names to functions
14:10 From if to while: the agent loop
15:49 What real agents add
16:18 Recap: how an agent works
17:05 Go further with the live course
π Become a Python expert with real-world tutorials, on-demand courses, interactive quizzes, and 24/7 access to a community of experts at https://realpython.com?utm_source=youtube&utm_medium=description&utm_campaign=home&utm_content=oBbwZjcunDE
β°β°β°β°β°β°β°β°β°β°β°β°β°β°β°β°β°β°β°β°
π Start Here β realpython.com/start?utm_source=youtube&utm_medium=description&utm_campaign=start&utm_content=oBbwZjcunDE
πΊοΈ Guided Learning Paths β realpython.com/learning-paths/?utm_source=youtube&utm_medium=description&utm_campaign=learning-paths&utm_content=oBbwZjcunDE
π§ Real Python Podcast β realpython.com/podcast?utm_source=youtube&utm_medium=description&utm_campaign=podcast&utm_content=oBbwZjcunDE
π Python Books β realpython.com/books?utm_source=youtube&utm_medium=description&utm_campaign=books&utm_content=oBbwZjcunDE
π Python Reference β realpython.com/ref?utm_source=youtube&utm_medium=description&utm_campaign=ref&utm_content=oBbwZjcunDE
π§βπ» Quizzes & Exercises β realpython.com/quizzes/?utm_source=youtube&utm_medium=description&utm_campaign=quizzes&utm_content=oBbwZjcunDE
π Live Courses: realpython.com/live/?utm_source=youtube&utm_medium=description&utm_campaign=live&utm_content=oBbwZjcunDE
βοΈ Reviews & Learner Stories: realpython.com/learner-stories/?utm_source=youtube&utm_medium=description&utm_campaign=learner-stories&utm_content=oBbwZjcunDE
β°β°β°β°β°β°β°β°β°β°β°β°β°β°β°β°β°β°β°β°










