The Agentic Loop: Building a Mini Agent Framework from Scratch
We start with a fixed RAG pipeline that searches a course FAQ once and passes the results to the model. That works until the search misses. A typo, a question phrased the wrong way, or a question that needs two lookups breaks it. The model never gets to try again.
So we give the model a search tool and let it pick when to call it.
Now we have an agent. The loop calls the model, runs whatever tool it
asks for, and feeds the result back. It repeats until the model answers.
Then we refactor that loop into a tiny framework of our own. We move the
tools into a registry and the loop into an Agent class, with no
toyaikit, PydanticAI, or any other agent library. Writing the loop once
makes those frameworks easier to read later. They all wrap the same
loop.
Workshop flow
We write the examples in Python with minsearch and the OpenAI
Responses API, in a notebook.
We build in this order:
- A RAG baseline that searches the LLM Zoomcamp FAQ once and answers.
- Function calling step by step: we define a
searchtool, run one round, and send the result back to the model. - The agentic loop: we repeat that round until the model stops asking for tools.
- A mini framework: we move the tools into a registry and the loop into
an
Agentclass. - Extensions: a max-iteration cap, a second tool, and steering through the instructions.
Links
We pulled this workshop together from earlier AI Shipping Labs workshops and the agent modules of two courses:
- Agentic RAG - the framework version of the same loop, built with toyaikit and PydanticAI rather than from scratch.
- Building an Agent with Guardrails - the same agent class, later wrapped in input and output guardrails.
- End-to-End Agent Deployment - the same loop behind FastAPI with streaming.
- LLM Zoomcamp - free course whose agent module covers function calling and the loop. We take just the loop and build it into a framework.
- AI Engineering Buildcamp: From RAG to Agents - the deeper course where we build a simple agent framework from scratch.
- toyaikit - the teaching
framework whose
Toolsregistry andAgentrunner take the framework we build in Part 4 further.
Sign in to access this workshop
Tutorial pages
Related content
Building an Agent with Guardrails
AI agents are useful because they can call tools and act on user requests. That same flexibility makes them easy to steer off topic. In this workshop, we build a Data Engineering …
May 26, 2026
Building a Coding Agent: Python/Django Edition
For a newer, combined take, see Coding Agent with Skills. We build a small project bootstrapper for Django, a coding agent that takes a plain-language app request and copies a wor…
August 14, 2025
What to Expect in an AI Engineering Hiring Manager Interview
A practical guide to project deep dives, Python exercises, unfamiliar tasks, and the evidence hiring managers look for in AI engineering interviews.
July 22, 2026