2025 has been dubbed the year of agentic AI. Tools like Google Gemini CLI, Claude Code, GitHub Copilot agent mode, and Cursor are all examples of agents—autonomous entities that can take an open-ended task, plan, take action, reflect on the results, and loop until the task is done. And they’re creating real value.But how do agents actually work? How can you build one?In this post, I’ll walk through the core of how agents function: the agent execution loop that powers these complex behaviors.Note: This post is adapted from my book Designing Multi-Agent Systems, where Part II (Chapters 4-6) guides you through building a complete agent framework from scratch.Digital PDF: buy.multiagentbook.comPrint on Amazon: amazon.com/dp/B0G2BCQQJY An agent is an entity that can reason, act, communicate, and adapt to solve problems.Consider two questions you might ask a generative AI model like GPT5 from OpenAI or Claude from Anthropic:“What is the capital of France?” “What is the stock price of NVIDIA today?” The first question can be answered by a model directly (it likely has seen instances of this specific fact/knowledge and this is now encoded in its model weights). The second cannot - the model will hallucinate a plausible-sounding but incorrect answer because it doesn’t have access to real-time data.An agent setup solves this by recognizing it needs current data, calling a financial API, and returning the actual price. This requires action, not just text generation.In simple terms, an agent has three core components:Model: The reasoning engine (typically an LLM like GPT-5) that processes context and decides what to doTools: Functions the agent can call to take action - APIs, databases, code execution, web searchMemory: Short-term (conversation history) and long-term (persistent storage across sessions)Before building an agent, you need to understand how to call a generative AI language model. Here’s the basic pattern using the OpenAI API:from openai import AsyncOpenAI