Smolagents AI Agent Framework

HuggingFace’s NEW Agent Framework, Create Powerful AI Agents with Minimal Effort

Get Viral Video Instantly

Powered By Nemovideo

Ai code Smolagents | FAST&FREE

Powered By Together AI and LlamaCoder

Llama Coder – AI Code Generator

Turn your idea into an app

Smolagents and Tools Gallery

Best Smolagents in HuggingFace

Smolagents and tools gallery

What are agents?

AI Agents are programs where LLM outputs control the workflow.

Agency Level Description How that’s called Example Pattern
☆☆☆ LLM output has no impact on program flow Simple processor process_llm_output(llm_response)
★☆☆ LLM output determines basic control flow Router if llm_decision(): path_a() else: path_b()
★★☆ LLM output determines function execution Tool call run_function(llm_chosen_tool, llm_chosen_args)
★★★ LLM output controls iteration and program continuation Multi-step Agent while llm_should_continue(): execute_next_step()
★★★ One agentic workflow can start another agentic workflow Multi-Agent if llm_trigger(): execute_agent()

Feature of SmolAgents

🤗 Smolagents is a minimalist AI agent framework developed by the Hugging Face team, crafted to enable developers to deploy robust agents with just a few lines of code. Embracing simplicity and efficiency, smolagents empowers large language models (LLMs) to interact seamlessly with the real world.

✨ Simplicity

Compact Codebase: With approximately 1,000 lines of core code in agents.py, smolagents keeps abstractions to a minimum for straightforward development.

User-Friendly

Developers can swiftly define agents, supply the necessary tools, and run them immediately without intricate configurations.

Code Agents

smolagents focuses on code agents, where agents write and execute Python code snippets to perform actions, instead of generating actions as JSON or text blobs.

High Efficiency

Compared to standard tool-calling methods, code agents offer enhanced efficiency and accuracy, reducing steps and LLM calls by about 30%, and achieving superior performance on complex benchmarks.

Secure Execution

To ensure safe code execution, smolagents supports running code in sandboxed environments like E2B, providing a protected and isolated execution space.

Various LLMs

smolagents integrates effortlessly with any large language model, including models hosted on the Hugging Face Hub via Transformers, as well as models from OpenAI, Anthropic, and others through LiteLLM integration.

SmolAgents :Integration with Hugging Face Hub

Share and Load Tools: Deep integration with the Hugging Face Hub allows developers to easily share and import tools, fostering collaboration and sharing within the community.

Ecosystem Growth: Leveraging the Hub’s capabilities, smolagents continually expands with more functionalities and tools, offering limitless potential for development.

Support for Traditional Tool-Calling Agents

Variety of Choices: In addition to code agents, smolagents also supports traditional tool-calling agents, where actions are written as JSON or text blocks, suitable for specific scenarios and requirements.

Reasons to Opt for Code smolAgents

Superior Composability: Code naturally supports function nesting and reuse, allowing for the expression of complex logic.

Efficient Object Handling: Compared to JSON, code simplifies the management and transfer of objects.

Ultimate Flexibility: Code can represent any operation a computer can perform, providing immense versatility.

Extensive Training Data: LLMs have been trained on vast amounts of high-quality code, enhancing their ability to generate and comprehend code.

Performance Benefits of smolagents

In various benchmarks, smolagents utilizing open-source models have matched the performance of agents using proprietary models. Thanks to the efficiency of code agents and the continuous advancements of open-source models, developers can build powerful agent systems without relying on closed-source services.

Application example of SmolAgents

In Smolagents, agents are encapsulated in classes that allow them to perform specific tasks. For instance, a ManagedAgent can be created to manage various tasks by utilizing different agent types. Below is a simplified example of how two agents—one for web searching and another for image generation—can be implemented.

from typing import Optional
from smolagents import CodeAgent, HfApiModel, tool

@tool
def get_travel_duration(start_location: str, destination_location: str, transportation_mode: Optional[str] = None) -> str:
    """Gets the travel time between two places.

Args:
        start_location: the place from which you start your ride
        destination_location: the place of arrival
        transportation_mode: The transportation mode, in 'driving', 'walking', 'bicycling', or 'transit'. Defaults to 'driving'.
    """
    import os   # All imports are placed within the function, to allow for sharing to Hub.
    import googlemaps
    from datetime import datetime

gmaps = googlemaps.Client(os.getenv("GMAPS_API_KEY"))

if transportation_mode is None:
        transportation_mode = "driving"
    try:
        directions_result = gmaps.directions(
            start_location,
            destination_location,
            mode=transportation_mode,
            departure_time=datetime(2025, 6, 6, 11, 0), # At 11, date far in the future
        )
        if len(directions_result) == 0:
            return "No way found between these places with the required transportation mode."
        return directions_result[0]["legs"][0]["duration"]["text"]
    except Exception as e:
        print(e)
        return e

agent = CodeAgent(tools=[get_travel_duration], model=HfApiModel(), additional_authorized_imports=["datetime"])

agent.run("Can you give me a nice one-day trip around Paris with a few locations and the times? Could be in the city or outside, but should fit in one day. I'm travelling only with a rented bicycle.")

Frequently Asked Questions about smolagents

What is smolagents?

smolagents is a minimalist AI agent library developed by the Hugging Face team. It allows developers to create and run powerful AI agents with minimal code. By focusing on simplicity and efficiency, smolagents enables large language models (LLMs) to interact seamlessly with real-world tasks.

How does smolagents differ from other AI agent frameworks?

Unlike many AI agent frameworks that have complex abstractions and configurations, smolagents maintains a compact codebase of about 1,000 lines. It emphasizes ease of use and supports code agents, where agents execute Python code snippets directly, enhancing efficiency and reducing the number of required steps and LLM calls.

Which large language models are compatible with smolagents?

smolagents is designed for broad compatibility with LLMs. It integrates seamlessly with models hosted on the Hugging Face Hub via Transformers, as well as with models from OpenAI, Anthropic, and others through LiteLLM integration. This flexibility allows you to choose the most suitable LLM for your project needs.