Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
39 commits
Select commit Hold shift + click to select a range
450934c
Add support for OpenTelemetry instrumentation 📊 (#200)
aymeric-roucher Jan 15, 2025
a22c221
call.func parameter (#194)
nvrxq Jan 15, 2025
7ce27f1
fix: fix string concatenation bug in GradioUI.log_user_message (#199)
kingdomad Jan 15, 2025
06aca55
Fix import from ChatMessage in test_monitoring (#202)
aymeric-roucher Jan 15, 2025
25e00c6
Document OpenTelemetry (#204)
aymeric-roucher Jan 15, 2025
df76ed5
Fix quality in gradio_ui (#206)
albertvillanova Jan 15, 2025
e5c054c
Pre-release fixes (#207)
aymeric-roucher Jan 15, 2025
369d066
Bump version following release of 1.3.0
aymeric-roucher Jan 15, 2025
4c5f1fe
fix typo in building_good_agents.md (#193)
rug Jan 15, 2025
6ef0837
Update README.md (#208)
aymeric-roucher Jan 15, 2025
98c6688
Add pip install for instrumentation
aymeric-roucher Jan 16, 2025
4449c51
Align data types in example benchmark (#205)
albertvillanova Jan 16, 2025
2ae590e
Rename the benchmark dataset split from train to test (#216)
albertvillanova Jan 16, 2025
40087aa
Update mascot
aymeric-roucher Jan 16, 2025
34a718c
Fix mascot positioning
aymeric-roucher Jan 16, 2025
96ebe01
Add license_to_call graphic to documentation index
aymeric-roucher Jan 16, 2025
72b01a9
Restore previous agents.py
aymeric-roucher Jan 16, 2025
2a69f15
Fix vanilla model answer in example benchmark (#219)
albertvillanova Jan 16, 2025
fdf4fe4
Fix additional args in stream_to_gradio (#221)
aymeric-roucher Jan 16, 2025
a4ec1e5
Return textboxes on file upload errors (#214)
stackviolator Jan 16, 2025
a1d8f3c
fix tool example with additional args (#228)
RolandJAAI Jan 16, 2025
b4091cb
Allow passing kwargs to all models (#222)
aymeric-roucher Jan 16, 2025
c56d737
Dead Link to Duck Duck Go search tool (#233)
matterattetatte Jan 16, 2025
d5c2ef4
Add resizeable option to Gradio UI component for better usabilty (#234)
jank Jan 16, 2025
c255c1f
Fix subpackage import vulnerability (#238)
aymeric-roucher Jan 17, 2025
11a738e
Add trust_remote_code arg to TransformersModel (#240)
aymeric-roucher Jan 17, 2025
fabc59a
Fix missing python modules in CodeAgent system prompt (#226)
edbeeching Jan 17, 2025
1f8fd72
Clean makefile, pyproject.toml and CI (#229)
Wauplin Jan 17, 2025
68933e7
Make openai dependency optional (#236)
albertvillanova Jan 17, 2025
d8591dc
Improve OpenAIServerModel by making api_base and api_url optional (wi…
aymeric-roucher Jan 17, 2025
6db7518
Fix style
aymeric-roucher Jan 17, 2025
58b18f5
Remove dependency on _is_package_available from transformers (#247)
albertvillanova Jan 17, 2025
e30ec8a
Set ollama context lenght in example to 8192 to make it work (#252)
RolandJAAI Jan 17, 2025
3e1c979
Add Chinese translations for multi-agent example (#246)
FanwangM Jan 17, 2025
116b12e
chore: unset console width, utilize auto detect feature (#196)
simpletrontdip Jan 17, 2025
d1b8a78
Max length of "print" outputs as a parameter of an agent (#209)
IlyaGusev Jan 17, 2025
7d6599e
docs: small fixes in docs (#245)
MoritzLaurer Jan 17, 2025
a4d029d
add support for MCP Servers tools as `ToolCollection` (#232)
grll Jan 17, 2025
e3ae180
Fixes before release (#254)
aymeric-roucher Jan 17, 2025
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 5 additions & 10 deletions .github/workflows/quality.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,20 +16,15 @@ jobs:
python-version: "3.12"

# Setup venv
# TODO: revisit when https://github.com/astral-sh/uv/issues/1526 is addressed.
- name: Setup venv + uv
run: |
pip install --upgrade uv
uv venv

- name: Install dependencies
run: uv pip install "smolagents[test] @ ."
- run: uv run ruff check tests src # linter
- run: uv run ruff format --check tests src # formatter
run: uv pip install "smolagents[quality] @ ."

# Run type checking at least on smolagents root file to check all modules
# that can be lazy-loaded actually exist.
# - run: uv run mypy src/smolagents/__init__.py --follow-imports=silent --show-traceback

# Run mypy on full package
# - run: uv run mypy src
# Equivalent of "make quality" but step by step
- run: uv run ruff check examples src tests utils # linter
- run: uv run ruff format --check examples src tests utils # formatter
- run: uv run python utils/check_tests_in_ci.py
48 changes: 36 additions & 12 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,7 @@ jobs:
with:
python-version: ${{ matrix.python-version }}


# Setup venv
# TODO: revisit when https://github.com/astral-sh/uv/issues/1526 is addressed.
- name: Setup venv + uv
run: |
pip install --upgrade uv
Expand All @@ -33,33 +31,59 @@ jobs:
run: |
uv pip install "smolagents[test] @ ."

# Run all tests separately for individual feedback
# Use 'if success() || failure()' so that all tests are run even if one failed
# See https://stackoverflow.com/a/62112985
- name: Agent tests
run: |
uv run pytest -sv ./tests/test_agents.py
uv run pytest ./tests/test_agents.py
if: ${{ success() || failure() }}

- name: Default tools tests
run: |
uv run pytest -sv ./tests/test_default_tools.py
uv run pytest ./tests/test_default_tools.py
if: ${{ success() || failure() }}

# - name: Docs tests # Disabled for now (slow test + requires API keys)
# run: |
# uv run pytest ./tests/test_all_docs.py

- name: Final answer tests
run: |
uv run pytest -sv ./tests/test_final_answer.py
uv run pytest ./tests/test_final_answer.py
if: ${{ success() || failure() }}

- name: Models tests
run: |
uv run pytest -sv ./tests/test_models.py
uv run pytest ./tests/test_models.py
if: ${{ success() || failure() }}

- name: Monitoring tests
run: |
uv run pytest -sv ./tests/test_monitoring.py
uv run pytest ./tests/test_monitoring.py
if: ${{ success() || failure() }}

- name: Python interpreter tests
run: |
uv run pytest -sv ./tests/test_python_interpreter.py
uv run pytest ./tests/test_python_interpreter.py
if: ${{ success() || failure() }}

- name: Search tests
run: |
uv run pytest -sv ./tests/test_search.py
uv run pytest ./tests/test_search.py
if: ${{ success() || failure() }}

- name: Tools tests
run: |
uv run pytest -sv ./tests/test_tools.py
uv run pytest ./tests/test_tools.py
if: ${{ success() || failure() }}

- name: Types tests
run: |
uv run pytest -sv ./tests/test_types.py
uv run pytest ./tests/test_types.py
if: ${{ success() || failure() }}

- name: Utils tests
run: |
uv run pytest -sv ./tests/test_utils.py
uv run pytest ./tests/test_utils.py
if: ${{ success() || failure() }}
4 changes: 2 additions & 2 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -91,8 +91,8 @@ happy to make the changes or help you make a contribution if you're interested!

## I want to become a maintainer of the project. How do I get there?

Smolagents is a project led and managed by Hugging Face as an initial fork of Transformers Agents. We are more than
happy to have motivated individuals from other organizations join us as maintainers with the goal of helping Smolagents
smolagents is a project led and managed by Hugging Face. We are more than
happy to have motivated individuals from other organizations join us as maintainers with the goal of helping smolagents
make a dent in the world of Agents.

If you are such an individual (or organization), please reach out to us and let's collaborate.
47 changes: 6 additions & 41 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,53 +1,18 @@
.PHONY: quality style test docs utils

check_dirs := .
check_dirs := examples src tests utils

# Check that source code meets quality standards

extra_quality_checks:
python utils/check_copies.py
python utils/check_dummies.py
python utils/check_repo.py
doc-builder style smolagents docs/source --max_len 119

# this target runs checks on all files
# Check code quality of the source code
quality:
ruff check $(check_dirs)
ruff format --check $(check_dirs)
doc-builder style smolagents docs/source --max_len 119 --check_only
python utils/check_tests_in_ci.py

# Format source code automatically and check is there are any problems left that need manual fixing
# Format source code automatically
style:
ruff check $(check_dirs) --fix
ruff format $(check_dirs)
doc-builder style smolagents docs/source --max_len 119

# Run tests for the library
test_big_modeling:
python -m pytest -s -v ./tests/test_big_modeling.py ./tests/test_modeling_utils.py $(if $(IS_GITHUB_CI),--report-log "$(PYTORCH_VERSION)_big_modeling.log",)

test_core:
python -m pytest -s -v ./tests/ --ignore=./tests/test_examples.py $(if $(IS_GITHUB_CI),--report-log "$(PYTORCH_VERSION)_core.log",)

test_cli:
python -m pytest -s -v ./tests/test_cli.py $(if $(IS_GITHUB_CI),--report-log "$(PYTORCH_VERSION)_cli.log",)


# Since the new version of pytest will *change* how things are collected, we need `deepspeed` to
# run after test_core and test_cli
# Run smolagents tests
test:
$(MAKE) test_core
$(MAKE) test_cli
$(MAKE) test_big_modeling
$(MAKE) test_deepspeed
$(MAKE) test_fsdp

test_examples:
python -m pytest -s -v ./tests/test_examples.py $(if $(IS_GITHUB_CI),--report-log "$(PYTORCH_VERSION)_examples.log",)

# Same as test but used to install only the base dependencies
test_prod:
$(MAKE) test_core

test_rest:
python -m pytest -s -v ./tests/test_examples.py::FeatureExamplesTests $(if $(IS_GITHUB_CI),--report-log "$(PYTORCH_VERSION)_rest.log",)
pytest ./tests/
39 changes: 36 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,10 @@ limitations under the License.
</p>

<h3 align="center">
<p>🤗 smolagents - a smol library to build great agents!</p>
<div style="display:flex;flex-direction:row;">
<img src="https://huggingface.co/datasets/huggingface/documentation-images/resolve/main/smolagents/mascot.png" alt="Hugging Face mascot as James Bond" width=100px>
<p>smolagents - a smol library to build great agents!</p>
</div>
</h3>

`smolagents` is a library that enables you to run powerful agents in a few lines of code. It offers:
Expand Down Expand Up @@ -66,8 +69,8 @@ In our `CodeAgent`, the LLM engine writes its actions in code. This approach is
and [reaches higher performance on difficult benchmarks](https://huggingface.co/papers/2411.01747). Head to [our high-level intro to agents](https://huggingface.co/docs/smolagents/conceptual_guides/intro_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](https://e2b.dev/).
- 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](https://e2b.dev/) (removes the risk to your own system).

## How smol is it really?

Expand All @@ -88,6 +91,36 @@ We've created [`CodeAgent`](https://huggingface.co/docs/smolagents/reference/age

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

## Contributing

To contribute, follow our [contribution guide](https://github.com/huggingface/smolagents/blob/main/CONTRIBUTING.md).

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:
```bash
pytest .
```

## Citing smolagents

If you use `smolagents` in your publication, please cite it by using the following BibTeX entry.
Expand Down
2 changes: 2 additions & 0 deletions docs/source/en/_toctree.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@
sections:
- local: tutorials/building_good_agents
title: ✨ Building good agents
- local: tutorials/inspect_runs
title: 📊 Inspect your agent runs using telemetry
- local: tutorials/tools
title: 🛠️ Tools - in-depth guide
- local: tutorials/secure_code_execution
Expand Down
4 changes: 2 additions & 2 deletions docs/source/en/examples/multiagents.md
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ model_id = "Qwen/Qwen2.5-Coder-32B-Instruct"

## 🔍 Create a web search tool

For web browsing, we can already use our pre-existing [`DuckDuckGoSearchTool`](https://github.com/huggingface/smolagents/blob/main/src/smolagents/default_tools/search.py) tool to provide a Google search equivalent.
For web browsing, we can already use our pre-existing [`DuckDuckGoSearchTool`](https://github.com/huggingface/smolagents/blob/main/src/smolagents/default_tools.py#L151-L176) tool to provide a Google search equivalent.

But then we will also need to be able to peak into the page found by the `DuckDuckGoSearchTool`.
To do so, we could import the library's built-in `VisitWebpageTool`, but we will build it again to see how it's done.
Expand Down Expand Up @@ -196,4 +196,4 @@ Seems like we'll need some sizeable powerplants if the [scaling hypothesis](http

Our agents managed to efficiently collaborate towards solving the task! ✅

💡 You can easily extend this orchestration to more agents: one does the code execution, one the web search, one handles file loadings...
💡 You can easily extend this orchestration to more agents: one does the code execution, one the web search, one handles file loadings...
5 changes: 3 additions & 2 deletions docs/source/en/guided_tour.md
Original file line number Diff line number Diff line change
Expand Up @@ -89,8 +89,9 @@ from smolagents import CodeAgent, LiteLLMModel

model = LiteLLMModel(
model_id="ollama_chat/llama3.2", # This model is a bit weak for agentic behaviours though
api_base="http://localhost:11434", # replace with remote open-ai compatible server if necessary
api_base="http://localhost:11434", # replace with 127.0.0.1:11434 or remote open-ai compatible server if necessary
api_key="YOUR_API_KEY" # replace with API key if necessary
num_ctx=8192 # ollama default is 2048 which will fail horribly. 8192 works for easy tasks, more is better. Check https://huggingface.co/spaces/NyxKrage/LLM-Model-VRAM-Calculator to calculate how much VRAM this will need for the selected model.
)

agent = CodeAgent(tools=[], model=model, add_base_tools=True)
Expand Down Expand Up @@ -336,7 +337,7 @@ from smolagents import (
)

# Import tool from Hub
image_generation_tool = load_tool("m-ric/text-to-image")
image_generation_tool = load_tool("m-ric/text-to-image", trust_remote_code=True)

model = HfApiModel(model_id)

Expand Down
4 changes: 4 additions & 0 deletions docs/source/en/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,10 @@ rendered properly in your Markdown viewer.

# `smolagents`

<div class="flex justify-center">
<img src="https://huggingface.co/datasets/huggingface/documentation-images/resolve/main/smolagents/license_to_call.png" width=100%/>
</div>

This library is the simplest framework out there to build powerful agents! By the way, wtf are "agents"? We provide our definition [in this page](conceptual_guides/intro_agents), where you'll also find tips for when to use them or not (spoilers: you'll often be better off without agents).

This library offers:
Expand Down
18 changes: 16 additions & 2 deletions docs/source/en/reference/agents.md
Original file line number Diff line number Diff line change
Expand Up @@ -136,8 +136,22 @@ messages = [
{"role": "user", "content": "No need to help, take it easy."},
]

model = LiteLLMModel("anthropic/claude-3-5-sonnet-latest", temperature=0.2)
print(model(messages, max_tokens=10))
model = LiteLLMModel("anthropic/claude-3-5-sonnet-latest", temperature=0.2, max_tokens=10)
print(model(messages))
```

[[autodoc]] LiteLLMModel

### OpenAiServerModel

This class lets you call any OpenAIServer compatible model.
Here's how you can set it (you can customise the `api_base` url to point to another server):
```py
from smolagents import OpenAIServerModel

model = OpenAIServerModel(
model_id="gpt-4o",
api_base="https://api.openai.com/v1",
api_key=os.environ["OPENAI_API_KEY"],
)
```
4 changes: 4 additions & 0 deletions docs/source/en/reference/tools.md
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,10 @@ contains the API docs for the underlying classes.

[[autodoc]] VisitWebpageTool

### UserInputTool

[[autodoc]] UserInputTool

## ToolCollection

[[autodoc]] ToolCollection
Expand Down
4 changes: 2 additions & 2 deletions docs/source/en/tutorials/building_good_agents.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ rendered properly in your Markdown viewer.

There's a world of difference between building an agent that works and one that doesn't.
How can we build agents that fall into the latter category?
In this guide, we're going to see best practices for building agents.
In this guide, we're going to talk about best practices for building agents.

> [!TIP]
> If you're new to building agents, make sure to first read the [intro to agents](../conceptual_guides/intro_agents) and the [guided tour of smolagents](../guided_tour).
Expand Down Expand Up @@ -67,7 +67,7 @@ def get_weather_report_at_coordinates(coordinates, date_time):
# Dummy function, returns a list of [temperature in °C, risk of rain on a scale 0-1, wave height in m]
return [28.0, 0.35, 0.85]

def get_coordinates_from_location(location):
def convert_location_to_coordinates(location):
# Returns dummy coordinates
return [3.3, -42.0]

Expand Down
Loading
Loading