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.

When to Use an Agentic Framework

An agentic framework is not always needed when building an application around LLMs. They provide flexibility in the workflow to efficiently solve a specific task, but they’re not always necessary. Sometimes, predefined workflows are sufficient to fulfill user requests, and there is no real need for an agentic framework. Even if the agentic approach is low-level, like chains or routers, using plain code may be enough since the developer will have full control and understanding of the system.

However, when the workflow becomes more complex, such as letting an LLM call functions (tool calling) or execute multiple steps (multi-step agent), these abstractions start to become necessary.

Considering these ideas, we can already identify the need for some features:

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 calling search or image generation tools. AI agents are programs where LLM outputs control the workflow.

Key Advantages of smolagents

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 inherit from MultiStepAgent, enabling them to operate in multiple steps, where each step consists of:

There are two types of agents available:

  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.

Note: 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 as long as it meets certain criteria. To simplify connections with various model types, the framework provides predefined classes:

This flexibility ensures that developers can choose the most suitable model integration for their specific use cases.

When to use smolagents

All the previously mentioned functionality is available in smolagents. So the question becomes: when should we use smolagents instead of other possible frameworks?

You may choose smolagents if:

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

Further Reading

< > Update on GitHub