smolagents banner

Why use smolagents

In this module, we will explore the pros and cons of using smolagents, helping you make an informed decision about whether it’s the right framework for your needs.

What is smolagents ?

smolagents is a simple yet powerful framework for building AI agents. It provides LLMs with the agency to interact with the real world, such as searching or generating images.

As we learned in unit 1, AI agents are programs that use LLMs to generate ‘thoughts’ based on ‘observations’ to perform ‘actions’. Let’s explore how this is implemented in smolagents.

Key Advantages of smolagents

When to use smolagents?

With these advantages in mind, when should we use smolagents over other frameworks?

smolagents is ideal when:

Code vs. JSON Actions

Unlike other frameworks where agents write actions in JSON, smolagents focuses on tool calls in code, simplifying the execution process. This is because there’s no need to parse the JSON in order to build code that calls the tools: the output can be executed directly.

The following diagram illustrates this difference:

Code vs. JSON actions

To review the difference between Code vs JSON Actions, you can revisit the Actions Section in Unit 1.

Agent Types in smolagents

Agents in smolagents operate as multi-step agents.

Each MultiStepAgent performs:

In addition to using CodeAgent as the primary type of agent, smolagents also supports ToolCallingAgent, which writes tool calls in JSON.

We will explore each agent type in more detail in the following sections.

In smolagents, tools are defined using @tool decorator wrapping a python function or the Tool class.

Model Integration in smolagents

smolagents supports flexible LLM integration, allowing you to use any callable model that meets certain criteria. The framework provides several predefined classes to simplify model connections:

This flexibility ensures that developers can choose the model and service most suitable for their specific use cases, and allows for easy experimentation.

Now that we understood why and when to use smolagents, let’s dive deeper into this powerful library!

Resources

< > Update on GitHub