How AI Agents Really Work: Build One in Plain Python @realpython
How AI Agents Really Work: Build One in Plain Python  @realpython
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
β–°β–°β–°β–°β–°β–°β–°β–°β–°β–°β–°β–°β–°β–°β–°β–°β–°β–°β–°β–°
How AI Agents Really Work: Build One in Plain Python3.15s New Stable ABI: One Wheel for Every VersionContext Window Is a Workspace, Not a WarehouseConvert PDFs and Excel Into LLM-Ready Markdown With PythonClaude Skills Are Just Files You Can Read and EditRedaction Mistake That Leaves Text for AI to Read7 Python Mistakes Beginners MakePerformance Lessons From a Python Team LeadBuild Python CLIs With Argparse and No DependenciesOne Wheel for Free-Threaded and GIL PythonGive AI Just Enough Context to Succeed3 Problems With Hard-Coding Parameters in Python Code
Real Python |

How AI Agents Really Work: Build One in Plain Python

SHARE TO X SHARE TO REDDIT SHARE TO FACEBOOK WALLPAPER