Back to Workshops
Workshop Free with sign-in

The Agentic Loop: Building a Mini Agent Framework from Scratch

July 7, 2026
ai-agents agentic-loop function-calling python

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.

flowchart LR USER["User question"] --> LLM["LLM"] LLM -->|"wants to search"| TOOL["search tool over the FAQ"] TOOL -->|"results"| LLM LLM -->|"done"| ANSWER["Final answer"]

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 search tool, 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 Agent class.
  • 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:

Sign in to access this workshop

This workshop is free — you just need an account. Sign in or create one in seconds.

Sign In
Already have an account? Sign in
or sign up with

By 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.