Build Your First AI Agent in Python (Tool-Calling, Step by Step)
Versions used in this post — read this first: Python 3.12 · google-genai 1.35.0 · model gemini-2.5-flash · No framework, no LangChain. Everything below runs from one file. If a newer SDK changes a method name, the loop in Step 4 stays the same — only the call syntax moves. The direct answer An AI agent is not a special kind of model. It is a normal program that does three things in a loop: it sends your question and a list of tools to a model, it runs whichever tool the model asks for, and it sends the tool result back so the model can answer — or ask for another tool. Execution stays with your program from start to finish — the model only ever asks. This post builds that loop by hand, on purpose. Frameworks hide the loop, and the loop is the part you need when something breaks in production. What you will build A small command-line agent with two tools: Weather lookup — gets the current temperature and wind for a city from the free Open-Meteo service, which needs no...