1{
2 lib,
3 stdenv,
4 accelerate,
5 buildPythonPackage,
6 boto3,
7 docker,
8 duckduckgo-search,
9 fetchFromGitHub,
10 gradio,
11 huggingface-hub,
12 jinja2,
13 ipython,
14 litellm,
15 markdownify,
16 mcp,
17 mcpadapt,
18 openai,
19 pandas,
20 pillow,
21 pytest-datadir,
22 pytestCheckHook,
23 python-dotenv,
24 requests,
25 rich,
26 setuptools,
27 soundfile,
28 torch,
29 torchvision,
30 transformers,
31 websocket-client,
32 wikipedia-api,
33}:
34
35buildPythonPackage rec {
36 pname = "smolagents";
37 version = "1.17.0";
38 pyproject = true;
39
40 src = fetchFromGitHub {
41 owner = "huggingface";
42 repo = "smolagents";
43 tag = "v${version}";
44 hash = "sha256-BMyLN8eNGBhywpN/EEE8hFf4Wb5EDpZvqBbX0ojRYec=";
45 };
46
47 build-system = [ setuptools ];
48
49 pythonRelaxDeps = [ "pillow" ];
50
51 dependencies = [
52 duckduckgo-search
53 huggingface-hub
54 jinja2
55 markdownify
56 pandas
57 pillow
58 python-dotenv
59 requests
60 rich
61 ];
62
63 optional-dependencies = {
64 audio = [ soundfile ];
65 bedrock = [ boto3 ];
66 docker = [
67 docker
68 websocket-client
69 ];
70 # e2b = [
71 # e2b-code-interpreter
72 # python-dotenv
73 # ];
74 gradio = [ gradio ];
75 litellm = [ litellm ];
76 mcp = [
77 mcp
78 mcpadapt
79 ];
80 # mlx-lm = [ mlx-lm ];
81 openai = [ openai ];
82 # telemetry = [
83 # arize-phoenix
84 # openinference-instrumentation-smolagents
85 # opentelemetry-exporter-otlp
86 # opentelemetry-sdk
87 # ];
88 torch = [
89 torch
90 torchvision
91 ];
92 transformers = [
93 accelerate
94 transformers
95 ];
96 # vision = [
97 # helium
98 # selenium
99 # ];
100 # vllm = [
101 # torch
102 # vllm
103 # ];
104 };
105
106 nativeCheckInputs = [
107 ipython
108 pytest-datadir
109 pytestCheckHook
110 wikipedia-api
111 ] ++ lib.flatten (builtins.attrValues optional-dependencies);
112
113 pythonImportsCheck = [ "smolagents" ];
114
115 disabledTests =
116 [
117 # Missing dependencies
118 "test_ddgs_with_kwargs"
119 "test_e2b_executor_instantiation"
120 "test_flatten_messages_as_text_for_all_models"
121 "mcp"
122 "test_import_smolagents_without_extras"
123 "test_vision_web_browser_main"
124 "test_multiple_servers"
125 # Tests require network access
126 "test_agent_type_output"
127 "test_call_different_providers_without_key"
128 "test_can_import_sklearn_if_explicitly_authorized"
129 "test_transformers_message_no_tool"
130 "test_transformers_message_vl_no_tool"
131 "test_transformers_toolcalling_agent"
132 "test_visit_webpage"
133 "test_wikipedia_search"
134 ]
135 ++ lib.optionals stdenv.isDarwin [
136 # Missing dependencies
137 "test_get_mlx"
138
139 # Fatal Python error: Aborted
140 # thread '<unnamed>' panicked, Attempted to create a NULL object.
141 # duckduckgo_search/duckduckgo_search.py", line 83 in __init__
142 "TestDuckDuckGoSearchTool"
143 "test_init_agent_with_different_toolsets"
144 "test_multiagents_save"
145 "test_new_instance"
146 ];
147
148 __darwinAllowLocalNetworking = true;
149
150 meta = {
151 description = "Barebones library for agents";
152 homepage = "https://github.com/huggingface/smolagents";
153 changelog = "https://github.com/huggingface/smolagents/releases/tag/${src.tag}";
154 license = lib.licenses.asl20;
155 maintainers = with lib.maintainers; [ fab ];
156 };
157}