1{
2 lib,
3 stdenv,
4 accelerate,
5 buildPythonPackage,
6 docker,
7 duckduckgo-search,
8 fetchFromGitHub,
9 gradio,
10 huggingface-hub,
11 jinja2,
12 ipython,
13 litellm,
14 markdownify,
15 mcp,
16 mcpadapt,
17 openai,
18 pandas,
19 pillow,
20 pytest-datadir,
21 pytestCheckHook,
22 python-dotenv,
23 requests,
24 rich,
25 setuptools,
26 soundfile,
27 torch,
28 torchvision,
29 transformers,
30 websocket-client,
31 wikipedia-api,
32}:
33
34buildPythonPackage rec {
35 pname = "smolagents";
36 version = "1.13.0";
37 pyproject = true;
38
39 src = fetchFromGitHub {
40 owner = "huggingface";
41 repo = "smolagents";
42 tag = "v${version}";
43 hash = "sha256-LZW2MsBowr2ttl3V5J3AlIxZijo++DwT02gBVaXXBXs=";
44 };
45
46 build-system = [ setuptools ];
47
48 pythonRelaxDeps = [
49 "pillow"
50 ];
51
52 dependencies = [
53 duckduckgo-search
54 huggingface-hub
55 jinja2
56 markdownify
57 pandas
58 pillow
59 python-dotenv
60 requests
61 rich
62 ];
63
64 optional-dependencies = {
65 audio = [ soundfile ];
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 "test_from_mcp"
122 "test_import_smolagents_without_extras"
123 "test_vision_web_browser_main"
124 # Tests require network access
125 "test_agent_type_output"
126 "test_call_different_providers_without_key"
127 "test_can_import_sklearn_if_explicitly_authorized"
128 "test_transformers_message_no_tool"
129 "test_transformers_message_vl_no_tool"
130 "test_transformers_toolcalling_agent"
131 "test_visit_webpage"
132 "test_wikipedia_search"
133 ]
134 ++ lib.optionals stdenv.isDarwin [
135 # Missing dependencies
136 "test_get_mlx"
137
138 # Fatal Python error: Aborted
139 # thread '<unnamed>' panicked, Attempted to create a NULL object.
140 # duckduckgo_search/duckduckgo_search.py", line 83 in __init__
141 "TestDuckDuckGoSearchTool"
142 "test_init_agent_with_different_toolsets"
143 "test_multiagents_save"
144 "test_new_instance"
145 ];
146
147 __darwinAllowLocalNetworking = true;
148
149 meta = {
150 description = "Barebones library for agents";
151 homepage = "https://github.com/huggingface/smolagents";
152 changelog = "https://github.com/huggingface/smolagents/releases/tag/${src.tag}";
153 license = lib.licenses.asl20;
154 maintainers = with lib.maintainers; [ fab ];
155 };
156}