Skip to content
Naveen Raj

Building AI Agents from Scratch with Python

Building the Core Loop

Theory is done — this chapter writes the actual agent loop in Python, from an empty file to something that can hold a conversation, call a tool, and remember what happened.

We won't use an agent framework here on purpose. Seeing the loop with no abstraction on top of it makes the frameworks (LangGraph, CrewAI, etc.) make a lot more sense later, because you'll recognize exactly which part of the loop each one is automating for you.