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.
Tutorial pages
Sign in to access this workshop
This workshop is free — you just need an account. Sign in or create one in seconds.
Sign InBy creating an account, you agree to our Terms of Service and Privacy Policy.
By signing up free, you'll receive community updates. You can unsubscribe at any time.
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
AI Hero: 7-Day AI Agents Crash-Course
Build a complete AI agent from data ingestion to deployment in 7 focused days. You will use a real GitHub repository as the source material, then build an assistant that can read …
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