smolagents
A lightweight open-source Python library by Hugging Face for building powerful AI agents that write and execute actions as Python code snippets in just a few lines of code.
At a Glance
About smolagents
smolagents is a lightweight open-source Python library from Hugging Face that lets you build and run powerful AI agents in just a few lines of code. The core logic fits in under 1,000 lines, keeping abstractions minimal while supporting advanced agentic workflows. It features first-class support for Code Agents that write their actions as Python code rather than JSON blobs, which research shows uses 30% fewer LLM steps and achieves higher performance on difficult benchmarks.
- CodeAgent — the flagship agent type that writes actions as Python code snippets, enabling complex multi-step reasoning and tool use via function calls
- ToolCallingAgent — a standard ReAct-style agent that writes actions as JSON/text blobs for use cases where code execution is not desired
- Model-agnostic support — works with local transformers or Ollama models, Hugging Face inference providers, OpenAI, Anthropic, Azure, Amazon Bedrock, and 100+ LLMs via LiteLLM integration
- Modality-agnostic inputs — agents support text, vision, video, and audio inputs out of the box
- Tool-agnostic ecosystem — use tools from any MCP server, LangChain, Hugging Face Hub Spaces, or define your own custom tools
- Sandboxed code execution — supports E2B, Blaxel, Modal (managed cloud sandboxes), Docker (self-hosted), and Pyodide+Deno WebAssembly for secure agent code execution
- Hub integrations — share and pull tools or entire agents to/from the Hugging Face Hub as Space repositories with a single line of code
- Multi-agent hierarchies — compose multiple agents together for complex, hierarchical agentic workflows
- CLI support — run agents directly from the command line using
smolagent(generalist) orwebagent(web-browsing) commands - MCP server support — load tool collections directly from any MCP server for instant extensibility
To get started, install the package with pip install "smolagents[toolkit]", then instantiate a model, create a CodeAgent with your chosen tools, and call agent.run("your task"). The library is designed to be hackable — you can use only the parts you need and extend or override any component.
Community Discussions
Be the first to start a conversation about smolagents
Share your experience with smolagents, ask questions, or help others learn from your insights.
Pricing
Open Source
Fully free and open-source under the Apache License 2.0. Free to use, modify, and distribute.
- CodeAgent and ToolCallingAgent
- Model-agnostic LLM support
- MCP server tool integration
- Hugging Face Hub sharing
- Multi-agent hierarchies
Capabilities
Key Features
- CodeAgent with Python code actions
- ToolCallingAgent with JSON actions
- Model-agnostic LLM support
- Modality-agnostic inputs (text, vision, video, audio)
- MCP server tool integration
- LangChain tool integration
- Hugging Face Hub sharing
- Multi-agent hierarchies
- Sandboxed code execution (E2B, Blaxel, Modal, Docker, Pyodide+Deno)
- CLI commands (smolagent, webagent)
- LiteLLM integration for 100+ LLMs
- Web search tool
- Vision web browser agent
- Remote code execution support
