Hub documentation

Agent 库

Hugging Face's logo
Join the Hugging Face community

and get access to the augmented documentation experience

to get started

Agent 库

tiny-agents

一个轻量级工具包,用于在 Hugging Face Inference 之上运行基于 MCP 的智能体。提供 JavaScript(@huggingface/tiny-agents)和 Python(huggingface_hub)版本。

# JavaScript
npx @huggingface/tiny-agents run "agent/id"

# Python
pip install "huggingface_hub[mcp]"
tiny-agents run "agent/id"

使用 agent.json 配置创建你自己的 agent:

{
	"model": "Qwen/Qwen2.5-72B-Instruct",
	"provider": "together",
	"servers": [
		{
			"type": "stdio",
			"command": "npx",
			"args": ["@playwright/mcp@latest"]
		}
	]
}

对于本地 LLM,请添加一个指向您服务器的 endpointUrl(例如 http://localhost:1234/v1)。有关详细信息,请参阅 SDK 指南。

Gradio MCP 服务器

只需一行代码,即可将任意 Gradio 应用转换为 MCP 服务器:

demo.launch(mcp_server=True)

服务器将每个函数暴露为一个工具,其描述由文档字符串自动生成。您可以将其连接到任何 MCP 客户端。在 Hub 上有数千个兼容 MCP 的 Spaces。有关更多信息,请参阅 Gradio MCP 指南。

smolagents

smolagents 是一个轻量级 Python 库,只需几行代码即可构建智能体。它支持 CodeAgent(以 Python 编写操作)和 ToolCallingAgent(使用 JSON 工具调用),可通过 Inference Providers 与任意模型配合使用,并支持与 MCP 服务器集成。

smolagent "Plan a trip to Tokyo, Kyoto and Osaka between Mar 28 and Apr 7." \
--model-type "InferenceClientModel" \
--model-id "Qwen/Qwen2.5-Coder-32B-Instruct" \
--tools "web_search"

可以将 Agent 作为 Space 推送到 Hub。浏览社区 Agent 请访问此处。更多详情请参阅smolagents 文档。

Update on GitHub