SuperAPI AI Directory

smolagents

A barebones Python library where agents think and act by writing code, built by Hugging Face.

Open website

About this tool

Purpose

smolagents is a Python library for building and running AI agents, developed by Hugging Face. Its core feature is letting agents "think in code": instead of outputting a dictionary of tools to call, the agent directly writes Python code snippets as actions. According to the official team, this approach can reduce the number of steps by about 30% (i.e., reduce LLM calls by 30%) compared with the industry practice of having the LLM output a dictionary of tool calls, and achieves higher performance on difficult benchmarks.

Main capabilities

  • Minimalist design: The agent's main logic is located in agents.py, at about 1,000 lines of code, with abstractions kept in a minimal form close to the original code.
  • First-class support for CodeAgent: CodeAgent writes actions as code; for safety, it supports execution in sandboxed environments via Blaxel, E2B, Modal, or Docker.
  • Hub integration: Tools or agents can be shared with/pulled from the Hugging Face Hub, making it easy to instantly share efficient agents.
  • Model-agnostic: Supports any LLM, including local transformers or ollama models, the many providers on the Hub, and models such as OpenAI and Anthropic through LiteLLM integration.
  • Modality-agnostic: Agents support text, vision, video, and even audio input.
  • Tool-agnostic: You can use any MCP server, tools from LangChain, and even use a Hub Space as a tool.
  • Multiple agent types: In addition to CodeAgent, a standard ToolCallingAgent is also provided, which writes actions as JSON/text blocks; it also supports multi-agent hierarchies, importing from tool collections, remote code execution, vision models, and more.

How to use

First install the package with the default tool set, then define an agent, give it the required tools, and run it. You can also share the agent to the Hub as a Space repository. The library is LLM-agnostic, and examples can be switched to any inference provider.

The command line provides two commands:

  • smolagent: a general command used to run a multi-step CodeAgent that can be equipped with a variety of tools. Interactive mode guides you through selecting the agent type (CodeAgent and ToolCallingAgent), choosing tools from the available toolbox, configuring the model (type, ID, API settings), advanced options (such as additional imports), and entering the task prompt.
  • webagent: a specific web-browsing agent that uses helium.

CodeAgent works similarly to a classic ReAct agent, except that the LLM engine writes actions as Python code snippets, so tool calls are executed as Python function calls. For example, the agent can perform a web search across multiple websites in a single action.

Suitable scenarios

Suitable for developers who need to build lightweight, customizable AI agents, especially in scenarios where they want the agent to execute actions in the form of code, need to connect to a variety of models and tools, or need to safely execute code in a sandbox. It is also suitable for researching agent workflows and comparing the performance of different models on agent tasks.

Limitations and safety

Code execution carries serious security risks (arbitrary code execution), so agent code should be run in a sandbox. It supports E2B, Blaxel, Modal (managed cloud sandboxes, easiest to set up) and Docker (self-hosted container isolation). The built-in LocalPythonExecutor is not a secure sandbox; it only provides best-effort mitigations, can be bypassed, must not be used as a security boundary, and should not be used to run untrusted code.