1{
2 lib,
3 stdenv,
4 buildPythonPackage,
5 fetchFromGitHub,
6
7 # build-system
8 setuptools,
9
10 # dependencies
11 huggingface-hub,
12 jinja2,
13 pillow,
14 python-dotenv,
15 requests,
16 rich,
17
18 # optional-dependencies
19 # audio
20 soundfile,
21 # bedrock
22 boto3,
23 # docker
24 docker,
25 websocket-client,
26 # gradio
27 gradio,
28 # litellm
29 litellm,
30 # mcp
31 mcp,
32 mcpadapt,
33 # openai
34 openai,
35 # toolkit
36 ddgs,
37 markdownify,
38 # torch
39 numpy,
40 torch,
41 torchvision,
42 # transformers
43 accelerate,
44 transformers,
45
46 # tests
47 ipython,
48 pytest-datadir,
49 pytestCheckHook,
50 wikipedia-api,
51}:
52
53buildPythonPackage rec {
54 pname = "smolagents";
55 version = "1.21.3";
56 pyproject = true;
57
58 src = fetchFromGitHub {
59 owner = "huggingface";
60 repo = "smolagents";
61 tag = "v${version}";
62 hash = "sha256-X9tJfNxF2icULyma0dWIQEllY9oKaCB+MQ4JJTdzhz4=";
63 };
64
65 # TODO: remove at the next release
66 # ImportError: cannot import name 'require_soundfile' from 'transformers.testing_utils'
67 # Caused by: https://github.com/huggingface/transformers/commit/1ecd52e50a31e7c344c32564e0484d7e9a0f2256
68 # Fixed in: https://github.com/huggingface/smolagents/pull/1625
69 postPatch = ''
70 substituteInPlace tests/test_types.py \
71 --replace-fail "require_soundfile" "require_torchcodec"
72 '';
73
74 build-system = [ setuptools ];
75
76 dependencies = [
77 huggingface-hub
78 jinja2
79 pillow
80 python-dotenv
81 requests
82 rich
83 ];
84
85 optional-dependencies = lib.fix (self: {
86 audio = [ soundfile ] ++ self.torch;
87 bedrock = [ boto3 ];
88 docker = [
89 docker
90 websocket-client
91 ];
92 # e2b = [
93 # e2b-code-interpreter
94 # python-dotenv
95 # ];
96 gradio = [ gradio ];
97 litellm = [ litellm ];
98 mcp = [
99 mcp
100 mcpadapt
101 ];
102 # mlx-lm = [ mlx-lm ];
103 openai = [ openai ];
104 # telemetry = [
105 # arize-phoenix
106 # openinference-instrumentation-smolagents
107 # opentelemetry-exporter-otlp
108 # opentelemetry-sdk
109 # ];
110 toolkit = [
111 ddgs
112 markdownify
113 ];
114 torch = [
115 numpy
116 torch
117 torchvision
118 ];
119 transformers = [
120 accelerate
121 transformers
122 ]
123 ++ self.torch;
124 # vision = [
125 # helium
126 # selenium
127 # ];
128 # vllm = [
129 # torch
130 # vllm
131 # ];
132 });
133
134 nativeCheckInputs = [
135 ipython
136 pytest-datadir
137 pytestCheckHook
138 wikipedia-api
139 ]
140 ++ lib.flatten (builtins.attrValues optional-dependencies);
141
142 pythonImportsCheck = [ "smolagents" ];
143
144 disabledTestPaths = [
145 # ImportError: cannot import name 'require_soundfile' from 'transformers.testing_utils'
146 "tests/test_types.py"
147 ];
148
149 disabledTests = [
150 # Missing dependencies
151 "test_cleanup"
152 "test_ddgs_with_kwargs"
153 "test_e2b_executor_instantiation"
154 "test_flatten_messages_as_text_for_all_models"
155 "mcp"
156 "test_import_smolagents_without_extras"
157 "test_vision_web_browser_main"
158 "test_multiple_servers"
159 # Tests require network access
160 "test_agent_type_output"
161 "test_call_different_providers_without_key"
162 "test_can_import_sklearn_if_explicitly_authorized"
163 "test_transformers_message_no_tool"
164 "test_transformers_message_vl_no_tool"
165 "test_transformers_toolcalling_agent"
166 "test_visit_webpage"
167 "test_wikipedia_search"
168 ]
169 ++ lib.optionals stdenv.hostPlatform.isDarwin [
170 # Missing dependencies
171 "test_get_mlx"
172
173 # Fatal Python error: Aborted
174 # thread '<unnamed>' panicked, Attempted to create a NULL object.
175 # duckduckgo_search/duckduckgo_search.py", line 83 in __init__
176 "TestDuckDuckGoSearchTool"
177 "test_init_agent_with_different_toolsets"
178 "test_multiagents_save"
179 "test_new_instance"
180 ];
181
182 __darwinAllowLocalNetworking = true;
183
184 meta = {
185 description = "Barebones library for agents";
186 homepage = "https://github.com/huggingface/smolagents";
187 changelog = "https://github.com/huggingface/smolagents/releases/tag/${src.tag}";
188 license = lib.licenses.asl20;
189 maintainers = with lib.maintainers; [ fab ];
190 };
191}