2025-04-26
Agents is the new hype. Dozens of frameworks are popping up every day.
For me, in order to understand something, I love building it from scratch to get a feel of how it works. So I decided to build a minimal agent from scratch using Granite 3.3.
To be an agent, a model needs to have choice to perform certain actions in order to achieve a goal. In this case, I will give the agent the ability to call a magic function in order to let the user know what it returns for the number the user provides.
The full code is available in this Colab Notebook.
I've created a modified version using Groq, Tavily Search, and Riza in this Colab Notebook.
Let's start by building our toolbox:
The response from the model can be either
Our execution loop should parse the response and interpret it accordingly.
Let's define some utility methods for parsing and logging
Let's use the snippet provided in the Granite 3.3 Model Card
Abstract the logic of calling the model into a function
Now let's define the system message that will be used to instruct the model on how to behave.
Let's also add an example for in-context learning
Now let's define the agent loop that will execute the tool calls and print the results.
This is the core of any agent. You need to:
choice to perform certain actions