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

Update README.md

Browse files
Files changed (1) hide show
  1. README.md +104 -31
README.md CHANGED
@@ -6,55 +6,128 @@ colorTo: pink
6
  sdk: static
7
  pinned: false
8
  ---
9
- <h3 align="center">
10
- <div style="display:flex;flex-direction:row;">
11
- <img src="https://huggingface.co/datasets/huggingface/documentation-images/resolve/main/smolagents/smolagents.png" alt="Hugging Face mascot as James Bond" width=400px>
12
- <p>Agents that think in code!</p>
13
- </div>
14
- </h3>
 
 
 
 
 
 
 
15
 
16
- `smolagents` is a library that enables you to run powerful agents in a few lines of code. It offers:
17
 
18
- ✨ **Simplicity**: the logic for agents fits in ~1,000 lines of code (see [agents.py](https://github.com/huggingface/smolagents/blob/main/src/smolagents/agents.py)). We kept abstractions to their minimal shape above raw code!
19
 
20
- πŸ§‘β€πŸ’» **First-class support for Code Agents**. Our [`CodeAgent`](https://huggingface.co/docs/smolagents/reference/agents#smolagents.CodeAgent) writes its actions in code (as opposed to "agents being used to write code"). To make it secure, we support executing in sandboxed environments via [E2B](https://e2b.dev/) or via Docker.
21
 
22
- πŸ€— **Hub integrations**: you can [share/pull tools or agents to/from the Hub](https://huggingface.co/docs/smolagents/reference/tools#smolagents.Tool.from_hub) for instant sharing of the most efficient agents!
23
 
24
- 🌐 **Model-agnostic**: smolagents supports any LLM. It can be a local `transformers` or `ollama` model, one of [many providers on the Hub](https://huggingface.co/blog/inference-providers), or any model from OpenAI, Anthropic and many others via our [LiteLLM](https://www.litellm.ai/) integration.
25
 
26
- πŸ‘οΈ **Modality-agnostic**: Agents support text, vision, video, even audio inputs! Cf [this tutorial](https://huggingface.co/docs/smolagents/examples/web_browser) for vision.
27
 
28
- πŸ› οΈ **Tool-agnostic**: you can use tools from any [MCP server](https://huggingface.co/docs/smolagents/reference/tools#smolagents.ToolCollection.from_mcp), from [LangChain](https://huggingface.co/docs/smolagents/reference/tools#smolagents.Tool.from_langchain), you can even use a [Hub Space](https://huggingface.co/docs/smolagents/reference/tools#smolagents.Tool.from_space) as a tool.
29
 
30
- Full documentation can be found [here](https://huggingface.co/docs/smolagents/index).
31
 
32
- > [!NOTE]
33
- > Check the our [launch blog post](https://huggingface.co/blog/smolagents) to learn more about `smolagents`!
34
 
35
- ## Quick demo
 
 
 
 
36
 
37
- First install the package with a default set of tools:
38
  ```bash
39
- pip install smolagents[toolkit]
40
  ```
41
- Then define your agent, give it the tools it needs and run it!
42
- ```py
43
- from smolagents import CodeAgent, WebSearchTool, InferenceClientModel
44
 
45
- model = InferenceClientModel()
46
- agent = CodeAgent(tools=[WebSearchTool()], model=model, stream_outputs=True)
 
 
 
 
 
 
 
47
 
48
- agent.run("How many seconds would it take for a leopard at full speed to run through Pont des Arts?")
 
 
 
 
 
49
  ```
50
 
51
- https://github.com/user-attachments/assets/84b149b4-246c-40c9-a48d-ba013b08e600
 
 
 
 
52
 
53
- You can even share your agent to the Hub, as a Space repository:
54
- ```py
55
- agent.push_to_hub("m-ric/my_agent")
56
 
57
- # agent.from_hub("m-ric/my_agent") to load an agent from Hub
 
 
 
 
 
 
 
 
58
  ```
59
 
60
- Our library is LLM-agnostic: you could switch the example above to any inference provider: our InferenceClient, OpenAI, Anthropic...
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
+
19
+ 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>