Repolode
huggingface

huggingface/smolagents

A minimal Python library for building AI agents that write and run their actions as Python code.

Stars
29,943
Forks
3,111
Open issues
974
Last commit
14 days ago

What is it?

smolagents is a small Python library for building LLM-powered agents. Its core CodeAgent writes each action as a Python snippet, so tool calls become ordinary function calls and an agent can chain several tools in a single step. The agent logic is kept deliberately compact, with the main agents module at under 1,000 lines, so developers can read and modify the source directly.

The library is model-agnostic. It can run local transformers or Ollama models, models served through Hugging Face inference providers, OpenAI-compatible endpoints, and hundreds of models via LiteLLM, including Azure OpenAI and Amazon Bedrock. Tools can come from MCP servers, LangChain, Hugging Face Spaces, or the Hub, and agents and tools can be pushed to and loaded from the Hub.

Because agent-generated code can be dangerous, the project recommends running it in a sandbox such as E2B, Modal, Blaxel, or Docker. The built-in local Python executor is explicitly not a security boundary. A ToolCallingAgent that uses JSON-style tool calls is also available, and the package ships `smolagent` and `webagent` command-line tools.

Key features

  • 01CodeAgent writes actions as Python code, with tool calls as function calls.
  • 02Supports local transformers and Ollama models, Hugging Face providers, OpenAI-compatible APIs, and LiteLLM.
  • 03Runs generated code in sandboxes such as E2B, Modal, Blaxel, or Docker.
  • 04Imports tools from MCP servers, LangChain, and Hugging Face Spaces.
  • 05Shares agents and tools through the Hugging Face Hub.
  • 06Includes smolagent and webagent command-line interfaces.

Use cases

  • Prototyping an agent that calls several web or API tools in one run.
  • Building a research or browsing assistant that needs multi-step reasoning.
  • Experimenting with open-source models for agentic workflows.
  • Teaching or studying how code-based agents differ from JSON tool-calling agents.

Quick start

  1. 1

    Install the package with the default toolkit

    pip install "smolagents[toolkit]"
  2. 2

    Define a CodeAgent with tools and a model, then run it

Things to know

  • Running agent code safely requires an external sandbox such as E2B, Blaxel, Modal or Docker; the built-in LocalPythonExecutor is not a security boundary.
  • The default demo model is hosted on Hugging Face, so a provider account or API key is typically needed.

Topics

FAQ

What is smolagents?
A minimal Python library for building AI agents that write and run their actions as Python code. smolagents is a small Python library for building LLM-powered agents. Its core CodeAgent writes each action as a Python snippet, so tool calls become ordinary function calls and an agent can chain several tools in a single step. The agent logic is kept deliberately compact, with the main agents module at under 1,000 lines, so developers can read and modify the source directly.
Is smolagents free to use? What license does it have?
smolagents is open source under the Apache-2.0 license. Check the license terms before using it in commercial products.
Is smolagents still maintained?
Actively maintained. The last commit to smolagents was on Oct 6, 2026.
What can I use smolagents for?
Prototyping an agent that calls several web or API tools in one run. Building a research or browsing assistant that needs multi-step reasoning. Experimenting with open-source models for agentic workflows. Teaching or studying how code-based agents differ from JSON tool-calling agents.
How do I install smolagents?
Install the package with the default toolkit: pip install "smolagents[toolkit]" Define a CodeAgent with tools and a model, then run it
Where can I get smolagents?
The source code and installation instructions are on GitHub: https://github.com/huggingface/smolagents

Summary generated by AI from the project's README. GitHub stats refresh daily.

Related projects