Go to file
Aymeric 86c8d28830 Update pyproject 2024-12-27 16:46:32 +01:00
docs Pass tests 2024-12-27 16:27:16 +01:00
examples Improve prompts 2024-12-27 15:23:07 +01:00
src/smolagents Update version 2024-12-27 16:36:50 +01:00
tests Pass tests 2024-12-27 16:27:16 +01:00
.gitignore Add build files 2024-12-27 16:42:17 +01:00
.pre-commit-config.yaml Add build files 2024-12-27 16:42:17 +01:00
Dockerfile Add E2B code interpreter 🥳 2024-12-20 16:20:41 +01:00
LICENSE Initial commit 2024-12-05 12:28:04 +01:00
Makefile Uv config 2024-12-11 16:15:49 +01:00
README.md Update readme 2024-12-27 16:39:31 +01:00
e2b.Dockerfile Make RAG example extremely fast with BM25 2024-12-26 16:19:31 +01:00
e2b.toml Add E2B code interpreter 🥳 2024-12-20 16:20:41 +01:00
package-lock.json Add build files 2024-12-27 16:42:17 +01:00
package.json Add build files 2024-12-27 16:42:17 +01:00
pyproject.toml Update pyproject 2024-12-27 16:46:32 +01:00
requirements.in Update readme 2024-12-26 12:10:17 +01:00
server.py another example 2024-12-17 17:01:34 +01:00

README.md

License Documentation GitHub release Contributor Covenant

🤗 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. We kept abstractions to their minimal shape above raw code!

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

🧑‍💻 First-class support for Code Agents, i.e. agents that write their actions in code (as opposed to "agents being used to write code"), read more here.

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

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("What time 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
  • a sandboxed environment using E2B.

How lightweight is it?

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 writing its actions in code snippets, and the more classic ToolCallingAgent that leverage built-in tool calling methods.

Many people ask: 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!

Citing smolagents

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

@Misc{accelerate,
  title =        {`smolagents`: The easiest way to build efficient agentic systems.},
  author =       {Aymeric Roucher and Thomas Wolf and Leandro von Werra and Erik Kaunismäki},
  howpublished = {\url{https://github.com/huggingface/smolagents}},
  year =         {2025}
}