Skip to main content

License Documentation GitHub release Contributor Covenant

Hugging Face mascot as James Bond

smolagents - a smol library to build great agents!

smolagents is a library that enables you to run powerful agents in a few lines of code. It offers:

Simplicity: the logic for agents fits in ~thousand lines of code (see agents.py). We kept abstractions to their minimal shape above raw code!

🧑‍💻 First-class support for Code Agents, i.e. agents that write their actions in code (as opposed to "agents being used to write code"). To make it secure, we support executing in sandboxed environments via E2B.

🤗 Hub integrations: you can share and load Gradio Spaces as tools to/from the Hub, and more is to come!

🌐 Support for any LLM: it supports models hosted on the Hub loaded in their transformers version or through our inference API, but also supports models from OpenAI, Anthropic and many others via our LiteLLM integration.

Full documentation can be found here.

[!NOTE] Check the our launch blog post to learn more about smolagents!

Quick demo

First install the package.

pip install smolagents

Then define your agent, give it the tools it needs and run it!

from smolagents import CodeAgent, DuckDuckGoSearchTool, HfApiModel

agent = CodeAgent(tools=[DuckDuckGoSearchTool()], model=HfApiModel())

agent.run("How many seconds would it take for a leopard at full speed to run through Pont des Arts?")

https://github.com/user-attachments/assets/cd0226e2-7479-4102-aea0-57c22ca47884

Code agents?

In our CodeAgent, the LLM engine writes its actions in code. This approach is demonstrated to work better than the current industry practice of letting the LLM output a dictionary of the tools it wants to calls: uses 30% fewer steps (thus 30% fewer LLM calls) and reaches higher performance on difficult benchmarks. Head to our high-level intro to agents to learn more on that.

Especially, since code execution can be a security concern (arbitrary code execution!), we provide options at runtime:

  • a secure python interpreter to run code more safely in your environment (more secure than raw code execution but still risky)
  • a sandboxed environment using E2B (removes the risk to your own system).

How smol is it really?

We strived to keep abstractions to a strict minimum: the main code in agents.py is only ~1,000 lines of code. Still, we implement several types of agents: CodeAgent writes its actions as Python code snippets, and the more classic ToolCallingAgent leverages built-in tool calling methods.

By the way, why use a framework at all? Well, because a big part of this stuff is non-trivial. For instance, the code agent has to keep a consistent format for code throughout its system prompt, its parser, the execution. So our framework handles this complexity for you. But of course we still encourage you to hack into the source code and use only the bits that you need, to the exclusion of everything else!

How strong are open models for agentic workflows?

We've created CodeAgent instances with some leading models, and compared them on this benchmark that gathers questions from a few different benchmarks to propose a varied blend of challenges.

Find the benchmarking code here for more detail on the agentic setup used, and see a comparison of using LLMs code agents compared to vanilla (spoilers: code agents works better).

benchmark of different models on agentic workflows

This comparison shows that open source models can now take on the best closed models!

Contributing

To contribute, follow our contribution guide.

At any moment, feel welcome to open an issue, citing your exact error traces and package versions if it's a bug. It's often even better to open a PR with your proposed fixes/changes!

To install dev dependencies, run:

pip install -e ".[dev]"

When making changes to the codebase, please check that it follows the repo's code quality requirements by running: To check code quality of the source code:

make quality

If the checks fail, you can run the formatter with:

make style

And commit the changes.

To run tests locally, run this command:

make test

Citing smolagents

If you use smolagents in your publication, please cite it by using the following BibTeX entry.

@Misc{smolagents,
  title =        {`smolagents`: a smol library to build great agentic systems.},
  author =       {Aymeric Roucher and Albert Villanova del Moral and Thomas Wolf and Leandro von Werra and Erik Kaunismäki},
  howpublished = {\url{https://github.com/huggingface/smolagents}},
  year =         {2025}
}

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

smolagents-1.7.0.tar.gz (108.5 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

smolagents-1.7.0-py3-none-any.whl (90.5 kB view details)

Uploaded Python 3

File details

Details for the file smolagents-1.7.0.tar.gz.

File metadata

  • Download URL: smolagents-1.7.0.tar.gz
  • Upload date:
  • Size: 108.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.11.10

File hashes

Hashes for smolagents-1.7.0.tar.gz
Algorithm Hash digest
SHA256 e48a0550734190a752288c408b0b8788aa7553e30d6c50dab7382657e4693a61
MD5 048807e17d4f3fa647f942563ed8401e
BLAKE2b-256 30db3ac5bbff6ad4a5ff3a669446fe8cd5862d7cd1bc13054199c0c6f055e76a

See more details on using hashes here.

File details

Details for the file smolagents-1.7.0-py3-none-any.whl.

File metadata

  • Download URL: smolagents-1.7.0-py3-none-any.whl
  • Upload date:
  • Size: 90.5 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.11.10

File hashes

Hashes for smolagents-1.7.0-py3-none-any.whl
Algorithm Hash digest
SHA256 246096f61177f45d3efd88a28270564f595f905031a19843f5234c1e94b93c01
MD5 782e17c911b767e7cbd1a83b4a30b631
BLAKE2b-256 06ab7a5e1bb38daa3200db57b8592cd9f4692f5e96016fbd9b1813f36edb49cd

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page