m-ric HF Staff commited on
Commit
a0c733d
Β·
verified Β·
1 Parent(s): 57650b8

Update README.md

Browse files
Files changed (1) hide show
  1. README.md +14 -78
README.md CHANGED
@@ -6,13 +6,13 @@ colorTo: pink
6
  sdk: static
7
  pinned: false
8
  ---
9
- # `smolagents`
 
10
 
11
  <div class="flex justify-center">
12
  <img src="https://huggingface.co/datasets/huggingface/documentation-images/resolve/main/smolagents/license_to_call.png" style="max-width:700px"/>
13
  </div>
14
 
15
- ## What is smolagents?
16
 
17
  `smolagents` is an open-source Python library designed to make it extremely easy to build and run agents using just a few lines of code.
18
 
@@ -20,114 +20,50 @@ Key features of `smolagents` include:
20
 
21
  ✨ **Simplicity**: The logic for agents fits in ~thousand lines of code. We kept abstractions to their minimal shape above raw code!
22
 
23
- πŸ§‘β€πŸ’» **First-class support for Code Agents**: [`CodeAgent`](reference/agents#smolagents.CodeAgent) writes its actions in code (as opposed to "agents being used to write code") to invoke tools or perform computations, enabling natural composability (function nesting, loops, conditionals). To make it secure, we support [executing in sandboxed environment](tutorials/secure_code_execution) via [E2B](https://e2b.dev/) or via Docker.
24
 
25
- πŸ“‘ **Common Tool-Calling Agent Support**: In addition to CodeAgents, [`ToolCallingAgent`](reference/agents#smolagents.ToolCallingAgent) supports usual JSON/text-based tool-calling for scenarios where that paradigm is preferred.
26
 
27
  πŸ€— **Hub integrations**: Seamlessly share and load agents and tools to/from the Hub as Gradio Spaces.
28
 
29
  🌐 **Model-agnostic**: Easily integrate any large language model (LLM), whether it's hosted on the Hub via [Inference providers](https://huggingface.co/docs/inference-providers/index), accessed via APIs such as OpenAI, Anthropic, or many others via LiteLLM integration, or run locally using Transformers or Ollama. Powering an agent with your preferred LLM is straightforward and flexible.
30
 
31
- πŸ‘οΈ **Modality-agnostic**: Beyond text, agents can handle vision, video, and audio inputs, broadening the range of possible applications. Check out [this tutorial](examples/web_browser) for vision.
32
 
33
- πŸ› οΈ **Tool-agnostic**: You can use tools from any [MCP server](reference/tools#smolagents.ToolCollection.from_mcp), from [LangChain](reference/tools#smolagents.Tool.from_langchain), you can even use a [Hub Space](reference/tools#smolagents.Tool.from_space) as a tool.
34
 
35
  πŸ’» **CLI Tools**: Comes with command-line utilities (smolagent, webagent) for quickly running agents without writing boilerplate code.
36
 
37
- ## Quickstart
38
-
39
- [[open-in-colab]]
40
 
41
  Get started with smolagents in just a few minutes! This guide will show you how to create and run your first agent.
42
 
43
- ### Installation
 
 
44
 
45
- Install smolagents with pip:
46
 
47
  ```bash
48
  pip install smolagents[toolkit] # Includes default tools like web search
49
  ```
50
 
51
- ### Create Your First Agent
52
-
53
- Here's a minimal example to create and run an agent:
54
-
55
  ```python
56
- from smolagents import CodeAgent, InferenceClientModel
57
 
58
  # Initialize a model (using Hugging Face Inference API)
59
  model = InferenceClientModel() # Uses a default model
60
 
61
  # Create an agent with no tools
62
- agent = CodeAgent(tools=[], model=model)
63
-
64
- # Run the agent with a task
65
- result = agent.run("Calculate the sum of numbers from 1 to 10")
66
- print(result)
67
- ```
68
-
69
- That's it! Your agent will use Python code to solve the task and return the result.
70
-
71
- ### Adding Tools
72
-
73
- Let's make our agent more capable by adding some tools:
74
-
75
- ```python
76
- from smolagents import CodeAgent, InferenceClientModel, DuckDuckGoSearchTool
77
-
78
- model = InferenceClientModel()
79
  agent = CodeAgent(
80
  tools=[DuckDuckGoSearchTool()],
81
  model=model,
82
  )
83
 
84
- # Now the agent can search the web!
85
  result = agent.run("What is the current weather in Paris?")
86
  print(result)
87
  ```
88
 
89
- ### Using Different Models
90
-
91
- You can use various models with your agent:
92
-
93
- ```python
94
- # Using a specific model from Hugging Face
95
- model = InferenceClientModel(model_id="meta-llama/Llama-2-70b-chat-hf")
96
-
97
- # Using OpenAI/Anthropic (requires smolagents[litellm])
98
- from smolagents import LiteLLMModel
99
- model = LiteLLMModel(model_id="gpt-4")
100
-
101
- # Using local models (requires smolagents[transformers])
102
- from smolagents import TransformersModel
103
- model = TransformersModel(model_id="meta-llama/Llama-2-7b-chat-hf")
104
- ```
105
 
106
- ## Next Steps
107
-
108
- - Learn how to set up smolagents with various models and tools in the [Installation Guide](installation)
109
- - Check out the [Guided Tour](guided_tour) for more advanced features
110
- - Learn about [building custom tools](tutorials/tools)
111
- - Explore [secure code execution](tutorials/secure_code_execution)
112
- - See how to create [multi-agent systems](tutorials/building_good_agents)
113
-
114
- <div class="mt-10">
115
- <div class="w-full flex flex-col space-y-4 md:space-y-0 md:grid md:grid-cols-2 md:gap-y-4 md:gap-x-5">
116
- <a class="!no-underline border dark:border-gray-700 p-5 rounded-lg shadow hover:shadow-lg" href="./guided_tour"
117
- ><div class="w-full text-center bg-gradient-to-br from-blue-400 to-blue-500 rounded-lg py-1.5 font-semibold mb-5 text-white text-lg leading-relaxed">Guided tour</div>
118
- <p class="text-gray-700">Learn the basics and become familiar with using Agents. Start here if you are using Agents for the first time!</p>
119
- </a>
120
- <a class="!no-underline border dark:border-gray-700 p-5 rounded-lg shadow hover:shadow-lg" href="./examples/text_to_sql"
121
- ><div class="w-full text-center bg-gradient-to-br from-indigo-400 to-indigo-500 rounded-lg py-1.5 font-semibold mb-5 text-white text-lg leading-relaxed">How-to guides</div>
122
- <p class="text-gray-700">Practical guides to help you achieve a specific goal: create an agent to generate and test SQL queries!</p>
123
- </a>
124
- <a class="!no-underline border dark:border-gray-700 p-5 rounded-lg shadow hover:shadow-lg" href="./conceptual_guides/intro_agents"
125
- ><div class="w-full text-center bg-gradient-to-br from-pink-400 to-pink-500 rounded-lg py-1.5 font-semibold mb-5 text-white text-lg leading-relaxed">Conceptual guides</div>
126
- <p class="text-gray-700">High-level explanations for building a better understanding of important topics.</p>
127
- </a>
128
- <a class="!no-underline border dark:border-gray-700 p-5 rounded-lg shadow hover:shadow-lg" href="./tutorials/building_good_agents"
129
- ><div class="w-full text-center bg-gradient-to-br from-purple-400 to-purple-500 rounded-lg py-1.5 font-semibold mb-5 text-white text-lg leading-relaxed">Tutorials</div>
130
- <p class="text-gray-700">Horizontal tutorials that cover important aspects of building agents.</p>
131
- </a>
132
- </div>
133
- </div>
 
6
  sdk: static
7
  pinned: false
8
  ---
9
+
10
+ ## `smolagents`
11
 
12
  <div class="flex justify-center">
13
  <img src="https://huggingface.co/datasets/huggingface/documentation-images/resolve/main/smolagents/license_to_call.png" style="max-width:700px"/>
14
  </div>
15
 
 
16
 
17
  `smolagents` is an open-source Python library designed to make it extremely easy to build and run agents using just a few lines of code.
18
 
 
20
 
21
  ✨ **Simplicity**: The logic for agents fits in ~thousand lines of code. We kept abstractions to their minimal shape above raw code!
22
 
23
+ πŸ§‘β€πŸ’» **First-class support for Code Agents**: `CodeAgent` writes its actions in code (as opposed to "agents being used to write code") to invoke tools or perform computations, enabling natural composability (function nesting, loops, conditionals). To make it secure, we support [executing in sandboxed environment](tutorials/secure_code_execution) via [E2B](https://e2b.dev/) or via Docker.
24
 
25
+ πŸ“‘ **Common Tool-Calling Agent Support**: In addition to CodeAgents, `ToolCallingAgent` supports usual JSON/text-based tool-calling for scenarios where that paradigm is preferred.
26
 
27
  πŸ€— **Hub integrations**: Seamlessly share and load agents and tools to/from the Hub as Gradio Spaces.
28
 
29
  🌐 **Model-agnostic**: Easily integrate any large language model (LLM), whether it's hosted on the Hub via [Inference providers](https://huggingface.co/docs/inference-providers/index), accessed via APIs such as OpenAI, Anthropic, or many others via LiteLLM integration, or run locally using Transformers or Ollama. Powering an agent with your preferred LLM is straightforward and flexible.
30
 
31
+ πŸ‘οΈ **Modality-agnostic**: Beyond text, agents can handle vision, video, and audio inputs, broadening the range of possible applications.
32
 
33
+ πŸ› οΈ **Tool-agnostic**: You can use tools from any MCP server, you can even use a Hub Space as a tool.
34
 
35
  πŸ’» **CLI Tools**: Comes with command-line utilities (smolagent, webagent) for quickly running agents without writing boilerplate code.
36
 
 
 
 
37
 
38
  Get started with smolagents in just a few minutes! This guide will show you how to create and run your first agent.
39
 
40
+ ### Run Your First Agent
41
+
42
+ Here's a minimal example to create and run an agent:
43
 
44
+ First, install smolagents with pip:
45
 
46
  ```bash
47
  pip install smolagents[toolkit] # Includes default tools like web search
48
  ```
49
 
 
 
 
 
50
  ```python
51
+ from smolagents import CodeAgent, InferenceClientModel, DuckDuckGoSearchTool
52
 
53
  # Initialize a model (using Hugging Face Inference API)
54
  model = InferenceClientModel() # Uses a default model
55
 
56
  # Create an agent with no tools
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
57
  agent = CodeAgent(
58
  tools=[DuckDuckGoSearchTool()],
59
  model=model,
60
  )
61
 
62
+ # Run the agent with a task
63
  result = agent.run("What is the current weather in Paris?")
64
  print(result)
65
  ```
66
 
67
+ That's it! Your agent will use Python code to solve the task and return the result.
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
68
 
69
+ Head to [the documentation](https://huggingface.co/docs/smolagents/index) to know more!