
smolagents
Open-source Python library from Hugging Face for agents that act through Python code or JSON tool calls.
smolagents is Hugging Face's open-source Python library for building agents in a few lines of code: CodeAgent writes its actions as Python code, ToolCallingAgent as JSON tool calls. It installs with pip; models on Inference Providers are pay-as-you-go and need an HF token, and a free HF account comes with included credits.
About smolagents
CodeAgent writes each action as a Python snippet that calls tools, so it can combine tools, loop and branch. ToolCallingAgent writes the structured JSON tool calls used by many frameworks and runs no code itself. The guided tour suggests CodeAgent when you need reasoning, chaining or dynamic composition, and ToolCallingAgent for simple, atomic tools where you want high reliability and clear validation.
By default the generated code runs in your local Python environment, where only the tools you provide and a set of predefined safe functions can be called, and imports outside a safe list are blocked unless you authorize them. For more isolation, code can run in a Modal or Blaxel sandbox, on E2B, or in a Docker container.
Tools can come from any MCP server, from LangChain or from a Hub Space, and you can write your own by wrapping a Python function with the tool decorator or by subclassing Tool. Agents and tools can be shared to the Hugging Face Hub and loaded from it.
The library ships command-line utilities, smolagent and webagent, for running agents without boilerplate code, and a GradioUI for submitting tasks to an agent and watching its thought and execution process. A manager agent can call other agents to form hierarchical multi-agent systems, and agents can take vision, video and audio inputs.
Sources: huggingface.co/docs/smolagents/index, /pricing, /docs, /docs/smolagents/guided_tour, /docs/smolagents/installation and /docs/inference-providers/index, read 2026-10-26
smolagents pros and cons
Pros
- The agent logic fits in about a thousand lines of code, with abstractions kept to a minimal shape above raw code.
- Model-agnostic: hosted and local LLMs both work, from Hugging Face Inference Providers and LiteLLM to Transformers and Ollama on your own machine.
- Integrations are optional pip extras, from MCP support and model backends to sandboxes, telemetry and a Gradio UI, and smolagents[all] installs every extra.
- Runs can be inspected afterwards through agent.logs, which stores every step, and the telemetry extra adds monitoring and tracing.
Cons
- Generated code runs locally by default, which the guided tour calls potentially unsecure, and because the model can write arbitrary code the docs warn against adding unsafe imports.
- The guided tour lists the limits of code agents: you must handle syntax errors and exceptions, and outputs are less predictable and more prone to unsafe results.
- Remote sandboxes need setup: Blaxel and E2B each require API keys set as environment variables.
Tagged
- Supports Local Models
- CLI
- Agentic Mode
- Terminal Execution
- Open Source
smolagents alternatives
The closest alternatives to smolagents.
- 01Free →LangGraph
MIT-licensed agent runtime and low-level orchestration framework from LangChain for controllable agents.
- 02Freemium →CrewAI
Open-source Python framework for multi-agent Crews and Flows, plus the CrewAI AMP agent management platform.
- 03Freemium →Agno
Apache 2.0 Python SDK and AgentOS runtime for agents in your own cloud, plus a browser-based control plane.
Related reading
Featured on Vibedonalds
Own smolagents? Add this badge to your site to show you’re listed — and link back to your profile here.
<a href="https://vibedonalds.com/tools/smolagents" target="_blank" rel="noopener nofollow">
<img src="https://vibedonalds.com/badge/featured-on-vibedonalds.svg" alt="smolagents — Featured on Vibedonalds" width="240" height="60" loading="lazy" />
</a>Frequently asked questions
- What is smolagents?
- smolagents is an open-source Python library from Hugging Face for agents that act through Python code or JSON tool calls.
- What platforms does smolagents support?
- smolagents's own site lists it for CLI.
- What are the alternatives to smolagents?
- The closest alternatives to smolagents are LangGraph, CrewAI, Agno.
- What are the downsides of smolagents?
- Generated code runs locally by default, which the guided tour calls potentially unsecure, and because the model can write arbitrary code the docs warn against adding unsafe imports. The guided tour lists the limits of code agents: you must handle syntax errors and exceptions, and outputs are less predictable and more prone to unsafe results. Remote sandboxes need setup: Blaxel and E2B each require API keys set as environment variables.
- How do I install smolagents?
- Run pip install smolagents, or use uv, on Python 3.10 or newer; the docs strongly recommend a virtual environment. Extras add features: smolagents[toolkit] brings default tools such as web search, smolagents[mcp] adds MCP support, smolagents[litellm] adds LiteLLM, and smolagents[all] installs every extra.
- Does smolagents support MCP?
- Yes: the mcp extra adds Model Context Protocol support for external tools and services, and agents can use tools from any MCP server.
- Can smolagents use Ollama or other local models?
- Yes: the guided tour lists Ollama, Transformers and mlx-lm for local runs, and the vllm extra adds vLLM support. Hosted options include Hugging Face Inference Providers, OpenAI and Anthropic through LiteLLM, Azure OpenAI and Amazon Bedrock.
- What is the difference between CodeAgent and ToolCallingAgent?
- CodeAgent generates tool calls as Python code snippets, which makes it more expressive but needs a secure execution environment. ToolCallingAgent writes structured JSON tool calls with strictly validated arguments and no arbitrary code, which the guided tour calls more reliable but less expressive.
- Is smolagents free?
- The docs describe smolagents as an open-source library that installs with pip. If you run models on Hugging Face Inference Providers, they are pay-as-you-go; the pricing page lists PRO at $9 a month with $2 of included inference credits monthly.