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 that require parsing, smolagents focuses on direct tool calls in code, simplifying the execution process. The following diagram illustrates this difference:

Code vs. JSON actions

Agent Types in smolagents

Agents in smolagents operate as multi-step agents. Each MultiStepAgent performs:

The framework offers two types of agents:

  1. CodeAgent: The default agent type that writes tool calls using Python
  2. ToolCallingAgent: Writes tool calls in JSON

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

In smolagents, tools are defined using @tool or the Tool class. They are distinct from ToolCallingAgent. Both CodeAgents and ToolCallingAgent utilize tools. Keep this distinction in mind throughout the rest of the unit to avoid confusion!

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 most suitable model integration for their specific use cases.

Join us as we dive deep into smolagents in the upcoming sections!

Resources

< > Update on GitHub