Skip to content

Commit 3883aee

Browse files
Merge pull request #14 from huggingface/main
merge main
2 parents d5b32a0 + 68cdf52 commit 3883aee

127 files changed

Lines changed: 9988 additions & 16657 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

.github/workflows/quality.yml

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,9 @@ name: Quality Check
22

33
on: [pull_request]
44

5+
env:
6+
UV_SYSTEM_PYTHON: 1
7+
58
jobs:
69
check_code_quality:
710
runs-on: ubuntu-latest
@@ -16,15 +19,13 @@ jobs:
1619
python-version: "3.12"
1720

1821
# Setup venv
19-
- name: Setup venv + uv
22+
- name: Setup uv
2023
run: |
2124
pip install --upgrade uv
22-
uv venv
2325
2426
- name: Install dependencies
2527
run: uv pip install "smolagents[quality] @ ."
2628

2729
# Equivalent of "make quality" but step by step
28-
- run: uv run ruff check examples src tests utils # linter
29-
- run: uv run ruff format --check examples src tests utils # formatter
30-
- run: uv run python utils/check_tests_in_ci.py
30+
- run: ruff check examples src tests # linter
31+
- run: ruff format --check examples src tests # formatter

.github/workflows/tests.yml

Lines changed: 12 additions & 88 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,13 @@
11
name: Python tests
22

3-
on: [pull_request]
3+
on:
4+
pull_request:
5+
push:
6+
branches:
7+
- ci-*
8+
9+
env:
10+
UV_SYSTEM_PYTHON: 1
411

512
jobs:
613
build-ubuntu:
@@ -21,99 +28,16 @@ jobs:
2128
python-version: ${{ matrix.python-version }}
2229

2330
# Setup venv
24-
- name: Setup venv + uv
31+
- name: Setup uv
2532
run: |
2633
pip install --upgrade uv
27-
uv venv
2834
2935
# Install dependencies
3036
- name: Install dependencies
3137
run: |
3238
uv pip install "smolagents[test] @ ."
3339
34-
# Run all tests separately for individual feedback
35-
# Use 'if success() || failure()' so that all tests are run even if one failed
36-
# See https://stackoverflow.com/a/62112985
37-
- name: Import tests
38-
run: |
39-
uv run pytest ./tests/test_import.py
40-
if: ${{ success() || failure() }}
41-
42-
- name: Agent tests
43-
run: |
44-
uv run pytest ./tests/test_agents.py
45-
if: ${{ success() || failure() }}
46-
47-
- name: Default tools tests
48-
run: |
49-
uv run pytest ./tests/test_default_tools.py
50-
if: ${{ success() || failure() }}
51-
52-
# - name: Docs tests # Disabled for now (slow test + requires API keys)
53-
# run: |
54-
# uv run pytest ./tests/test_all_docs.py
55-
56-
- name: Final answer tests
57-
run: |
58-
uv run pytest ./tests/test_final_answer.py
59-
if: ${{ success() || failure() }}
60-
61-
- name: Models tests
62-
run: |
63-
uv run pytest ./tests/test_models.py
64-
if: ${{ success() || failure() }}
65-
66-
- name: Memory tests
67-
run: |
68-
uv run pytest ./tests/test_memory.py
69-
if: ${{ success() || failure() }}
70-
71-
- name: Monitoring tests
72-
run: |
73-
uv run pytest ./tests/test_monitoring.py
74-
if: ${{ success() || failure() }}
75-
76-
- name: Local Python executor tests
77-
run: |
78-
uv run pytest ./tests/test_local_python_executor.py
79-
if: ${{ success() || failure() }}
80-
81-
- name: E2B executor tests
82-
run: |
83-
uv run pytest ./tests/test_e2b_executor.py
84-
if: ${{ success() || failure() }}
85-
86-
- name: Search tests
87-
run: |
88-
uv run pytest ./tests/test_search.py
89-
if: ${{ success() || failure() }}
90-
91-
- name: Tools tests
92-
run: |
93-
uv run pytest ./tests/test_tools.py
94-
if: ${{ success() || failure() }}
95-
96-
- name: Tool validation tests
97-
run: |
98-
uv run pytest ./tests/test_tool_validation.py
99-
if: ${{ success() || failure() }}
100-
101-
- name: Types tests
102-
run: |
103-
uv run pytest ./tests/test_types.py
104-
if: ${{ success() || failure() }}
105-
106-
- name: Utils tests
107-
run: |
108-
uv run pytest ./tests/test_utils.py
109-
if: ${{ success() || failure() }}
110-
111-
- name: Gradio UI tests
112-
run: |
113-
uv run pytest ./tests/test_gradio_ui.py
114-
if: ${{ success() || failure() }}
115-
116-
- name: Function type hints utils tests
40+
# Run tests
41+
- name: Test with pytest
11742
run: |
118-
uv run pytest ./tests/test_function_type_hints_utils.py
119-
if: ${{ success() || failure() }}
43+
pytest ./tests/

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -150,3 +150,6 @@ archive/
150150
savedir/
151151
output/
152152
tool_output/
153+
154+
# Gradio runtime
155+
.gradio/

Dockerfile

Lines changed: 0 additions & 29 deletions
This file was deleted.

Makefile

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,11 @@
1-
.PHONY: quality style test docs utils
1+
.PHONY: quality style test docs
22

33
check_dirs := examples src tests utils
44

55
# Check code quality of the source code
66
quality:
77
ruff check $(check_dirs)
88
ruff format --check $(check_dirs)
9-
python utils/check_tests_in_ci.py
109

1110
# Format source code automatically
1211
style:

README.md

Lines changed: 34 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -26,23 +26,23 @@ limitations under the License.
2626
<h3 align="center">
2727
<div style="display:flex;flex-direction:row;">
2828
<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>
3030
</div>
3131
</h3>
3232

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

3535
**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!
3636

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.
3838

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!
4040

4141
🌐 **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.
4242

4343
👁️ **Modality-agnostic**: Agents support text, vision, video, even audio inputs! Cf [this tutorial](https://huggingface.co/docs/smolagents/examples/web_browser) for vision.
4444

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.
4646

4747
Full documentation can be found [here](https://huggingface.co/docs/smolagents/index).
4848

@@ -57,17 +57,17 @@ pip install smolagents
5757
```
5858
Then define your agent, give it the tools it needs and run it!
5959
```py
60-
from smolagents import CodeAgent, DuckDuckGoSearchTool, HfApiModel
60+
from smolagents import CodeAgent, DuckDuckGoSearchTool, InferenceClientModel
6161

62-
model = HfApiModel()
62+
model = InferenceClientModel()
6363
agent = CodeAgent(tools=[DuckDuckGoSearchTool()], model=model)
6464

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

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

70-
You can even share your agent to hub:
70+
You can even share your agent to the Hub, as a Space repository:
7171
```py
7272
agent.push_to_hub("m-ric/my_agent")
7373

@@ -77,12 +77,12 @@ agent.push_to_hub("m-ric/my_agent")
7777
Our library is LLM-agnostic: you could switch the example above to any inference provider.
7878

7979
<details>
80-
<summary> <b>HfApiModel, gateway for 4 inference providers</b></summary>
80+
<summary> <b>InferenceClientModel, gateway for all <a href="https://huggingface.co/docs/inference-providers/index">inference providers</a> supported on HF</b></summary>
8181

8282
```py
83-
from smolagents import HfApiModel
83+
from smolagents import InferenceClientModel
8484

85-
model = HfApiModel(
85+
model = InferenceClientModel(
8686
model_id="deepseek-ai/DeepSeek-R1",
8787
provider="together",
8888
)
@@ -95,7 +95,7 @@ model = HfApiModel(
9595
from smolagents import LiteLLMModel
9696

9797
model = LiteLLMModel(
98-
"anthropic/claude-3-5-sonnet-latest",
98+
model_id="anthropic/claude-3-5-sonnet-latest",
9999
temperature=0.2,
100100
api_key=os.environ["ANTHROPIC_API_KEY"]
101101
)
@@ -143,6 +143,18 @@ model = AzureOpenAIServerModel(
143143
)
144144
```
145145
</details>
146+
<details>
147+
<summary> <b>Amazon Bedrock models</b></summary>
148+
149+
```py
150+
import os
151+
from smolagents import AmazonBedrockServerModel
152+
153+
model = AmazonBedrockServerModel(
154+
model_id = os.environ.get("AMAZON_BEDROCK_MODEL_ID")
155+
)
156+
```
157+
</details>
146158

147159
## CLI
148160

@@ -151,7 +163,7 @@ You can run agents from CLI using two commands: `smolagent` and `webagent`.
151163
`smolagent` is a generalist command to run a multi-step `CodeAgent` that can be equipped with various tools.
152164

153165
```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"
155167
```
156168

157169
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
201213

202214
Especially, since code execution can be a security concern (arbitrary code execution!), we provide options at runtime:
203215
- 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).
205217

206218
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`.
207219

@@ -216,14 +228,22 @@ By the way, why use a framework at all? Well, because a big part of this stuff i
216228

217229
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.
218230

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).
220232

221233
<p align="center">
222234
<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>
223235
</p>
224236

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

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+
227247
## Contribute
228248

229249
Everyone is welcome to contribute, get started with our [contribution guide](https://github.com/huggingface/smolagents/blob/main/CONTRIBUTING.md).

SECURITY.md

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
# Security Policy
2+
3+
## Reporting a Vulnerability
4+
5+
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.

docs/README.md

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -121,10 +121,6 @@ Adding a new tutorial or section is done in two steps:
121121

122122
Make sure to put your new file under the proper section. If you have a doubt, feel free to ask in a Github Issue or PR.
123123

124-
### Translating
125-
126-
When translating, refer to the guide at [./TRANSLATING.md](https://github.com/huggingface/smolagents/blob/main/docs/TRANSLATING.md).
127-
128124
### Writing source documentation
129125

130126
Values that should be put in `code` should either be surrounded by backticks: \`like so\`. Note that argument names
@@ -271,4 +267,5 @@ is to be used in inference and also include the expected (ideally sensible)
271267
output.
272268
Often, readers will try out the example before even going through the function
273269
or class definitions. Therefore, it is of utmost importance that the example
274-
works as expected.
270+
works as expected.
271+

docs/source/en/_toctree.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
- local: tutorials/tools
1414
title: 🛠️ Tools - in-depth guide
1515
- local: tutorials/secure_code_execution
16-
title: 🛡️ Secure your code execution with E2B
16+
title: 🛡️ Secure code execution
1717
- local: tutorials/memory
1818
title: 📚 Manage your agent's memory
1919
- title: Conceptual guides
@@ -27,7 +27,7 @@
2727
- local: examples/text_to_sql
2828
title: Self-correcting Text-to-SQL
2929
- local: examples/rag
30-
title: Master you knowledge base with agentic RAG
30+
title: Master your knowledge base with agentic RAG
3131
- local: examples/multiagents
3232
title: Orchestrate a multi-agent system
3333
- local: examples/web_browser

0 commit comments

Comments
 (0)