Skip to content

🤗 Agents: the simplest building blocks to build and run LLM agents.

License

Notifications You must be signed in to change notification settings

huggingface/agents

Repository files navigation

License Documentation GitHub release Contributor Covenant

Smolagents - build great agents!

Smolagents is a library that enables you to run powerful agents in a few lines of code!

This library 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... it's really easy to power an agent with any LLM.

🧑‍💻 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 agents

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

from smolagents import CodeAgent, DuckDuckGoSearchTool, HfApiEngine

agent = CodeAgent(tools=[DuckDuckGoSearchTool()], llm_engine=HfApiEngine())

agent.run("What time would the world's fastest car take to travel from New York to San Francisco?")

TODO: Add video

Code agents?

We built agents where 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 [./conceptual_guides/intro_agents.md] 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.

How lightweight is it?

We strived to keep abstractions to a strict minimum, with the main code in agents.py being roughly 1,000 lines of code, and still being quite complete, with several types of agents implemented: 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!

About

🤗 Agents: the simplest building blocks to build and run LLM agents.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages