Debuly
smolagents logo

smolagents

Hugging Face's minimal open-source Python library for building agents that write their actions as code.

Open source

What is smolagents?

smolagents is an open-source Python library from Hugging Face for building and running AI agents in a few lines of code. Its core idea is the CodeAgent, which writes each action as Python so it can nest function calls, loop and use conditionals when calling tools, rather than emitting JSON that has to be parsed. A ToolCallingAgent is also included for teams that prefer JSON or text-based tool calls. The agent logic fits in roughly a thousand lines, and abstractions are kept thin. To run generated code more safely it can execute inside Modal, Blaxel, E2B or Docker sandboxes. It works with any model, including Hugging Face Inference Providers, OpenAI and Anthropic through LiteLLM, and local models via Transformers or Ollama. Tools can come from MCP servers, LangChain or Hub Spaces. The library is free; hosted inference through Hugging Face is billed separately.

Use cases

  • Build a code-writing agent in Python
  • Give an LLM web search as a tool
  • Run agent code inside a sandbox
  • Use MCP server tools in an agent
  • Share agents and tools on the Hub
  • Prototype agents with a local model

Who it's for

  • Python developers
  • AI engineers
  • Researchers
  • Students learning agents

Why use smolagents

  • A very small codebase makes the framework easy to read, adapt and debug.
  • Code actions compose naturally, so one step can combine several tool calls with loops and conditions.
  • Switching between hosted, API and local models needs only a different model class.
  • Sandbox options let you run generated code away from your own machine.
  • Hub integration lets you publish and reuse tools and agents as Gradio Spaces.

smolagents features

  • CodeAgent that writes actions as Python
  • ToolCallingAgent for JSON or text tool calls
  • Sandboxed execution via Modal, Blaxel, E2B or Docker
  • Model-agnostic through Inference Providers, LiteLLM, Transformers and Ollama
  • Vision, video and audio inputs
  • Tools from MCP servers, LangChain or Hub Spaces
  • Share agents and tools on the Hugging Face Hub
  • smolagent and webagent command-line tools
  • Roughly a thousand lines of core agent logic

smolagents integrations

  • Hugging Face Hub
  • Modal
  • Blaxel
  • E2B
  • Docker
  • LiteLLM
  • OpenAI
  • Anthropic
  • Ollama
  • LangChain
  • Gradio

How to get started with smolagents

  1. Install it with pip install smolagents[toolkit] to get default tools like web search.
  2. Create a model object such as InferenceClientModel, LiteLLMModel or TransformersModel.
  3. Create a CodeAgent with a list of tools and your chosen model.
  4. Call agent.run with a task and the agent plans, writes code and calls tools step by step.
  5. Add a sandbox or share the finished agent to the Hub when ready.

smolagents limitations

  • Best for lightweight agents with straightforward logic
  • Code execution needs a sandbox such as Docker or E2B for safety
  • Hosted inference through Hugging Face is billed separately
  • Installing from source is required for the main branch docs

smolagents pricing

smolagents is open source, so you can use and self-host it for free.

Prices can change and may vary by country or exclude tax. Check the official pricing page.

smolagents alternatives

The main smolagents alternatives listed on Debuly are LangGraph, CrewAI, AutoGen, Pydantic AI, OpenAI Agents SDK and LlamaIndex. The table compares pricing and platforms; order is A–Z.

smolagents compared with its alternatives
ToolPricingStarting pricePlatforms
smolagentsOpen source—CLI, Self-hosted
AutoGenOpen source—API, CLI
CrewAIOpen source—Web, API, CLI, Self-hosted
LangGraphOpen source—Self-hosted, Web, API
LlamaIndexFreemium$50/moWeb, API, Self-hosted
OpenAI Agents SDKOpen source—Python, macOS, Linux, Windows
Pydantic AIOpen source—API, CLI, Self-hosted
  1. AutoGen

    Microsoft's MIT-licensed Python and .NET framework for multi-agent AI apps, now archived; new projects are pointed to Microsoft Agent Framework.

  2. CrewAI

    Multi-agent framework and platform for building AI agent crews in Python or a visual editor, then deploying and monitoring them.

  3. LangGraph

    Low-level open-source orchestration framework and runtime for building stateful, long-running AI agents as graphs.

  4. LlamaIndex

    Open-source framework plus the LlamaParse platform for parsing, extracting and indexing documents so LLM apps can use them.

  5. OpenAI Agents SDK

    Open-source Python framework for building multi-agent workflows with tools, handoffs, guardrails, tracing, sandboxes and voice agents.

  6. Pydantic AI

    A type-safe, model-agnostic Python framework for building agents and LLM applications, from the team behind Pydantic.

smolagents FAQ

How much does smolagents cost?

The library itself is free and open source. Costs come from the model you choose: hosted inference through Hugging Face Inference Providers is pay-as-you-go, while local models run on your own hardware.

Is smolagents open source?

Yes. The documentation describes it as an open-source Python library, installable with pip.

Which models does smolagents support?

Any LLM: models on the Hub through Inference Providers, OpenAI, Anthropic and others through LiteLLM, and local models through Transformers or Ollama.

What is the difference between CodeAgent and ToolCallingAgent?

CodeAgent writes its actions as Python code, while ToolCallingAgent uses the usual JSON or text-based tool calls.

How do I run agent code safely?

smolagents supports executing generated code in sandboxed environments through Modal, Blaxel, E2B or Docker.

Can smolagents use MCP tools?

Yes. Tools can come from any MCP server, from LangChain, or from a Hub Space.

What are alternatives to smolagents?

Other agent frameworks include LangGraph, CrewAI, AutoGen, PydanticAI and the OpenAI Agents SDK.

Sources & verification

Facts on this page come from the official sources below, each with the date we read it. Written by Debuly; the vendor did not review this page.

Image credits

  • Logo: from huggingface.co · fetched · Vendor trademark, used only to identify the product; removed on request
  • Cover: none collected yet, so a generated tile is shown.

Spot an error? Report an issue with this listing. We also remove a logo or image on the owner's request.