You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: README.md
+34-14Lines changed: 34 additions & 14 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -26,23 +26,23 @@ limitations under the License.
26
26
<h3align="center">
27
27
<divstyle="display:flex;flex-direction:row;">
28
28
<img src="https://huggingface.co/datasets/huggingface/documentation-images/resolve/main/smolagents/smolagents.png" alt="Hugging Face mascot as James Bond" width=400px>
29
-
<p>A smol library to build great agents!</p>
29
+
<p>Agents that think in code!</p>
30
30
</div>
31
31
</h3>
32
32
33
33
`smolagents` is a library that enables you to run powerful agents in a few lines of code. It offers:
34
34
35
35
✨ **Simplicity**: the logic for agents fits in ~1,000 lines of code (see [agents.py](https://github.com/huggingface/smolagents/blob/main/src/smolagents/agents.py)). We kept abstractions to their minimal shape above raw code!
36
36
37
-
🧑💻 **First-class support for Code Agents**. Our [`CodeAgent`](https://huggingface.co/docs/smolagents/reference/agents#smolagents.CodeAgent) writes its actions in code (as opposed to "agents being used to write code"). To make it secure, we support executing in sandboxed environments via [E2B](https://e2b.dev/).
37
+
🧑💻 **First-class support for Code Agents**. Our [`CodeAgent`](https://huggingface.co/docs/smolagents/reference/agents#smolagents.CodeAgent) writes its actions in code (as opposed to "agents being used to write code"). To make it secure, we support executing in sandboxed environments via [E2B](https://e2b.dev/) or via Docker.
38
38
39
-
🤗 **Hub integrations**: you can [share/pull tools to/from the Hub](https://huggingface.co/docs/smolagents/reference/tools#smolagents.Tool.from_hub), and more is to come!
39
+
🤗 **Hub integrations**: you can [share/pull tools or agents to/from the Hub](https://huggingface.co/docs/smolagents/reference/tools#smolagents.Tool.from_hub) for instant sharing of the most efficient agents!
40
40
41
41
🌐 **Model-agnostic**: smolagents supports any LLM. It can be a local `transformers` or `ollama` model, one of [many providers on the Hub](https://huggingface.co/blog/inference-providers), or any model from OpenAI, Anthropic and many others via our [LiteLLM](https://www.litellm.ai/) integration.
42
42
43
43
👁️ **Modality-agnostic**: Agents support text, vision, video, even audio inputs! Cf [this tutorial](https://huggingface.co/docs/smolagents/examples/web_browser) for vision.
44
44
45
-
🛠️ **Tool-agnostic**: you can use tools from [LangChain](https://huggingface.co/docs/smolagents/reference/tools#smolagents.Tool.from_langchain), [Anthropic's MCP](https://huggingface.co/docs/smolagents/reference/tools#smolagents.ToolCollection.from_mcp), you can even use a [Hub Space](https://huggingface.co/docs/smolagents/reference/tools#smolagents.Tool.from_space) as a tool.
45
+
🛠️ **Tool-agnostic**: you can use tools from [LangChain](https://huggingface.co/docs/smolagents/reference/tools#smolagents.Tool.from_langchain), [MCP](https://huggingface.co/docs/smolagents/reference/tools#smolagents.ToolCollection.from_mcp), you can even use a [Hub Space](https://huggingface.co/docs/smolagents/reference/tools#smolagents.Tool.from_space) as a tool.
46
46
47
47
Full documentation can be found [here](https://huggingface.co/docs/smolagents/index).
48
48
@@ -57,17 +57,17 @@ pip install smolagents
57
57
```
58
58
Then define your agent, give it the tools it needs and run it!
59
59
```py
60
-
from smolagents import CodeAgent, DuckDuckGoSearchTool, HfApiModel
60
+
from smolagents import CodeAgent, DuckDuckGoSearchTool, InferenceClientModel
Our library is LLM-agnostic: you could switch the example above to any inference provider.
78
78
79
79
<details>
80
-
<summary> <b>HfApiModel, gateway for 4 inference providers</b></summary>
80
+
<summary> <b>InferenceClientModel, gateway for all <ahref="https://huggingface.co/docs/inference-providers/index">inference providers</a> supported on HF</b></summary>
81
81
82
82
```py
83
-
from smolagents importHfApiModel
83
+
from smolagents importInferenceClientModel
84
84
85
-
model =HfApiModel(
85
+
model =InferenceClientModel(
86
86
model_id="deepseek-ai/DeepSeek-R1",
87
87
provider="together",
88
88
)
@@ -95,7 +95,7 @@ model = HfApiModel(
95
95
from smolagents import LiteLLMModel
96
96
97
97
model = LiteLLMModel(
98
-
"anthropic/claude-3-5-sonnet-latest",
98
+
model_id="anthropic/claude-3-5-sonnet-latest",
99
99
temperature=0.2,
100
100
api_key=os.environ["ANTHROPIC_API_KEY"]
101
101
)
@@ -143,6 +143,18 @@ model = AzureOpenAIServerModel(
@@ -151,7 +163,7 @@ You can run agents from CLI using two commands: `smolagent` and `webagent`.
151
163
`smolagent` is a generalist command to run a multi-step `CodeAgent` that can be equipped with various tools.
152
164
153
165
```bash
154
-
smolagent "Plan a trip to Tokyo, Kyoto and Osaka between Mar 28 and Apr 7." --model-type "HfApiModel" --model-id "Qwen/Qwen2.5-Coder-32B-Instruct" --imports "pandas numpy" --tools "web_search"
166
+
smolagent "Plan a trip to Tokyo, Kyoto and Osaka between Mar 28 and Apr 7." --model-type "InferenceClientModel" --model-id "Qwen/Qwen2.5-Coder-32B-Instruct" --imports "pandas numpy" --tools "web_search"
155
167
```
156
168
157
169
Meanwhile `webagent` is a specific web-browsing agent using [helium](https://github.com/mherrmann/helium) (read more [here](https://github.com/huggingface/smolagents/blob/main/src/smolagents/vision_web_browser.py)).
@@ -201,7 +213,7 @@ Writing actions as code snippets is demonstrated to work better than the current
201
213
202
214
Especially, since code execution can be a security concern (arbitrary code execution!), we provide options at runtime:
203
215
- a secure python interpreter to run code more safely in your environment (more secure than raw code execution but still risky)
204
-
- a sandboxed environment using [E2B](https://e2b.dev/) (removes the risk to your own system).
216
+
- a sandboxed environment using [E2B](https://e2b.dev/)or Docker (removes the risk to your own system).
205
217
206
218
On top of this [`CodeAgent`](https://huggingface.co/docs/smolagents/reference/agents#smolagents.CodeAgent) class, we still support the standard [`ToolCallingAgent`](https://huggingface.co/docs/smolagents/reference/agents#smolagents.ToolCallingAgent) that writes actions as JSON/text blobs. But we recommend always using `CodeAgent`.
207
219
@@ -216,14 +228,22 @@ By the way, why use a framework at all? Well, because a big part of this stuff i
216
228
217
229
We've created [`CodeAgent`](https://huggingface.co/docs/smolagents/reference/agents#smolagents.CodeAgent) instances with some leading models, and compared them on [this benchmark](https://huggingface.co/datasets/m-ric/agents_medium_benchmark_2) that gathers questions from a few different benchmarks to propose a varied blend of challenges.
218
230
219
-
[Find the benchmarking code here](https://github.com/huggingface/smolagents/blob/main/examples/benchmark.ipynb) 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).
231
+
[Find the benchmarking code here](https://github.com/huggingface/smolagents/blob/main/examples/smolagents_benchmark/run.py) 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).
220
232
221
233
<palign="center">
222
234
<img src="https://huggingface.co/datasets/huggingface/documentation-images/resolve/main/smolagents/benchmark_code_agents.jpeg" alt="benchmark of different models on agentic workflows. Open model DeepSeek-R1 beats closed-source models." width=60% max-width=500px>
223
235
</p>
224
236
225
237
This comparison shows that open-source models can now take on the best closed models!
226
238
239
+
## Security
240
+
241
+
Security is a critical consideration when working with code-executing agents. Our library provides:
242
+
- Sandboxed execution options using [E2B](https://e2b.dev/) or Docker
243
+
- Best practices for running agent code securely
244
+
245
+
For security policies, vulnerability reporting, and more information on secure agent execution, please see our [Security Policy](SECURITY.md).
246
+
227
247
## Contribute
228
248
229
249
Everyone is welcome to contribute, get started with our [contribution guide](https://github.com/huggingface/smolagents/blob/main/CONTRIBUTING.md).
To report a security vulnerability, please contact: security@huggingface.co
6
+
7
+
## Learning More About Security
8
+
9
+
To learn more about running agents more securely, please see the [Secure Code Execution tutorial](docs/source/en/tutorials/secure_code_execution.mdx) which covers sandboxing with E2B and Docker.
0 commit comments