Hugging Face just released "smolagents," a stripped-down open-source library that lets developers create AI agents with minimal code.
The library itself is remarkably lightweight, containing just about a thousand lines of code and keeping things as simple as possible. While the design is intentionally minimal, Hugging Face says it still handles all the complex parts of building AI agents.
After installing it through pip (Python's package manager), you can get an agent up and running with just a few lines of code. In their demo, they show an agent using DuckDuckGo to answer complex questions.
The heart of smolagents is the so-called CodeAgent. Instead of following the usual industry practice where AI models output a dictionary of tools to call, CodeAgent lets the AI write Python code directly.
According to Hugging Face, this approach reduces the number of steps by 30 percent and requires fewer AI calls, while still performing better on benchmarks. For those who prefer the traditional approach, there's also a ToolCallingAgent that uses standard tool calling methods.
Flexibility and Security
Smolagents works with a wide range of language models, including those from OpenAI and Anthropic, as well as models hosted on Hugging Face Hub. Developers can connect to these models through the Hub's Transformers library, the HF Inference API, or LiteLLM.
Since letting AI agents generate and run code can be risky, smolagents comes with several security features. Developers can choose between a secure Python interpreter for local execution or use a sandboxed environment with E2B.
The platform also lets users share and load tools through the Hugging Face Hub, with more hub features planned for the future. The entire Smolagents project is available on GitHub. Smolagents joins a growing field of AI agent frameworks, with OpenAI, Microsoft, and AWS all releasing their own takes recently.