**smolagents** logo

**smolagents**

Free

HuggingFace

FreeFree tier
Inputs: text, image, video, audioOutputs: code, text
Type
Open Source
Company
Hugging Face

About **smolagents**

smolagents is a lightweight library by Hugging Face for building AI agents that 'think in code.' The core agent logic fits in approximately 1,000 lines, with minimal abstractions. It provides first-class support for CodeAgents that write actions in Python, which can be executed in sandboxed environments (Blaxel, E2B, Modal, Docker) for security. The library is model-agnostic, supporting local models (transformers, ollama), Hugging Face Hub models, and any LLM provider via LiteLLM or OpenAI-compatible APIs. It is also modality-agnostic, handling text, vision, video, and audio inputs, and tool-agnostic, integrating with MCP servers, LangChain tools, or even Hugging Face Spaces as tools. Agents and tools can be easily shared on the Hugging Face Hub.

Key Features

Core agent logic in ~1,000 lines of code for simplicity
First-class CodeAgent that writes actions in Python code
Sandboxed execution via Blaxel, E2B, Modal, or Docker
Model-agnostic: supports local, Hugging Face, OpenAI, Anthropic, and 100+ LLMs via LiteLLM
Modality-agnostic: handles text, vision, video, and audio inputs
Tool-agnostic: integrates with MCP servers, LangChain tools, and Hugging Face Spaces
Seamless Hugging Face Hub integration for sharing agents and tools
Agent can be pushed to Hub as a Space repository

Pros & Cons

Pros
  • Extremely lightweight and simple codebase
  • Supports a wide range of LLMs including local and cloud
  • Handles multimodal inputs (text, vision, video, audio)
  • Secure execution via sandboxed environments
  • Easy to share and reuse agents on Hugging Face Hub
  • Tool-agnostic design for maximum flexibility
Cons
  • Relatively new library with a smaller ecosystem than LangChain or CrewAI
  • Requires additional setup for sandboxed execution environments
  • Limited built-in tools compared to more mature agent frameworks

Best For

Building intelligent agents that perform web searches and answer queriesAutomating multi-step tasks that require tool use and code generationCreating vision-enabled agents that process images and videosIntegrating multiple LLM providers in a single agent workflowRapidly prototyping and sharing agents on Hugging Face Hub

FAQ

What LLMs are supported by smolagents?
smolagents supports any LLM via Hugging Face InferenceClient (all providers on the Hub), LiteLLM (100+ providers including Anthropic, OpenAI), and OpenAI-compatible servers (e.g., Together AI, OpenRouter). Local models from transformers or ollama are also supported.
Is smolagents secure?
Yes, CodeAgent actions can be executed in sandboxed environments using Blaxel, E2B, Modal, or Docker to prevent unsafe operations.
Can smolagents handle non-text inputs?
Yes, it is modality-agnostic and supports text, vision, video, and even audio inputs.