





Deep Research build By Smolagents FREE
Powered By Smolagents
广告代码 Smolagents | FAST&FREE
由 Together AI 和 LlamaCoder 提供技术支持
smolagents and tools gallery
best smolagents in huggingface
什么是代理?
人工智能代理是 由 LLM 输出控制工作流程的程序.
下表说明了不同系统的代理机构有何不同:
机构层面 | 说明 | 这就是所谓的 | 模式示例 |
---|---|---|---|
☆☆☆ | LLM 输出对程序流程没有影响 | 简单处理器 | process_llm_output(llm_response) |
★☆☆ | LLM 输出决定基本控制流 | 路由器 | 如果 llm_decision(): path_a(),否则: path_b() |
★★☆ | LLM 输出决定函数的执行 | 工具调用 | run_function(llm_chosen_tool, llm_chosen_args) |
★★★ | LLM 输出控制迭代和程序继续 | 多级制剂 | while llm_should_continue(): execute_next_step() |
★★★ | 一个代理工作流可以启动另一个代理工作流 | 多代理 | if llm_trigger(): execute_agent() |
SmolAgents 的特点
🤗 Smolagents 是由 Hugging Face 团队开发的极简人工智能代理框架,只需几行代码就能让开发人员部署强大的代理。smolagents 秉承简单高效的理念,使大型语言模型(LLM)能够与现实世界无缝交互。
✨ 简洁
紧凑型代码库:有大约 1,000 行核心代码 agents.py
因此,smolagents 将抽象概念减少到最低限度,以便于直接开发。
方便用户
开发人员可以迅速定义代理,提供必要的工具,并立即运行它们,而无需进行复杂的配置。
代码代理
smolagents 的重点是 代码代理在这里,代理编写并执行 Python 代码片段来执行操作,而不是将操作生成 JSON 或文本块。
高效率
与标准工具调用方法相比,代码代理提高了效率和准确性,减少了约 30% 的步骤和 LLM 调用,并在复杂基准测试中取得了优异的性能。
安全执行
为确保代码执行安全,smolagents 支持在沙盒环境中运行代码,例如 E2B提供一个受保护的隔离执行空间。
各种法学硕士
smolagents 可以毫不费力地与任何大型语言模型集成,包括通过 Transformers 托管在 Hugging Face Hub 上的模型,以及通过 LiteLLM 集成的 OpenAI、Anthropic 和其他公司的模型。

SmolAgents :与抱抱脸枢纽集成
共享和加载工具:与 Hugging Face Hub 深度集成,使开发人员能够轻松共享和导入工具,促进社区内的协作和共享。
生态系统增长:smolagents 利用 Hub 的能力,不断扩展更多功能和工具,提供无限的发展潜力。
支持传统工具呼叫代理
多种选择:除代码代理外,smolagents 还支持传统的 工具呼叫代理,其中的操作以 JSON 或文本块的形式编写,适用于特定场景和要求。


选择 smolAgents 代码的原因
卓越的可组合性:代码自然支持函数嵌套和重复使用,允许表达复杂的逻辑。
高效对象处理:与 JSON 相比,代码简化了对象的管理和传输。
终极灵活性:代码可以表示计算机可以执行的任何操作,具有极大的通用性。
广泛的培训数据:法律硕士接受过大量高质量代码的培训,提高了生成和理解代码的能力。
性能优势 的 smolagents
在各种基准测试中,使用开源模型的 smolagent 与使用专有模型的代理性能相当。得益于代码代理的高效性和开源模型的不断进步,开发人员无需依赖闭源服务就能构建功能强大的代理系统。

SmolAgents 应用实例
在 Smolagents 中,代理被封装在允许它们执行特定任务的类中。例如,一个 托管代理
通过使用不同的代理类型,可以创建管理各种任务的代理。下面是一个简化示例,说明如何实现两个代理--一个用于网络搜索,另一个用于生成图片。下面是如何制作一个自定义工具,从谷歌地图中获取旅行时间,以及如何将其用于旅行计划代理:
from typing import Optional
from smolagents import CodeAgent, HfApiModel, tool
@tool
def get_travel_duration(start_location: str, destination_location: str, transportation_mode: Optional[str] = None) -> str:
"""Gets the travel time between two places.
Args:
start_location: the place from which you start your ride
destination_location: the place of arrival
transportation_mode: The transportation mode, in 'driving', 'walking', 'bicycling', or 'transit'. Defaults to 'driving'.
"""
import os # All imports are placed within the function, to allow for sharing to Hub.
import googlemaps
from datetime import datetime
gmaps = googlemaps.Client(os.getenv("GMAPS_API_KEY"))
if transportation_mode is None:
transportation_mode = "driving"
try:
directions_result = gmaps.directions(
start_location,
destination_location,
mode=transportation_mode,
departure_time=datetime(2025, 6, 6, 11, 0), # At 11, date far in the future
)
if len(directions_result) == 0:
return "No way found between these places with the required transportation mode."
return directions_result[0]["legs"][0]["duration"]["text"]
except Exception as e:
print(e)
return e
agent = CodeAgent(tools=[get_travel_duration], model=HfApiModel(), additional_authorized_imports=["datetime"])
agent.run("Can you give me a nice one-day trip around Paris with a few locations and the times? Could be in the city or outside, but should fit in one day. I'm travelling only with a rented bicycle.")
经过几步收集旅行时间和计算后,代理返回了最终建议:巴黎自行车一日游路线:
1.上午 9:00 在埃菲尔铁塔出发。
2.埃菲尔铁塔观光至上午 10:30。
3.上午 10:46 前往圣母大教堂。
4.游览巴黎圣母院大教堂至中午 12:16。
5.中午 12:41 前往蒙马特。
6.在蒙马特观光至下午 2:11。
7.下午 2:33 前往卢森堡公园。
8.在卢森堡公园游览至下午 4:03。
9.下午 4:12 前往卢浮宫博物馆。
10.在卢浮宫博物馆游览至下午 5:42。
11.午休至下午 6:12。
12.计划结束时间:下午 6:12。
创建工具后,将其共享到 Hub 非常简单:
get_travel_duration.push_to_hub("{your_username}/get-travel-duration-tool")
人们在 X.com 上是如何谈论 SmolAgents 的?
今天发布的新 smolagents 程序库由 @huggingface 看起来真的令人印象深刻。
- Ben Klieger (@benklieger) 2024 年 12 月 31 日
将简单性(主文件只有 ~1000 行!)和基准意见功能(支持代码优先方法而非直接函数调用)相结合 🔥
教程主题 (🧵) pic.twitter.com/sKuakggpcM
我利用周末的时间学习了代理工作流,并玩了一下 smolagents 库。 @huggingface.因此,我创建了一个很酷的旅行助理代理(我称之为 Tracy)。
- 阿纳夫-贾伊特利 (@arnitly) 2025 年 1 月 6 日
我使用 CodeLlama-34b-Instruct-hf 为我的 LLM 代理在后台进行... pic.twitter.com/e7GHA7rVlk
好的、 @huggingface 我想说,smolagent 和他们的代理定义成功了。
- 格瑞德 (@devgerred) 2024 年 12 月 31 日
也许客户只是需要谈判的一方,而我们需要继续投资于法律硕士本身。我喜欢这种一目了然的感觉。 pic.twitter.com/sD6qMqpzgs
smolagents 现已在 ai-gradio 中提供
- AK (@_akhaliq) 2024 年 12 月 31 日
pip install ai-gradio[smolagents]==0.2.1
然后只需
import gradio as gr
导入 ai_gradio
gr.load( name='smolagents:meta-llama/Llama-3.1-8B-Instruct'、
src=ai_gradio.registry).launch() pic.twitter.com/r7vfhrW36l
Hugging Face 推出了 Smolagents 库,该库旨在使用大型语言模型(LLM)构建代理系统。
- 马扎尔-乔德里(@mazrnow) 2025 年 1 月 5 日
与传统的基于 LLM 的系统不同,...
显示更多 https://t.co/EBEWPBEwAj pic.twitter.com/h2xswDLAxg
smolagents - 只需 3 行代码,即可通过搜索创建类似 Devin 的代理!🔥 pic.twitter.com/PPyhbFWN5w
- Vaibhav (VB) Srivastav (@reach_vb) 2024 年 12 月 29 日
Agent 元年来势汹汹啊!一周猛涨 3.9K Star? ⚡️ @huggingface 正式发布并开源 smolagents!
- Tom Huang (@tuturetom) 2025 年 1 月 8 日
3 行代码启动一个 Agent 完成复杂工作,支持 40+ LLM,支持无缝连接 Huggingface hub 下载一些自定义模型
不仅是一个 Agent 框架,还是一个将 HF 所有有价值的大小模型作为工具融入 Agent 的伟大尝试 pic.twitter.com/wJZ9ZL8nRT